Skip to content

Commit 7f2b05d

Browse files
feat: add multiple arguments support for ARRAY (#279)
1 parent c1c9930 commit 7f2b05d

File tree

5 files changed

+88
-20
lines changed

5 files changed

+88
-20
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111

1212
jobs:
1313
tests:
14-
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }} + Composer ${{ matrix.composer-flags }}"
14+
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }}"
1515
runs-on: ubuntu-latest
1616

1717
strategy:
@@ -22,7 +22,6 @@ jobs:
2222
- php: '8.2'
2323
- php: '8.3'
2424
- php: '8.4'
25-
ignore-php-version: true
2625
calculate-code-coverage: true
2726
- doctrine-orm: '2.14'
2827
- doctrine-orm: '3.0'
@@ -54,11 +53,11 @@ jobs:
5453
- name: Install composer dependencies
5554
run: |
5655
if [ "${{ matrix.doctrine-orm }}" == "2.14" ]; then
57-
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress ${{ matrix.composer-flags }}
56+
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress
5857
elif [ "${{ matrix.doctrine-orm }}" == "3.0" ]; then
59-
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress ${{ matrix.composer-flags }}
58+
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress
6059
else
61-
composer update --prefer-dist --no-interaction --no-progress ${{ matrix.composer-flags }}
60+
composer update --prefer-dist --no-interaction --no-progress
6261
fi
6362
6463
- name: Run static analysis
@@ -67,9 +66,6 @@ jobs:
6766

6867
- name: Check code style
6968
run: composer check-code-style
70-
if: matrix.ignore-php-version == true
71-
env:
72-
PHP_CS_FIXER_IGNORE_ENV: 1
7369

7470
- name: Check for security vulnerabilities in 3rd party dependencies
7571
run: composer audit
@@ -84,4 +80,4 @@ jobs:
8480
github-token: ${{ secrets.GITHUB_TOKEN }}
8581
fail-on-error: false
8682
base-path: ./var/logs/test-coverage/
87-
flag-name: "PHP ${{ matrix.php }} + Composer@${{ matrix.composer-flags || '*' }}"
83+
flag-name: "PHP ${{ matrix.php }}"

ci/phpstan/config.neon

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ includes:
55
parameters:
66
level: max
77
paths:
8+
- ../../ci
89
- ../../src
910
- ../../tests
1011

11-
checkMissingIterableValueType: false
1212
reportUnmatchedIgnoredErrors: false
13+
1314
ignoreErrors:
15+
- identifier: missingType.iterableValue
16+
1417
- '#Parameter \#1 \$phpArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToDatabaseValue\(\) expects array\|null, string given.#'
1518
- '#Parameter \#1 \$postgresArray of method MartinGeorgiev\\Doctrine\\DBAL\\Types\\BaseArray::convertToPHPValue\(\) expects string\|null, int given.#'
1619
- '#Property MartinGeorgiev\\Doctrine\\ORM\\Query\\AST\\Functions\\Cast::\$sourceType \(Doctrine\\ORM\\Query\\AST\\Node\) does not accept Doctrine\\ORM\\Query\\AST\\Node\|string#'

composer.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,39 @@
5959
},
6060

6161
"scripts": {
62+
"deptrac": [
63+
"deptrac analyze --config-file=./ci/deptrac/config.yml --cache-file=./ci/deptrac/.cache --no-interaction --no-progress"
64+
],
65+
"php-cs-fixer": [
66+
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config=./ci/php-cs-fixer/config.php --show-progress=none --no-interaction --diff -v"
67+
],
68+
"phpstan": [
69+
"phpstan analyse --configuration=./ci/phpstan/config.neon"
70+
],
71+
"phpunit": [
72+
"XDEBUG_MODE=coverage phpunit --configuration=./ci/phpunit/config.xml"
73+
],
74+
"rector": [
75+
"rector --config=./ci/rector/config.php --ansi --no-progress-bar"
76+
],
77+
6278
"check-code-style": [
63-
"php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --dry-run --no-interaction --diff -v",
64-
"rector --config='./ci/rector/config.php' --ansi --no-progress-bar --dry-run"
79+
"@php-cs-fixer --dry-run",
80+
"@rector --dry-run"
6581
],
6682
"fix-code-style": [
67-
"rector --config='./ci/rector/config.php' --ansi --no-progress-bar",
68-
"php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v"
83+
"@rector",
84+
"@php-cs-fixer"
6985
],
7086
"run-static-analysis": [
71-
"phpstan analyse --configuration='./ci/phpstan/config.neon'",
72-
"deptrac analyze --config-file='./ci/deptrac/config.yml' --cache-file='./ci/deptrac/.cache' --no-interaction --no-progress"
87+
"@phpstan",
88+
"@deptrac"
7389
],
7490
"run-tests": [
75-
"phpunit --configuration='./ci/phpunit/config.xml'"
91+
"@phpunit"
7692
],
7793
"run-tests-with-clover": [
78-
"phpunit --configuration='./ci/phpunit/config.xml' --coverage-clover './var/logs/test-coverage/clover.xml'"
94+
"@phpunit --coverage-clover=./var/logs/test-coverage/clover.xml"
7995
]
8096
},
8197

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
66

7+
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
8+
79
/**
810
* Implementation of PostgreSQL ARRAY[].
911
*
@@ -12,11 +14,20 @@
1214
*
1315
* @author Martin Georgiev <martin.georgiev@gmail.com>
1416
*/
15-
class Arr extends BaseFunction
17+
class Arr extends BaseVariadicFunction
1618
{
19+
protected string $commonNodeMapping = 'StringPrimary';
20+
1721
protected function customizeFunction(): void
1822
{
1923
$this->setFunctionPrototype('ARRAY[%s]');
20-
$this->addNodeMapping('StringPrimary');
24+
}
25+
26+
protected function validateArguments(array $arguments): void
27+
{
28+
$argumentCount = \count($arguments);
29+
if ($argumentCount === 0) {
30+
throw InvalidArgumentForVariadicFunctionException::atLeast('ARRAY', 1);
31+
}
2132
}
2233
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6+
7+
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsArrays;
8+
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Arr;
9+
10+
class ArrTest extends TestCase
11+
{
12+
protected function getStringFunctions(): array
13+
{
14+
return [
15+
'ARRAY' => Arr::class,
16+
];
17+
}
18+
19+
protected function getExpectedSqlStatements(): array
20+
{
21+
return [
22+
// Multiple literal values
23+
"SELECT ARRAY['foo', 'bar', 'baz'] AS sclr_0 FROM ContainsArrays c0_",
24+
// Column references
25+
'SELECT ARRAY[c0_.array1] AS sclr_0 FROM ContainsArrays c0_',
26+
// Mix of column references and literals
27+
"SELECT ARRAY[c0_.array1, 'test-value', c0_.array2] AS sclr_0 FROM ContainsArrays c0_",
28+
];
29+
}
30+
31+
protected function getDqlStatements(): array
32+
{
33+
return [
34+
// Multiple literal values
35+
\sprintf("SELECT ARRAY('foo', 'bar', 'baz') FROM %s e", ContainsArrays::class),
36+
// Column references
37+
\sprintf('SELECT ARRAY(e.array1) FROM %s e', ContainsArrays::class),
38+
// Mix of column references and literals
39+
\sprintf("SELECT ARRAY(e.array1, 'test-value', e.array2) FROM %s e", ContainsArrays::class),
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)