Skip to content

Commit 0c8d84f

Browse files
authored
Merge pull request #40: add snowflake
2 parents 49b0c71 + b343082 commit 0c8d84f

File tree

4 files changed

+200
-134
lines changed

4 files changed

+200
-134
lines changed

psalm-baseline.xml

Lines changed: 128 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,131 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="6.12.1@e71404b0465be25cf7f8a631b298c01c5ddd864f">
3-
<file src="src/CreatedAt.php">
4-
<PropertyNotSetInConstructor>
5-
<code><![CDATA[CreatedAt]]></code>
6-
</PropertyNotSetInConstructor>
7-
</file>
8-
<file src="src/Dispatcher/ListenerProvider.php">
9-
<DocblockTypeContradiction>
10-
<code><![CDATA[!\is_array($event)]]></code>
11-
</DocblockTypeContradiction>
12-
<MixedArgument>
13-
<code><![CDATA[$arguments]]></code>
14-
<code><![CDATA[$definition]]></code>
15-
<code><![CDATA[$definition[self::DEFINITION_CLASS]]]></code>
16-
<code><![CDATA[$role]]></code>
17-
</MixedArgument>
18-
<MixedArrayAccess>
19-
<code><![CDATA[$definition[self::DEFINITION_CLASS]]]></code>
20-
</MixedArrayAccess>
21-
<MixedAssignment>
22-
<code><![CDATA[$arguments]]></code>
23-
<code><![CDATA[$role]]></code>
24-
</MixedAssignment>
25-
<RedundantConditionGivenDocblockType>
26-
<code><![CDATA[\assert($listen instanceof Listen)]]></code>
27-
</RedundantConditionGivenDocblockType>
28-
</file>
29-
<file src="src/Event/Mapper/Command/OnCreate.php">
30-
<PropertyNotSetInConstructor>
31-
<code><![CDATA[OnCreate]]></code>
32-
</PropertyNotSetInConstructor>
33-
</file>
34-
<file src="src/Event/Mapper/Command/OnDelete.php">
35-
<PropertyNotSetInConstructor>
36-
<code><![CDATA[OnDelete]]></code>
37-
</PropertyNotSetInConstructor>
38-
</file>
39-
<file src="src/Event/Mapper/Command/OnUpdate.php">
40-
<PropertyNotSetInConstructor>
41-
<code><![CDATA[OnUpdate]]></code>
42-
</PropertyNotSetInConstructor>
43-
</file>
44-
<file src="src/EventDrivenCommandGenerator.php">
45-
<MixedReturnStatement>
46-
<code><![CDATA[$event->command]]></code>
47-
<code><![CDATA[$event->command]]></code>
48-
<code><![CDATA[$event->command]]></code>
49-
</MixedReturnStatement>
50-
<PropertyNotSetInConstructor>
51-
<code><![CDATA[$timestamp]]></code>
52-
</PropertyNotSetInConstructor>
53-
</file>
54-
<file src="src/EventListener.php">
55-
<MixedArrayAssignment>
56-
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
57-
</MixedArrayAssignment>
58-
<PropertyNotSetInConstructor>
59-
<code><![CDATA[$role]]></code>
60-
</PropertyNotSetInConstructor>
61-
</file>
62-
<file src="src/Exception/OptimisticLock/ChangedVersionException.php">
63-
<ClassMustBeFinal>
64-
<code><![CDATA[ChangedVersionException]]></code>
65-
</ClassMustBeFinal>
66-
<MixedArgument>
67-
<code><![CDATA[$new]]></code>
68-
<code><![CDATA[$old]]></code>
69-
</MixedArgument>
70-
</file>
71-
<file src="src/Exception/OptimisticLock/RecordIsLockedException.php">
72-
<ClassMustBeFinal>
73-
<code><![CDATA[RecordIsLockedException]]></code>
74-
</ClassMustBeFinal>
75-
</file>
76-
<file src="src/Hook.php">
77-
<PropertyNotSetInConstructor>
78-
<code><![CDATA[Hook]]></code>
79-
</PropertyNotSetInConstructor>
80-
</file>
81-
<file src="src/Listener/OptimisticLock.php">
82-
<MixedAssignment>
83-
<code><![CDATA[$nodeValue]]></code>
84-
<code><![CDATA[$stateValue]]></code>
85-
</MixedAssignment>
86-
</file>
87-
<file src="src/OptimisticLock.php">
88-
<PropertyNotSetInConstructor>
89-
<code><![CDATA[OptimisticLock]]></code>
90-
</PropertyNotSetInConstructor>
91-
</file>
92-
<file src="src/Schema/BaseModifier.php">
93-
<MixedArrayAssignment>
94-
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
95-
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
96-
</MixedArrayAssignment>
97-
</file>
98-
<file src="src/Schema/RegistryModifier.php">
99-
<ArgumentTypeCoercion>
100-
<code><![CDATA[$columnName]]></code>
101-
<code><![CDATA[$columnName]]></code>
102-
<code><![CDATA[$columnName]]></code>
103-
<code><![CDATA[$columnName]]></code>
104-
<code><![CDATA[$columnName]]></code>
105-
<code><![CDATA[$columnName]]></code>
106-
<code><![CDATA[$columnName]]></code>
107-
<code><![CDATA[$columnName]]></code>
108-
<code><![CDATA[$columnName]]></code>
109-
<code><![CDATA[$columnName]]></code>
110-
<code><![CDATA[$columnName]]></code>
111-
<code><![CDATA[$columnName]]></code>
112-
<code><![CDATA[$columnName]]></code>
113-
<code><![CDATA[$columnName]]></code>
114-
<code><![CDATA[$columnName]]></code>
115-
<code><![CDATA[$columnName]]></code>
116-
<code><![CDATA[$columnName]]></code>
117-
<code><![CDATA[$columnName]]></code>
118-
<code><![CDATA[$rule]]></code>
119-
</ArgumentTypeCoercion>
120-
<ClassMustBeFinal>
121-
<code><![CDATA[RegistryModifier]]></code>
122-
</ClassMustBeFinal>
123-
<MixedAssignment>
124-
<code><![CDATA[$defaultHandlers]]></code>
125-
</MixedAssignment>
126-
</file>
127-
<file src="src/SoftDelete.php">
128-
<PropertyNotSetInConstructor>
129-
<code><![CDATA[SoftDelete]]></code>
130-
</PropertyNotSetInConstructor>
131-
</file>
132-
<file src="src/UpdatedAt.php">
133-
<PropertyNotSetInConstructor>
134-
<code><![CDATA[UpdatedAt]]></code>
135-
</PropertyNotSetInConstructor>
136-
</file>
3+
<file src="src/CreatedAt.php">
4+
<PropertyNotSetInConstructor>
5+
<code><![CDATA[CreatedAt]]></code>
6+
</PropertyNotSetInConstructor>
7+
</file>
8+
<file src="src/Dispatcher/ListenerProvider.php">
9+
<DocblockTypeContradiction>
10+
<code><![CDATA[!\is_array($event)]]></code>
11+
</DocblockTypeContradiction>
12+
<MixedArgument>
13+
<code><![CDATA[$arguments]]></code>
14+
<code><![CDATA[$definition]]></code>
15+
<code><![CDATA[$definition[self::DEFINITION_CLASS]]]></code>
16+
<code><![CDATA[$role]]></code>
17+
</MixedArgument>
18+
<MixedArrayAccess>
19+
<code><![CDATA[$definition[self::DEFINITION_CLASS]]]></code>
20+
</MixedArrayAccess>
21+
<MixedAssignment>
22+
<code><![CDATA[$arguments]]></code>
23+
<code><![CDATA[$role]]></code>
24+
</MixedAssignment>
25+
<RedundantConditionGivenDocblockType>
26+
<code><![CDATA[\assert($listen instanceof Listen)]]></code>
27+
</RedundantConditionGivenDocblockType>
28+
</file>
29+
<file src="src/Event/Mapper/Command/OnCreate.php">
30+
<PropertyNotSetInConstructor>
31+
<code><![CDATA[OnCreate]]></code>
32+
</PropertyNotSetInConstructor>
33+
</file>
34+
<file src="src/Event/Mapper/Command/OnDelete.php">
35+
<PropertyNotSetInConstructor>
36+
<code><![CDATA[OnDelete]]></code>
37+
</PropertyNotSetInConstructor>
38+
</file>
39+
<file src="src/Event/Mapper/Command/OnUpdate.php">
40+
<PropertyNotSetInConstructor>
41+
<code><![CDATA[OnUpdate]]></code>
42+
</PropertyNotSetInConstructor>
43+
</file>
44+
<file src="src/EventDrivenCommandGenerator.php">
45+
<MixedReturnStatement>
46+
<code><![CDATA[$event->command]]></code>
47+
<code><![CDATA[$event->command]]></code>
48+
<code><![CDATA[$event->command]]></code>
49+
</MixedReturnStatement>
50+
<PropertyNotSetInConstructor>
51+
<code><![CDATA[$timestamp]]></code>
52+
</PropertyNotSetInConstructor>
53+
</file>
54+
<file src="src/EventListener.php">
55+
<MixedArrayAssignment>
56+
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
57+
</MixedArrayAssignment>
58+
<PropertyNotSetInConstructor>
59+
<code><![CDATA[$role]]></code>
60+
</PropertyNotSetInConstructor>
61+
</file>
62+
<file src="src/Exception/OptimisticLock/ChangedVersionException.php">
63+
<ClassMustBeFinal>
64+
<code><![CDATA[ChangedVersionException]]></code>
65+
</ClassMustBeFinal>
66+
<MixedArgument>
67+
<code><![CDATA[$new]]></code>
68+
<code><![CDATA[$old]]></code>
69+
</MixedArgument>
70+
</file>
71+
<file src="src/Exception/OptimisticLock/RecordIsLockedException.php">
72+
<ClassMustBeFinal>
73+
<code><![CDATA[RecordIsLockedException]]></code>
74+
</ClassMustBeFinal>
75+
</file>
76+
<file src="src/Hook.php">
77+
<PropertyNotSetInConstructor>
78+
<code><![CDATA[Hook]]></code>
79+
</PropertyNotSetInConstructor>
80+
</file>
81+
<file src="src/Listener/OptimisticLock.php">
82+
<MixedAssignment>
83+
<code><![CDATA[$nodeValue]]></code>
84+
<code><![CDATA[$stateValue]]></code>
85+
</MixedAssignment>
86+
</file>
87+
<file src="src/OptimisticLock.php">
88+
<PropertyNotSetInConstructor>
89+
<code><![CDATA[OptimisticLock]]></code>
90+
</PropertyNotSetInConstructor>
91+
</file>
92+
<file src="src/Schema/BaseModifier.php">
93+
<MixedArrayAssignment>
94+
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
95+
<code><![CDATA[$schema[SchemaInterface::LISTENERS][]]]></code>
96+
</MixedArrayAssignment>
97+
</file>
98+
<file src="src/Schema/RegistryModifier.php">
99+
<ArgumentTypeCoercion>
100+
<code><![CDATA[$columnName]]></code>
101+
<code><![CDATA[$columnName]]></code>
102+
<code><![CDATA[$columnName]]></code>
103+
<code><![CDATA[$columnName]]></code>
104+
<code><![CDATA[$columnName]]></code>
105+
<code><![CDATA[$columnName]]></code>
106+
<code><![CDATA[$columnName]]></code>
107+
<code><![CDATA[$columnName]]></code>
108+
<code><![CDATA[$columnName]]></code>
109+
<code><![CDATA[$columnName]]></code>
110+
<code><![CDATA[$columnName]]></code>
111+
<code><![CDATA[$columnName]]></code>
112+
<code><![CDATA[$rule]]></code>
113+
</ArgumentTypeCoercion>
114+
<ClassMustBeFinal>
115+
<code><![CDATA[RegistryModifier]]></code>
116+
</ClassMustBeFinal>
117+
<MixedAssignment>
118+
<code><![CDATA[$defaultHandlers]]></code>
119+
</MixedAssignment>
120+
</file>
121+
<file src="src/SoftDelete.php">
122+
<PropertyNotSetInConstructor>
123+
<code><![CDATA[SoftDelete]]></code>
124+
</PropertyNotSetInConstructor>
125+
</file>
126+
<file src="src/UpdatedAt.php">
127+
<PropertyNotSetInConstructor>
128+
<code><![CDATA[UpdatedAt]]></code>
129+
</PropertyNotSetInConstructor>
130+
</file>
137131
</files>

src/Schema/RegistryModifier.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class RegistryModifier
4141
protected const STRING_COLUMN = AbstractColumn::STRING;
4242
protected const BIG_INTEGER_COLUMN = 'bigInteger';
4343
protected const DATETIME_COLUMN = 'datetime';
44+
protected const SNOWFLAKE_COLUMN = 'snowflake';
4445
protected const ULID_COLUMN = 'ulid';
4546
protected const UUID_COLUMN = 'uuid';
4647

@@ -85,6 +86,13 @@ public static function isStringType(string $type): bool
8586
return $matches['type'] === 'string';
8687
}
8788

89+
public static function isSnowflakeType(string $type): bool
90+
{
91+
\preg_match(self::DEFINITION, $type, $matches);
92+
93+
return $matches['type'] === self::SNOWFLAKE_COLUMN;
94+
}
95+
8896
public static function isUlidType(string $type): bool
8997
{
9098
\preg_match(self::DEFINITION, $type, $matches);
@@ -188,6 +196,31 @@ public function addStringColumn(string $columnName, string $fieldName, int|null
188196
}
189197

190198
/**
199+
* @param non-empty-string $columnName
200+
* @throws BehaviorCompilationException
201+
*/
202+
public function addSnowflakeColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn
203+
{
204+
if ($this->fields->has($fieldName)) {
205+
if (!static::isSnowflakeType($this->fields->get($fieldName)->getType())) {
206+
throw new BehaviorCompilationException(
207+
\sprintf('Field %s must be of type %s.', $fieldName, self::SNOWFLAKE_COLUMN),
208+
);
209+
}
210+
$this->validateColumnName($fieldName, $columnName);
211+
$this->fields->get($fieldName)->setGenerated($generated);
212+
213+
return $this->table->column($columnName);
214+
}
215+
216+
$field = (new Field())->setColumn($columnName)->setType(self::SNOWFLAKE_COLUMN)->setGenerated($generated);
217+
$this->fields->set($fieldName, $field);
218+
219+
return $this->table->column($columnName)->type(self::SNOWFLAKE_COLUMN);
220+
}
221+
222+
/**
223+
* @param non-empty-string $columnName
191224
* @throws BehaviorCompilationException
192225
*/
193226
public function addUlidColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn
@@ -211,6 +244,7 @@ public function addUlidColumn(string $columnName, string $fieldName, int|null $g
211244
}
212245

213246
/**
247+
* @param non-empty-string $columnName
214248
* @throws BehaviorCompilationException
215249
*/
216250
public function addUuidColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn

tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ public function testAddBigIntegerFieldThrowsException(): void
8080
$this->modifier->addBigIntegerColumn('snowflake_column', 'snowflake');
8181
}
8282

83+
public function testAddSnowflakeField(): void
84+
{
85+
$this->modifier->addSnowflakeColumn('snowflake_column', 'snowflake');
86+
87+
$entity = $this->registry->getEntity(self::ROLE_TEST);
88+
$fields = $entity->getFields();
89+
90+
$this->assertTrue($fields->has('snowflake'));
91+
$this->assertSame('snowflake', $fields->get('snowflake')->getType());
92+
$this->assertSame('snowflake_column', $fields->get('snowflake')->getColumn());
93+
}
94+
95+
public function testAddSnowflakeFieldThrowsException(): void
96+
{
97+
$this->modifier->addStringColumn('snowflake_column', 'snowflake');
98+
99+
$this->expectException(BehaviorCompilationException::class);
100+
$this->expectExceptionMessage('Field snowflake must be of type snowflake.');
101+
102+
$this->modifier->addSnowflakeColumn('snowflake_column', 'snowflake');
103+
}
104+
83105
public function testAddUlidField(): void
84106
{
85107
$this->modifier->addUlidColumn('ulid_column', 'ulid');

tests/Behavior/Unit/Schema/RegistryModifierTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ public function testIsStringTypeFalse(mixed $type): void
121121
$this->assertFalse(RegistryModifier::isStringType($type));
122122
}
123123

124+
public function testIsSnowflakeTypeTrue(): void
125+
{
126+
$this->assertTrue(RegistryModifier::isSnowflakeType('snowflake'));
127+
}
128+
129+
/**
130+
* @dataProvider integerDataProvider
131+
* @dataProvider datetimeDataProvider
132+
* @dataProvider invalidDataProvider
133+
* @dataProvider stringDataProvider
134+
*/
135+
public function testIsSnowflakeTypeFalse(mixed $type): void
136+
{
137+
$this->assertFalse(RegistryModifier::isSnowflakeType($type));
138+
}
139+
124140
public function testIsUlidTypeTrue(): void
125141
{
126142
$this->assertTrue(RegistryModifier::isUlidType('ulid'));

0 commit comments

Comments
 (0)