From 167f5de66aeeb62aa0af72f3920228c2e8e4df22 Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 13 Mar 2025 16:22:44 +0000 Subject: [PATCH] style: improve rector config, static calls invocation in tests, and add missing `@throws` in phpdocs --- .gitignore | 1 + ci/rector/config.php | 2 -- .../ORM/Query/AST/Functions/BaseVariadicFunction.php | 6 ++++++ tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php | 4 ++-- .../Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php | 6 +++--- .../MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php | 2 +- .../MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php | 6 +++--- .../MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php | 2 +- tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php | 6 +++--- tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php | 6 +++--- .../Doctrine/DBAL/Types/SmallIntArrayTest.php | 2 +- tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php | 6 +++--- .../Doctrine/ORM/Query/AST/Functions/TestCase.php | 2 +- tests/MartinGeorgiev/Utils/DataStructureTest.php | 4 ++-- 14 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index be106c7f..2f1f5715 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/ +/var/ /vendor/ composer.lock diff --git a/ci/rector/config.php b/ci/rector/config.php index e3c7a50c..12c0f7b0 100644 --- a/ci/rector/config.php +++ b/ci/rector/config.php @@ -2,7 +2,6 @@ declare(strict_types=1); -use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; use Rector\Config\RectorConfig; use Rector\Doctrine\Set\DoctrineSetList; use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector; @@ -21,7 +20,6 @@ $rectorConfig->parallel(); $rectorConfig->phpstanConfig($basePath.'ci/phpstan/config.neon'); $rectorConfig->skip([ - ArraySpreadInsteadOfArrayMergeRector::class, RenamePropertyToMatchTypeRector::class, ]); $rectorConfig->importShortClasses(false); diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php index 6f1ba2e1..055c08e0 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\TokenType; +use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException; use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\ParserException; use MartinGeorgiev\Utils\DoctrineOrm; @@ -19,6 +20,9 @@ abstract class BaseVariadicFunction extends BaseFunction { protected string $commonNodeMapping = 'StringPrimary'; + /** + * @throws ParserException + */ public function feedParserWithNodes(Parser $parser): void { $lexer = $parser->getLexer(); @@ -56,6 +60,8 @@ public function getSql(SqlWalker $sqlWalker): string * Validates the arguments passed to the function. * * @param mixed[] $arguments The array of arguments to validate + * + * @throws InvalidArgumentForVariadicFunctionException */ abstract protected function validateArguments(array $arguments): void; } diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php index 0adc9469..670d59a4 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php @@ -43,7 +43,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres ->method('isValidArrayItemForDatabase') ->willReturn(true); - $this->assertSame($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); + self::assertSame($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); } /** @@ -53,7 +53,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres */ public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue): void { - $this->assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); + self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php index 72ac706e..6f84245e 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php @@ -22,7 +22,7 @@ abstract class BaseIntegerArrayTestCase extends TestCase */ public function can_detect_invalid_for_transformation_php_value(mixed $phpValue): void { - $this->assertFalse($this->fixture->isValidArrayItemForDatabase($phpValue)); + self::assertFalse($this->fixture->isValidArrayItemForDatabase($phpValue)); } /** @@ -47,7 +47,7 @@ public static function provideInvalidTransformations(): array */ public function can_transform_from_php_value(int $phpValue, string $postgresValue): void { - $this->assertTrue($this->fixture->isValidArrayItemForDatabase($phpValue)); + self::assertTrue($this->fixture->isValidArrayItemForDatabase($phpValue)); } /** @@ -57,7 +57,7 @@ public function can_transform_from_php_value(int $phpValue, string $postgresValu */ public function can_transform_to_php_value(int $phpValue, string $postgresValue): void { - $this->assertEquals($phpValue, $this->fixture->transformArrayItemForPHP($postgresValue)); + self::assertEquals($phpValue, $this->fixture->transformArrayItemForPHP($postgresValue)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php index c813da77..143b2ee7 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php @@ -20,7 +20,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('bigint[]', $this->fixture->getName()); + self::assertEquals('bigint[]', $this->fixture->getName()); } public static function provideInvalidTransformations(): array diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php index 74d1f177..79d08698 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php @@ -30,7 +30,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('bool[]', $this->fixture->getName()); + self::assertEquals('bool[]', $this->fixture->getName()); } /** @@ -44,7 +44,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres ->with($phpValue) ->willReturn($platformValue); - $this->assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); + self::assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); } /** @@ -58,7 +58,7 @@ public function can_transform_to_php_value(?array $phpValue, ?string $postgresVa ->with($this->anything()) ->willReturnCallback('boolval'); - $this->assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); + self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php index fbd385e4..5d2279d6 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php @@ -20,7 +20,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('integer[]', $this->fixture->getName()); + self::assertEquals('integer[]', $this->fixture->getName()); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php index a4a89d83..8abfc85b 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php @@ -31,7 +31,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('jsonb[]', $this->fixture->getName()); + self::assertEquals('jsonb[]', $this->fixture->getName()); } /** @@ -41,7 +41,7 @@ public function has_name(): void */ public function can_transform_from_php_value(?array $phpValue, ?string $postgresValue): void { - $this->assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); + self::assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); } /** @@ -51,7 +51,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres */ public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue): void { - $this->assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); + self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php index 5bcc1dc5..c64f2439 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php @@ -30,7 +30,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('jsonb', $this->fixture->getName()); + self::assertEquals('jsonb', $this->fixture->getName()); } /** @@ -40,7 +40,7 @@ public function has_name(): void */ public function can_transform_from_php_value(null|array|bool|float|int|string $phpValue, ?string $postgresValue): void { - $this->assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); + self::assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); } /** @@ -50,7 +50,7 @@ public function can_transform_from_php_value(null|array|bool|float|int|string $p */ public function can_transform_to_php_value(null|array|bool|float|int|string $phpValue, ?string $postgresValue): void { - $this->assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); + self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArrayTest.php index 60affac7..3dfa6146 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArrayTest.php @@ -20,7 +20,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('smallint[]', $this->fixture->getName()); + self::assertEquals('smallint[]', $this->fixture->getName()); } public static function provideInvalidTransformations(): array diff --git a/tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php b/tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php index 9516612e..9282ae8e 100644 --- a/tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php +++ b/tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php @@ -30,7 +30,7 @@ protected function setUp(): void */ public function has_name(): void { - $this->assertEquals('text[]', $this->fixture->getName()); + self::assertEquals('text[]', $this->fixture->getName()); } /** @@ -40,7 +40,7 @@ public function has_name(): void */ public function can_transform_from_php_value(?array $phpValue, ?string $postgresValue): void { - $this->assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); + self::assertEquals($postgresValue, $this->fixture->convertToDatabaseValue($phpValue, $this->platform)); } /** @@ -50,7 +50,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres */ public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue): void { - $this->assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); + self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform)); } /** diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php index 0b2c64f9..a7d3741b 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php @@ -103,7 +103,7 @@ public function dql_is_transformed_to_valid_sql(): void protected function assertSqlFromDql(string $expectedSql, string $dql, string $message = ''): void { $query = $this->buildEntityManager()->createQuery($dql); - $this->assertEquals($expectedSql, $query->getSQL(), $message); + self::assertEquals($expectedSql, $query->getSQL(), $message); } private function buildEntityManager(): EntityManager diff --git a/tests/MartinGeorgiev/Utils/DataStructureTest.php b/tests/MartinGeorgiev/Utils/DataStructureTest.php index eb209fed..b79cd11b 100644 --- a/tests/MartinGeorgiev/Utils/DataStructureTest.php +++ b/tests/MartinGeorgiev/Utils/DataStructureTest.php @@ -18,7 +18,7 @@ class DataStructureTest extends TestCase */ public function can_transform_from_php_value(array $phpValue, string $postgresValue): void { - $this->assertEquals($postgresValue, DataStructure::transformPHPArrayToPostgresTextArray($phpValue)); + self::assertEquals($postgresValue, DataStructure::transformPHPArrayToPostgresTextArray($phpValue)); } /** @@ -30,7 +30,7 @@ public function can_transform_from_php_value(array $phpValue, string $postgresVa */ public function can_transform_to_php_value(array $phpValue, string $postgresValue): void { - $this->assertEquals($phpValue, DataStructure::transformPostgresTextArrayToPHPArray($postgresValue)); + self::assertEquals($phpValue, DataStructure::transformPostgresTextArrayToPHPArray($postgresValue)); } /**