Passed
Push — validate-arguments-for-variadi... ( 03b437 )
by Martin
03:26
created

ToTsvector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateArguments() 0 5 3
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 MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
8
9
/**
10
 * Implementation of PostgreSQL TO_TSVECTOR().
11
 *
12
 * @see https://www.postgresql.org/docs/9.4/static/textsearch-controls.html
13
 * @since 0.1
14
 *
15
 * @author Martin Georgiev <[email protected]>
16
 */
17
class ToTsvector extends BaseVariadicFunction
18
{
19
    protected string $commonNodeMapping = 'StringExpression';
20
21
    protected function customizeFunction(): void
22
    {
23
        $this->setFunctionPrototype('to_tsvector(%s)');
24
    }
25
26
    protected function validateArguments(array $arguments): void
27
    {
28
        $argumentCount = \count($arguments);
29
        if ($argumentCount < 1 || $argumentCount > 2) {
30
            throw InvalidArgumentForVariadicFunctionException::between('to_tsvector', 1, 2);
31
        }
32
    }
33
}
34