Failed Conditions
Pull Request — master (#10)
by Adrien
02:34
created

AbstractSimpleOperator::getDqlCondition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 6
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\Doctrine\Types;
11
use GraphQL\Type\Definition\LeafType;
12
use GraphQL\Type\Definition\Type;
13
14
/**
15
 * A simple operator with two operands
16
 */
17
abstract class AbstractSimpleOperator extends AbstractOperator
18
{
19
    abstract protected function getDqlOperator(bool $isNot): string;
20
21 20
    protected function getConfiguration(Types $types, LeafType $leafType): array
22
    {
23
        return [
24 20
            'fields' => [
25
                [
26 20
                    'name' => 'value',
27 20
                    'type' => Type::nonNull($leafType),
28
                ],
29
                [
30 20
                    'name' => 'not',
31 20
                    'type' => Type::boolean(),
32
                    'defaultValue' => false,
33
                ],
34
            ],
35
        ];
36
    }
37
38 17
    public function getDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetadata $metadata, QueryBuilder $queryBuilder, string $alias, string $field, array $args): string
39
    {
40 17
        $param = $uniqueNameFactory->createParameterName();
41 17
        $queryBuilder->setParameter($param, $args['value']);
42
43 17
        return $alias . '.' . $field . ' ' . $this->getDqlOperator($args['not']) . ' :' . $param;
44
    }
45
}
46