|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode; |
|
8
|
|
|
use Doctrine\ORM\Query\AST\Node; |
|
9
|
|
|
use Doctrine\ORM\Query\Lexer; |
|
10
|
|
|
use Doctrine\ORM\Query\Parser; |
|
11
|
|
|
use Doctrine\ORM\Query\SqlWalker; |
|
12
|
|
|
use Doctrine\ORM\Query\TokenType; |
|
13
|
|
|
use MartinGeorgiev\Utils\DoctrineOrm; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @since 0.1 |
|
17
|
|
|
* |
|
18
|
|
|
* @author Martin Georgiev <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class BaseFunction extends FunctionNode |
|
21
|
|
|
{ |
|
22
|
|
|
protected string $functionPrototype; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var list<string> |
|
|
|
|
|
|
26
|
|
|
*/ |
|
27
|
|
|
protected array $nodesMapping = []; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var list<Node|null> |
|
31
|
|
|
*/ |
|
32
|
|
|
protected array $nodes = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* This method is meant for internal use only, and it is not suggested that the forks of the library depend on it. |
|
36
|
|
|
* |
|
37
|
|
|
* @internal |
|
38
|
|
|
*/ |
|
39
|
|
|
abstract protected function customizeFunction(): void; |
|
40
|
|
|
|
|
41
|
303 |
|
protected function setFunctionPrototype(string $functionPrototype): void |
|
42
|
|
|
{ |
|
43
|
303 |
|
$this->functionPrototype = $functionPrototype; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
172 |
|
protected function addNodeMapping(string $parserMethod): void |
|
47
|
|
|
{ |
|
48
|
172 |
|
$this->nodesMapping[] = $parserMethod; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
296 |
|
public function parse(Parser $parser): void |
|
52
|
|
|
{ |
|
53
|
296 |
|
$shouldUseLexer = DoctrineOrm::isPre219(); |
|
54
|
|
|
|
|
55
|
296 |
|
$this->customizeFunction(); |
|
56
|
|
|
|
|
57
|
296 |
|
$parser->match($shouldUseLexer ? Lexer::T_IDENTIFIER : TokenType::T_IDENTIFIER); |
|
|
|
|
|
|
58
|
296 |
|
$parser->match($shouldUseLexer ? Lexer::T_OPEN_PARENTHESIS : TokenType::T_OPEN_PARENTHESIS); |
|
|
|
|
|
|
59
|
296 |
|
$this->feedParserWithNodes($parser); |
|
60
|
223 |
|
$parser->match($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Feeds given parser with previously set nodes. |
|
65
|
|
|
*/ |
|
66
|
169 |
|
protected function feedParserWithNodes(Parser $parser): void |
|
67
|
|
|
{ |
|
68
|
169 |
|
$nodesMappingCount = \count($this->nodesMapping); |
|
69
|
169 |
|
$lastNode = $nodesMappingCount - 1; |
|
70
|
169 |
|
for ($i = 0; $i < $nodesMappingCount; $i++) { |
|
71
|
167 |
|
$parserMethod = $this->nodesMapping[$i]; |
|
72
|
|
|
// @phpstan-ignore-next-line |
|
73
|
167 |
|
$this->nodes[$i] = $parser->{$parserMethod}(); |
|
74
|
167 |
|
if ($i < $lastNode) { |
|
75
|
112 |
|
$parser->match(\class_exists(TokenType::class) ? TokenType::T_COMMA : Lexer::T_COMMA); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
170 |
|
public function getSql(SqlWalker $sqlWalker): string |
|
81
|
|
|
{ |
|
82
|
170 |
|
$dispatched = []; |
|
83
|
170 |
|
foreach ($this->nodes as $node) { |
|
84
|
168 |
|
$dispatched[] = $node instanceof Node ? $node->dispatch($sqlWalker) : 'null'; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
170 |
|
return \vsprintf($this->functionPrototype, $dispatched); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths