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

Configuration::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0876

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
ccs 5
cts 9
cp 0.5556
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.0876
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