File tree Expand file tree Collapse file tree 7 files changed +70
-24
lines changed
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions Expand file tree Collapse file tree 7 files changed +70
-24
lines changed Original file line number Diff line number Diff line change @@ -3,19 +3,21 @@ name: Sloth
33on :
44 merge_group :
55 pull_request :
6- branches :
7- - main
6+
7+ permissions :
8+ contents : read
9+ checks : read
810
911jobs :
1012 sloth :
1113 runs-on : ubuntu-latest
1214 steps :
1315 - name : Sloth
14- uses : lendable/sloth@0.2
16+ uses : lendable/sloth@0.2.0
1517 with :
1618 token : ${{ secrets.GITHUB_TOKEN }}
1719 interval : 10
18- ignored :
19- - Auto Request Review
20- - CodeRabbit
21- - Scrutinizer
20+ ignored : |
21+ Auto Request Review
22+ CodeRabbit
23+ Scrutinizer
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MartinGeorgiev \Doctrine \ORM \Query \AST \Functions ;
6+
7+ abstract class BaseRegexpFunction extends BaseFunction
8+ {
9+ abstract protected function getFunctionName (): string ;
10+
11+ abstract protected function getParameterCount (): int ;
12+
13+ protected function customiseFunction (): void
14+ {
15+ $ parameters = \str_repeat (', %s ' , $ this ->getParameterCount () - 1 );
16+ $ this ->setFunctionPrototype ($ this ->getFunctionName ().'(%s ' .$ parameters .') ' );
17+
18+ for ($ i = 0 ; $ i < $ this ->getParameterCount (); $ i ++) {
19+ $ this ->addNodeMapping ('StringPrimary ' );
20+ }
21+ }
22+ }
Original file line number Diff line number Diff line change 99use Doctrine \ORM \Query \Parser ;
1010use Doctrine \ORM \Query \SqlWalker ;
1111use Doctrine \ORM \Query \TokenType ;
12+ use MartinGeorgiev \Doctrine \ORM \Query \AST \Functions \Exception \ParserException ;
1213use MartinGeorgiev \Utils \DoctrineOrm ;
1314
1415/**
@@ -24,7 +25,7 @@ public function feedParserWithNodes(Parser $parser): void
2425
2526 $ this ->nodes [] = $ parser ->{$ this ->commonNodeMapping }();
2627 if ($ lexer ->lookahead ?->type === null ) {
27- throw new \ RuntimeException ( ' The parser \' s "lookahead" property is not populated with a type ' );
28+ throw ParserException:: missingLookaheadType ( );
2829 }
2930
3031 $ aheadType = $ lexer ->lookahead ->type ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MartinGeorgiev \Doctrine \ORM \Query \AST \Functions \Exception ;
6+
7+ class ParserException extends \RuntimeException
8+ {
9+ public static function missingLookaheadType (): self
10+ {
11+ return new self ('The parser \'s "lookahead" property is not populated with a type ' );
12+ }
13+ }
Original file line number Diff line number Diff line change 1212 *
1313 * @author Martin Georgiev <martin.georgiev@gmail.com>
1414 */
15- class RegexpLike extends BaseFunction
15+ class RegexpLike extends BaseRegexpFunction
1616{
17- protected function customiseFunction (): void
17+ protected function getFunctionName (): string
1818 {
19- $ this ->setFunctionPrototype ('regexp_like(%s, %s) ' );
20- $ this ->addNodeMapping ('StringPrimary ' );
21- $ this ->addNodeMapping ('StringPrimary ' );
19+ return 'regexp_like ' ;
20+ }
21+
22+ protected function getParameterCount (): int
23+ {
24+ return 2 ;
2225 }
2326}
Original file line number Diff line number Diff line change 1212 *
1313 * @author Martin Georgiev <martin.georgiev@gmail.com>
1414 */
15- class RegexpMatch extends BaseFunction
15+ class RegexpMatch extends BaseRegexpFunction
1616{
17- protected function customiseFunction (): void
17+ protected function getFunctionName (): string
1818 {
19- $ this ->setFunctionPrototype ('regexp_match(%s, %s) ' );
20- $ this ->addNodeMapping ('StringPrimary ' );
21- $ this ->addNodeMapping ('StringPrimary ' );
19+ return 'regexp_match ' ;
20+ }
21+
22+ protected function getParameterCount (): int
23+ {
24+ return 2 ;
2225 }
2326}
Original file line number Diff line number Diff line change 1212 *
1313 * @author Colin Doig
1414 */
15- class RegexpReplace extends BaseFunction
15+ class RegexpReplace extends BaseRegexpFunction
1616{
17- protected function customiseFunction (): void
17+ protected function getFunctionName (): string
1818 {
19- $ this ->setFunctionPrototype ('regexp_replace(%s, %s, %s) ' );
20- $ this ->addNodeMapping ('StringPrimary ' );
21- $ this ->addNodeMapping ('StringPrimary ' );
22- $ this ->addNodeMapping ('StringPrimary ' );
19+ return 'regexp_replace ' ;
20+ }
21+
22+ protected function getParameterCount (): int
23+ {
24+ return 3 ;
2325 }
2426}
You can’t perform that action at this time.
0 commit comments