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

AbstractSimpleOperator::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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