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

RegexpReplace   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 15
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateArguments() 0 8 4
A customizeFunction() 0 3 1
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_REPLACE().
12
 *
13
 * @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
14
 * @since 2.5
15
 *
16
 * @author Colin Doig
17
 */
18
class RegexpReplace extends BaseVariadicFunction
19
{
20
    protected function customizeFunction(): void
21
    {
22
        $this->setFunctionPrototype('regexp_replace(%s)');
23
    }
24
25
    protected function validateArguments(Node ...$arguments): void
26
    {
27
        $argumentCount = \count($arguments);
28
        if ($argumentCount < 2 || $argumentCount > 5) {
29
            throw InvalidArgumentForVariadicFunctionException::between('regexp_substr', 2, 5);
30
        }
31
        if ($argumentCount === 4) {
32
            throw InvalidArgumentForVariadicFunctionException::unsupportedCombination('regexp_substr', 4, 'start and N parameter shall be used together');
33
        }
34
    }
35
}
36