Passed
Push — main ( 5be9c9...995947 )
by Martin
14:57
created

RegexpInstr   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 27
ccs 15
cts 15
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getNodeMappingPattern() 0 9 1
A getMinArgumentCount() 0 3 1
A getMaxArgumentCount() 0 3 1
A getFunctionName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
/**
8
 * Implementation of PostgreSQL REGEXP_INSTR().
9
 *
10
 * Returns the position within string where the Nth match of the POSIX regular expression pattern occurs,
11
 * or zero if there is no such match.
12
 *
13
 * @see https://www.postgresql.org/docs/17/functions-matching.html#FUNCTIONS-POSIX-REGEXP
14
 * @since 3.1
15
 *
16
 * @author Martin Georgiev <[email protected]>
17
 *
18
 * @example Using it in DQL: "SELECT REGEXP_INSTR(e.text, 'c(.)(..)', 1, 1, 0, 'i', 2) FROM Entity e"
19
 */
20
class RegexpInstr extends BaseVariadicFunction
21
{
22 3
    protected function getNodeMappingPattern(): array
23
    {
24 3
        return [
25 3
            'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary,ArithmeticPrimary',
26 3
            'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary',
27 3
            'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary',
28 3
            'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary',
29 3
            'StringPrimary,StringPrimary,ArithmeticPrimary',
30 3
            'StringPrimary,StringPrimary',
31 3
        ];
32
    }
33
34 3
    protected function getFunctionName(): string
35
    {
36 3
        return 'regexp_instr';
37
    }
38
39 3
    protected function getMinArgumentCount(): int
40
    {
41 3
        return 2;
42
    }
43
44 3
    protected function getMaxArgumentCount(): int
45
    {
46 3
        return 7;
47
    }
48
}
49