Failed Conditions
Push — master ( ce2a97...d73709 )
by Adrien
13:38 queued 11:33
created

Configuration::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1.037

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
ccs 8
cts 12
cp 0.6667
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.037
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(): iterable
14
    {
15 1
        yield 'configuration' => fn () => [
16 1
            'type' => Type::nonNull(Type::string()),
17 1
            'description' => 'Return configuration value for given key. The value might be any format (HTML, JSON, text) as defined by client',
18 1
            'args' => [
19 1
                'key' => Type::nonNull(Type::string()),
20 1
            ],
21 1
            'resolve' => function ($root, array $args): string {
22
                $key = $args['key'];
23
24
                /** @var ConfigurationRepository $configurationRepository */
25
                $configurationRepository = _em()->getRepository(\Application\Model\Configuration::class);
26
                $configuration = $configurationRepository->getOrCreate($key);
27
28
                return $configuration->getValue();
29 1
            },
30 1
        ];
31
    }
32
}
33