From 86e6eb65b1e2fe519cb67b5008eb7049a682781e Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 13 Mar 2025 17:24:33 +0000 Subject: [PATCH 1/4] feat: add multiple arguments support for `ARRAY` --- composer.json | 22 +++++++--- .../Doctrine/ORM/Query/AST/Functions/Arr.php | 15 ++++++- .../ORM/Query/AST/Functions/ArrTest.php | 42 +++++++++++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrTest.php diff --git a/composer.json b/composer.json index f09b343b..3949a867 100644 --- a/composer.json +++ b/composer.json @@ -60,23 +60,33 @@ }, "scripts": { + "php-cs-fixer": [ + "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v" + ], + "phpunit": [ + "phpunit --configuration='./ci/phpunit/config.xml'" + ], + "rector": [ + "rector --config='./ci/rector/config.php' --ansi --no-progress-bar" + ], + "check-code-style": [ - "php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --dry-run --no-interaction --diff -v", - "rector --config='./ci/rector/config.php' --ansi --no-progress-bar --dry-run" + "@php-cs-fixer --dry-run", + "@rector --dry-run" ], "fix-code-style": [ - "rector --config='./ci/rector/config.php' --ansi --no-progress-bar", - "php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v" + "@rector", + "@php-cs-fixer" ], "run-static-analysis": [ "phpstan analyse --configuration='./ci/phpstan/config.neon'", "deptrac analyze --config-file='./ci/deptrac/config.yml' --cache-file='./ci/deptrac/.cache' --no-interaction --no-progress" ], "run-tests": [ - "phpunit --configuration='./ci/phpunit/config.xml'" + "@phpunit" ], "run-tests-with-clover": [ - "phpunit --configuration='./ci/phpunit/config.xml' --coverage-clover './build/logs/clover.xml'" + "@phpunit --coverage-clover './build/logs/clover.xml'" ] }, diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php index 848b9e51..daf731ef 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php @@ -4,6 +4,8 @@ namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; +use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException; + /** * Implementation of PostgreSQL ARRAY[]. * @@ -12,11 +14,20 @@ * * @author Martin Georgiev */ -class Arr extends BaseFunction +class Arr extends BaseVariadicFunction { + protected string $commonNodeMapping = 'StringPrimary'; + protected function customizeFunction(): void { $this->setFunctionPrototype('ARRAY[%s]'); - $this->addNodeMapping('StringPrimary'); + } + + protected function validateArguments(array $arguments): void + { + $argumentCount = \count($arguments); + if ($argumentCount === 0) { + throw InvalidArgumentForVariadicFunctionException::atLeast('ARRAY', 1); + } } } diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrTest.php new file mode 100644 index 00000000..12b1d12c --- /dev/null +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrTest.php @@ -0,0 +1,42 @@ + Arr::class, + ]; + } + + protected function getExpectedSqlStatements(): array + { + return [ + // Multiple literal values + "SELECT ARRAY['foo', 'bar', 'baz'] AS sclr_0 FROM ContainsArrays c0_", + // Column references + 'SELECT ARRAY[c0_.array1] AS sclr_0 FROM ContainsArrays c0_', + // Mix of column references and literals + "SELECT ARRAY[c0_.array1, 'test-value', c0_.array2] AS sclr_0 FROM ContainsArrays c0_", + ]; + } + + protected function getDqlStatements(): array + { + return [ + // Multiple literal values + \sprintf("SELECT ARRAY('foo', 'bar', 'baz') FROM %s e", ContainsArrays::class), + // Column references + \sprintf('SELECT ARRAY(e.array1) FROM %s e', ContainsArrays::class), + // Mix of column references and literals + \sprintf("SELECT ARRAY(e.array1, 'test-value', e.array2) FROM %s e", ContainsArrays::class), + ]; + } +} From 71d3ab8f9f3de315b16c2bdf6686e37e8923974a Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 13 Mar 2025 17:56:50 +0000 Subject: [PATCH 2/4] co config cleanup --- ci/phpstan/config.neon | 5 ++++- composer.json | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ci/phpstan/config.neon b/ci/phpstan/config.neon index 571ed447..5ffbffea 100644 --- a/ci/phpstan/config.neon +++ b/ci/phpstan/config.neon @@ -5,12 +5,15 @@ includes: parameters: level: max paths: + - ../../ci - ../../src - ../../tests - checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false + ignoreErrors: + - identifier: missingType.iterableValue + - '#Parameter \#1 \$phpArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToDatabaseValue\(\) expects array\|null, string given.#' - '#Parameter \#1 \$postgresArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToPHPValue\(\) expects string\|null, int given.#' - '#Property MartinGeorgiev\\Doctrine\\ORM\\Query\\AST\\Functions\\Cast::\$sourceType \(Doctrine\\ORM\\Query\\AST\\Node\) does not accept Doctrine\\ORM\\Query\\AST\\Node\|string#' diff --git a/composer.json b/composer.json index 3949a867..ed9e8566 100644 --- a/composer.json +++ b/composer.json @@ -60,14 +60,20 @@ }, "scripts": { + "deptrac": [ + "deptrac analyze --config-file=./ci/deptrac/config.yml --cache-file=./ci/deptrac/.cache --no-interaction --no-progress" + ], "php-cs-fixer": [ - "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v" + "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config=./ci/php-cs-fixer/config.php --show-progress=none --no-interaction --diff -v" + ], + "phpstan": [ + "phpstan analyse --configuration=./ci/phpstan/config.neon" ], "phpunit": [ - "phpunit --configuration='./ci/phpunit/config.xml'" + "XDEBUG_MODE=coverage phpunit --configuration='./ci/phpunit/config.xml" ], "rector": [ - "rector --config='./ci/rector/config.php' --ansi --no-progress-bar" + "rector --config=./ci/rector/config.php --ansi --no-progress-bar" ], "check-code-style": [ @@ -79,14 +85,14 @@ "@php-cs-fixer" ], "run-static-analysis": [ - "phpstan analyse --configuration='./ci/phpstan/config.neon'", - "deptrac analyze --config-file='./ci/deptrac/config.yml' --cache-file='./ci/deptrac/.cache' --no-interaction --no-progress" + "@phpstan", + "@deptrac" ], "run-tests": [ "@phpunit" ], "run-tests-with-clover": [ - "@phpunit --coverage-clover './build/logs/clover.xml'" + "@phpunit --coverage-clover=./var/logs/clover.xml" ] }, From aad60ab15af82c4d023492c51a4b889dc9e22534 Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 13 Mar 2025 17:58:50 +0000 Subject: [PATCH 3/4] =?UTF-8?q?typo=20=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed9e8566..9f906061 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "phpstan analyse --configuration=./ci/phpstan/config.neon" ], "phpunit": [ - "XDEBUG_MODE=coverage phpunit --configuration='./ci/phpunit/config.xml" + "XDEBUG_MODE=coverage phpunit --configuration=./ci/phpunit/config.xml" ], "rector": [ "rector --config=./ci/rector/config.php --ansi --no-progress-bar" From d879fd3348a1050c92f131406d1836d38a354fb3 Mon Sep 17 00:00:00 2001 From: Martin Georgiev Date: Thu, 13 Mar 2025 18:43:12 +0000 Subject: [PATCH 4/4] =?UTF-8?q?typo=20=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df44624..98f28b08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: elif [ "${{ matrix.doctrine-orm }}" == "3.0" ]; then composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress else - composer update --prefer-dist --no-interaction --no-progress }} + composer update --prefer-dist --no-interaction --no-progress fi - name: Run static analysis