Test Failed
Push — renovate/major-composer-qa-too... ( 9595c4...d17b72 )
by
unknown
13:07
created

RegexpReplace::getNodeMappingPattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 13
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
/**
8
 * Implementation of PostgreSQL REGEXP_REPLACE().
9
 *
10
 * Replaces substring(s) matching a POSIX regular expression pattern with a replacement string.
11
 *
12
 * @see https://www.postgresql.org/docs/17/functions-matching.html#FUNCTIONS-POSIX-REGEXP
13
 * @since 2.5
14
 *
15
 * @author Colin Doig
16
 * @author Martin Georgiev <[email protected]>
17
 *
18
 * @example Using it in DQL: "SELECT REGEXP_REPLACE(e.text, 'pattern', 'replacement', 3, 2, 'i') FROM Entity e"
19
 */
20
class RegexpReplace extends BaseVariadicFunction
21
{
22
    protected function getNodeMappingPattern(): array
23
    {
24
        /*
25
         * PostgreSQL overloads the 4th argument depending on its type:
26
         *   - if the 4th arg is a string, it’s taken as flags.
27
         *   - if the 4th arg is an integer, it’s taken as start position. This can be extended with the Nth argument.
28
         */
29
        return [
30
            'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary', // with start, N and flags: regexp_replace(string, pattern, replacement, 3, 2, 'i')
31
            'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary', // with start and N: regexp_replace(string, pattern, replacement, 3, 2)
32
            'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary', // with start: regexp_replace(string, pattern, replacement, 3)
33
            'StringPrimary,StringPrimary,StringPrimary,StringPrimary', // with flags: regexp_replace(string, pattern, replacement, 'i')
34
            'StringPrimary,StringPrimary,StringPrimary', // basic replacement: regexp_replace(string, pattern, replacement)
35
        ];
36
    }
37
38
    protected function getFunctionName(): string
39
    {
40
        return 'regexp_replace';
41
    }
42
43
    protected function getMinArgumentCount(): int
44
    {
45
        return 3;
46
    }
47
48
    protected function getMaxArgumentCount(): int
49
    {
50
        return 6;
51
    }
52
}
53