Skip to content

Commit a960738

Browse files
Merge branch 'main' into new-json-functions
2 parents f0f3c9f + 1d49d25 commit a960738

34 files changed

+242
-19
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"require-dev": {
4646
"doctrine/orm": "~2.14||~3.0",
4747
"ekino/phpstan-banned-code": "^1.0",
48-
"friendsofphp/php-cs-fixer": "^3.71.0",
48+
"friendsofphp/php-cs-fixer": "^3.72.0",
4949
"php-coveralls/php-coveralls": "^2.7.0",
5050
"phpstan/phpstan": "^1.12.21",
5151
"phpstan/phpstan-phpunit": "^1.4.2",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL check if all texts on the right side exist on the left-side JSONB (using ?&).
99
*
1010
* @see https://www.postgresql.org/docs/14/functions-json.html
11-
* @since 2.3.0
11+
* @since 2.3
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL check if any text on the right side exists on the left-side JSONB (using ?|).
99
*
1010
* @see https://www.postgresql.org/docs/14/functions-json.html
11-
* @since 2.3.0
11+
* @since 2.3
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function feedParserWithNodes(Parser $parser): void
3838
}
3939
$aheadType = $lexer->lookahead->type;
4040
}
41+
42+
$this->validateArguments($this->nodes);
4143
}
4244

4345
public function getSql(SqlWalker $sqlWalker): string
@@ -49,4 +51,11 @@ public function getSql(SqlWalker $sqlWalker): string
4951

5052
return \sprintf($this->functionPrototype, \implode(', ', $dispatched));
5153
}
54+
55+
/**
56+
* Validates the arguments passed to the function.
57+
*
58+
* @param mixed[] $arguments The array of arguments to validate
59+
*/
60+
abstract protected function validateArguments(array $arguments): void;
5261
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL DATERANGE().
99
*
1010
* @see https://www.postgresql.org/docs/17/rangetypes.html
11-
* @since 2.9.0
11+
* @since 2.9
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL deletion of a field at the specified path (using #-).
99
*
1010
* @see https://www.postgresql.org/docs/14/functions-json.html
11-
* @since 2.3.0
11+
* @since 2.3
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception;
6+
7+
class InvalidArgumentForVariadicFunctionException extends \InvalidArgumentException
8+
{
9+
public static function exactCount(string $functionName, int $expected): self
10+
{
11+
return new self(\sprintf(
12+
'%s() requires exactly %d argument%s',
13+
$functionName,
14+
$expected,
15+
$expected === 1 ? '' : 's'
16+
));
17+
}
18+
19+
public static function atLeast(string $functionName, int $min): self
20+
{
21+
return new self(\sprintf(
22+
'%s() requires at least %d argument%s',
23+
$functionName,
24+
$min,
25+
$min === 1 ? '' : 's'
26+
));
27+
}
28+
29+
public static function between(string $functionName, int $min, int $max): self
30+
{
31+
return new self(\sprintf(
32+
'%s() requires between %d and %d arguments',
33+
$functionName,
34+
$min,
35+
$max
36+
));
37+
}
38+
39+
public static function evenNumber(string $functionName): self
40+
{
41+
return new self(\sprintf(
42+
'%s() requires an even number of arguments',
43+
$functionName
44+
));
45+
}
46+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL REGEXP_REPLACE().
99
*
1010
* @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
11-
* @since 2.5.0
11+
* @since 2.5
1212
*
1313
* @author Colin Doig
1414
*/

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

Lines changed: 10 additions & 0 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 GREATEST().
911
*
@@ -18,4 +20,12 @@ protected function customizeFunction(): void
1820
{
1921
$this->setFunctionPrototype('greatest(%s)');
2022
}
23+
24+
protected function validateArguments(array $arguments): void
25+
{
26+
$argumentCount = \count($arguments);
27+
if ($argumentCount < 2) {
28+
throw InvalidArgumentForVariadicFunctionException::atLeast('greatest', 2);
29+
}
30+
}
2131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Implementation of PostgreSQL INT4RANGE().
99
*
1010
* @see https://www.postgresql.org/docs/17/rangetypes.html
11-
* @since 2.9.0
11+
* @since 2.9
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/

0 commit comments

Comments
 (0)