Passed
Push — master ( 1d5fb4...e5c3c4 )
by Sam
06:33 queued 01:55
created

Configuration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 1
eloc 12
dl 0
loc 20
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Query;
6
7
use Application\Repository\ConfigurationRepository;
8
use Ecodev\Felix\Api\Field\FieldInterface;
9
use GraphQL\Type\Definition\Type;
10
11
abstract class Configuration implements FieldInterface
12
{
13 1
    public static function build(): array
14
    {
15
        return
16
            [
17 1
                'name' => 'configuration',
18 1
                'type' => Type::nonNull(Type::string()),
19
                'description' => 'Return configuration value for given key. The value might be any format (HTML, JSON, text) as defined by client',
20
                'args' => [
21 1
                    'key' => Type::nonNull(Type::string()),
22
                ],
23 1
                'resolve' => function ($root, array $args): string {
24
                    $key = $args['key'];
25
26
                    /** @var ConfigurationRepository $configurationRepository */
27
                    $configurationRepository = _em()->getRepository(\Application\Model\Configuration::class);
28
                    $configuration = $configurationRepository->getOrCreate($key);
29
30
                    return $configuration->getValue();
31
                },
32
            ];
33
    }
34
}
35