AbstractSimpleOperator::getConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
rs 10
ccs 11
cts 11
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Definition\Operator;
6
7
use Doctrine\ORM\Mapping\ClassMetadata;
8
use Doctrine\ORM\QueryBuilder;
9
use GraphQL\Doctrine\Factory\UniqueNameFactory;
10
use GraphQL\Type\Definition\LeafType;
11
12
/**
13
 * A simple operator with two operands.
14
 */
15
abstract class AbstractSimpleOperator extends AbstractOperator
16
{
17
    abstract protected function getDqlOperator(bool $isNot): string;
18
19 33
    final protected function getConfiguration(LeafType $leafType): array
20
    {
21 33
        return [
22 33
            'fields' => [
23 33
                [
24 33
                    'name' => 'value',
25 33
                    'type' => self::nonNull($leafType),
26 33
                ],
27 33
                [
28 33
                    'name' => 'not',
29 33
                    'type' => self::boolean(),
30 33
                    'defaultValue' => false,
31 33
                ],
32 33
            ],
33 33
        ];
34
    }
35
36 25
    final public function getDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetadata $metadata, QueryBuilder $queryBuilder, string $alias, string $field, ?array $args): string
37
    {
38 25
        if ($args === null) {
0 ignored issues
show
introduced by
The condition $args === null is always false.
Loading history...
39 6
            return '';
40
        }
41
42 19
        $param = $uniqueNameFactory->createParameterName();
43 19
        $queryBuilder->setParameter($param, $args['value']);
44
45 19
        return $alias . '.' . $field . ' ' . $this->getDqlOperator($args['not']) . ' :' . $param;
46
    }
47
}
48