From cff3c701512740673bc784d156bdd51a5ef13acb Mon Sep 17 00:00:00 2001 From: Adam Dyson Date: Tue, 15 Jul 2025 19:11:58 +1000 Subject: [PATCH 1/3] Added logic for snowflake handling within RegistryModifier --- src/Schema/RegistryModifier.php | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Schema/RegistryModifier.php b/src/Schema/RegistryModifier.php index ed523de..cc99368 100644 --- a/src/Schema/RegistryModifier.php +++ b/src/Schema/RegistryModifier.php @@ -41,6 +41,7 @@ class RegistryModifier protected const STRING_COLUMN = AbstractColumn::STRING; protected const BIG_INTEGER_COLUMN = 'bigInteger'; protected const DATETIME_COLUMN = 'datetime'; + protected const SNOWFLAKE_COLUMN = 'snowflake'; protected const ULID_COLUMN = 'ulid'; protected const UUID_COLUMN = 'uuid'; @@ -85,6 +86,13 @@ public static function isStringType(string $type): bool return $matches['type'] === 'string'; } + public static function isSnowflakeType(string $type): bool + { + \preg_match(self::DEFINITION, $type, $matches); + + return $matches['type'] === self::SNOWFLAKE_COLUMN; + } + public static function isUlidType(string $type): bool { \preg_match(self::DEFINITION, $type, $matches); @@ -188,6 +196,31 @@ public function addStringColumn(string $columnName, string $fieldName, int|null } /** + * @param non-empty-string $columnName + * @throws BehaviorCompilationException + */ + public function addSnowflakeColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn + { + if ($this->fields->has($fieldName)) { + if (!static::isSnowflakeType($this->fields->get($fieldName)->getType())) { + throw new BehaviorCompilationException( + \sprintf('Field %s must be of type %s.', $fieldName, self::SNOWFLAKE_COLUMN), + ); + } + $this->validateColumnName($fieldName, $columnName); + $this->fields->get($fieldName)->setGenerated($generated); + + return $this->table->column($columnName); + } + + $field = (new Field())->setColumn($columnName)->setType(self::SNOWFLAKE_COLUMN)->setGenerated($generated); + $this->fields->set($fieldName, $field); + + return $this->table->column($columnName)->type(self::SNOWFLAKE_COLUMN); + } + + /** + * @param non-empty-string $columnName * @throws BehaviorCompilationException */ 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 } /** + * @param non-empty-string $columnName * @throws BehaviorCompilationException */ public function addUuidColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn From 1aa40baea60bcf61dc69d15c7b897099d2302752 Mon Sep 17 00:00:00 2001 From: Adam Dyson Date: Tue, 15 Jul 2025 19:12:19 +1000 Subject: [PATCH 2/3] Added test coverage for snowflake handling within RegistryModifier --- .../Common/Schema/RegistryModifierTest.php | 22 +++++++++++++++++++ .../Unit/Schema/RegistryModifierTest.php | 16 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php b/tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php index 04f43b5..0f8f1f4 100644 --- a/tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php +++ b/tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php @@ -80,6 +80,28 @@ public function testAddBigIntegerFieldThrowsException(): void $this->modifier->addBigIntegerColumn('snowflake_column', 'snowflake'); } + public function testAddSnowflakeField(): void + { + $this->modifier->addSnowflakeColumn('snowflake_column', 'snowflake'); + + $entity = $this->registry->getEntity(self::ROLE_TEST); + $fields = $entity->getFields(); + + $this->assertTrue($fields->has('snowflake')); + $this->assertSame('snowflake', $fields->get('snowflake')->getType()); + $this->assertSame('snowflake_column', $fields->get('snowflake')->getColumn()); + } + + public function testAddSnowflakeFieldThrowsException(): void + { + $this->modifier->addStringColumn('snowflake_column', 'snowflake'); + + $this->expectException(BehaviorCompilationException::class); + $this->expectExceptionMessage('Field snowflake must be of type snowflake.'); + + $this->modifier->addSnowflakeColumn('snowflake_column', 'snowflake'); + } + public function testAddUlidField(): void { $this->modifier->addUlidColumn('ulid_column', 'ulid'); diff --git a/tests/Behavior/Unit/Schema/RegistryModifierTest.php b/tests/Behavior/Unit/Schema/RegistryModifierTest.php index fa8cafc..d6b88d5 100644 --- a/tests/Behavior/Unit/Schema/RegistryModifierTest.php +++ b/tests/Behavior/Unit/Schema/RegistryModifierTest.php @@ -121,6 +121,22 @@ public function testIsStringTypeFalse(mixed $type): void $this->assertFalse(RegistryModifier::isStringType($type)); } + public function testIsSnowflakeTypeTrue(): void + { + $this->assertTrue(RegistryModifier::isSnowflakeType('snowflake')); + } + + /** + * @dataProvider integerDataProvider + * @dataProvider datetimeDataProvider + * @dataProvider invalidDataProvider + * @dataProvider stringDataProvider + */ + public function testIsSnowflakeTypeFalse(mixed $type): void + { + $this->assertFalse(RegistryModifier::isSnowflakeType($type)); + } + public function testIsUlidTypeTrue(): void { $this->assertTrue(RegistryModifier::isUlidType('ulid')); From b34308210716256d4eaf0d81b9cba4d95cfc322e Mon Sep 17 00:00:00 2001 From: Adam Dyson Date: Tue, 15 Jul 2025 19:13:01 +1000 Subject: [PATCH 3/3] Updated psalm reducing ArgumentTypeCoercion --- psalm-baseline.xml | 262 ++++++++++++++++++++++----------------------- 1 file changed, 128 insertions(+), 134 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6200c7f..0b85693 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,137 +1,131 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - command]]> - command]]> - command]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + command]]> + command]]> + command]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +