Passed
Push — master ( 3ba489...3505e6 )
by Adrien
11:36
created

Configuration::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.064

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 18
ccs 6
cts 10
cp 0.6
crap 1.064
rs 9.9
c 1
b 0
f 0
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 1
                '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 1
                },
32
            ];
33
    }
34
}
35