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
|
|
|
* TODO Make abstract when {@see customiseFunction()} is no more |
36
|
|
|
*/ |
37
|
|
|
protected function customizeFunction(): void |
38
|
|
|
{ |
39
|
|
|
// Void |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @deprecated |
44
|
|
|
*/ |
45
|
|
|
protected function customiseFunction(): void |
46
|
|
|
{ |
47
|
|
|
trigger_error('Method '.__METHOD__.' was renamed to '.__CLASS__.'::customizeFunction().', E_USER_DEPRECATED); |
48
|
|
|
$this->customizeFunction(); |
49
|
|
|
} |
50
|
|
|
|
51
|
100 |
|
protected function setFunctionPrototype(string $functionPrototype): void |
52
|
|
|
{ |
53
|
100 |
|
$this->functionPrototype = $functionPrototype; |
54
|
|
|
} |
55
|
|
|
|
56
|
82 |
|
protected function addNodeMapping(string $parserMethod): void |
57
|
|
|
{ |
58
|
82 |
|
$this->nodesMapping[] = $parserMethod; |
59
|
|
|
} |
60
|
|
|
|
61
|
98 |
|
public function parse(Parser $parser): void |
62
|
|
|
{ |
63
|
98 |
|
$shouldUseLexer = DoctrineOrm::isPre219(); |
64
|
|
|
|
65
|
98 |
|
$this->customizeFunction(); |
66
|
|
|
|
67
|
98 |
|
$parser->match($shouldUseLexer ? Lexer::T_IDENTIFIER : TokenType::T_IDENTIFIER); |
|
|
|
|
68
|
98 |
|
$parser->match($shouldUseLexer ? Lexer::T_OPEN_PARENTHESIS : TokenType::T_OPEN_PARENTHESIS); |
|
|
|
|
69
|
98 |
|
$this->feedParserWithNodes($parser); |
70
|
91 |
|
$parser->match($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Feeds given parser with previously set nodes. |
75
|
|
|
*/ |
76
|
82 |
|
protected function feedParserWithNodes(Parser $parser): void |
77
|
|
|
{ |
78
|
82 |
|
$nodesMappingCount = \count($this->nodesMapping); |
79
|
82 |
|
$lastNode = $nodesMappingCount - 1; |
80
|
82 |
|
for ($i = 0; $i < $nodesMappingCount; $i++) { |
81
|
82 |
|
$parserMethod = $this->nodesMapping[$i]; |
82
|
|
|
// @phpstan-ignore-next-line |
83
|
82 |
|
$this->nodes[$i] = $parser->{$parserMethod}(); |
84
|
82 |
|
if ($i < $lastNode) { |
85
|
55 |
|
$parser->match(\class_exists(TokenType::class) ? TokenType::T_COMMA : Lexer::T_COMMA); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
82 |
|
public function getSql(SqlWalker $sqlWalker): string |
91
|
|
|
{ |
92
|
82 |
|
$dispatched = []; |
93
|
82 |
|
foreach ($this->nodes as $node) { |
94
|
82 |
|
$dispatched[] = $node instanceof Node ? $node->dispatch($sqlWalker) : 'null'; |
95
|
|
|
} |
96
|
|
|
|
97
|
82 |
|
return \vsprintf($this->functionPrototype, $dispatched); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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