Test Failed
Push — regexp ( bbbe5d )
by Martin
12:32 queued 21s
created

RegexpInstr   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 12
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A customizeFunction() 0 3 1
A validateArguments() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\AST\Node;
8
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
9
10
/**
11
 * Implementation of PostgreSQL REGEXP_INSTR().
12
 *
13
 * Returns the position within string where the Nth match of the POSIX regular expression pattern occurs,
14
 * or zero if there is no such match.
15
 *
16
 * @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
17
 * @since 3.1
18
 *
19
 * @author Martin Georgiev <[email protected]>
20
 *
21
 * @example Using it in DQL: "SELECT REGEXP_INSTR(e.text, 'c(.)(..)', 1, 1, 0, 'i') FROM Entity e"
22
 */
23
class RegexpInstr extends BaseVariadicFunction
24
{
25
    protected function customizeFunction(): void
26
    {
27
        $this->setFunctionPrototype('regexp_instr(%s)');
28
    }
29
30
    protected function validateArguments(Node ...$arguments): void
31
    {
32
        $argumentCount = \count($arguments);
33
        if ($argumentCount < 2 || $argumentCount > 6) {
34
            throw InvalidArgumentForVariadicFunctionException::between('regexp_instr', 2, 6);
35
        }
36
    }
37
}
38