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

RegexpCount::customizeFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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_COUNT().
12
 *
13
 * Returns the number of times the POSIX regular expression pattern matches in the string.
14
 *
15
 * @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
16
 * @since 3.1
17
 *
18
 * @author Martin Georgiev <[email protected]>
19
 *
20
 * @example Using it in DQL: "SELECT REGEXP_COUNT(e.text, '\d\d\d') FROM Entity e"
21
 */
22
class RegexpCount extends BaseVariadicFunction
23
{
24
    protected function customizeFunction(): void
25
    {
26
        $this->setFunctionPrototype('regexp_count(%s)');
27
    }
28
29
    protected function validateArguments(Node ...$arguments): void
30
    {
31
        $argumentCount = \count($arguments);
32
        if ($argumentCount < 2 || $argumentCount > 4) {
33
            throw InvalidArgumentForVariadicFunctionException::between('regexp_count', 2, 4);
34
        }
35
    }
36
}
37