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

AbstractOperator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Definition\Operator;
6
7
use GraphQL\Doctrine\Types;
8
use GraphQL\Doctrine\Utils;
9
use GraphQL\Type\Definition\InputObjectType;
10
use GraphQL\Type\Definition\LeafType;
11
12
/**
13
 * Abstract class that must be implemented to define custom filter options.
14
 *
15
 * Once implemented its FQCN should be used via `API\Filter` annotation.
16
 */
17
abstract class AbstractOperator extends InputObjectType
18
{
19 29
    final public function __construct(Types $types, LeafType $leafType)
20
    {
21 29
        $config = $this->getConfiguration($types, $leafType);
22
23
        // Override type name to be predictable
24 29
        $config['name'] = Utils::getOperatorTypeName(get_class($this), $leafType);
25
26 29
        parent::__construct($config);
27 29
    }
28
29
    /**
30
     * Return the GraphQL type configuration for an `InputObjectType`.
31
     *
32
     * This should declare all custom fields needed to apply the filter. In most
33
     * cases it would include a field such as `value` or `values`, and possibly other
34
     * more specific fields.
35
     *
36
     * The type name, usually configured with the `name` key, should not be defined and
37
     * will be overridden in all cases. This is because we must have a predictable name
38
     * that is based only on the class name.
39
     *
40
     * @param Types $types
41
     * @param LeafType $leafType
42
     *
43
     * @return array
44
     */
45
    abstract protected function getConfiguration(Types $types, LeafType $leafType): array;
46
}
47