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

AbstractOperator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 29
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 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