ExtraStatistics   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
c 0
b 0
f 0
dl 0
loc 22
ccs 9
cts 14
cp 0.6429
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Query;
6
7
use Application\Enum\Site;
8
use Application\Model\Statistic;
9
use Application\Model\User;
10
use Application\Repository\StatisticRepository;
11
use Ecodev\Felix\Api\Field\FieldInterface;
12
use GraphQL\Type\Definition\Type;
13
14
abstract class ExtraStatistics implements FieldInterface
15
{
16 1
    public static function build(): iterable
17
    {
18 1
        yield 'extraStatistics' => fn () => [
19 1
            'type' => Type::nonNull(Type::string()),
20 1
            'description' => 'JSON encoded extra statistics',
21 1
            'args' => [
22 1
                'period' => Type::nonNull(Type::string()),
23 1
                'user' => _types()->getId(User::class),
24 1
            ],
25 1
            'resolve' => function ($root, array $args): string {
26
                /** @var Site $site */
27
                $site = $root['site'];
28
29
                /** @var StatisticRepository $repository */
30
                $repository = _em()->getRepository(Statistic::class);
31
                $user = @$args['user'] ? $args['user']->getEntity() : null;
32
33
                $result = $repository->getExtraStatistics($site, $args['period'], $user);
34
35
                return json_encode($result);
36 1
            },
37 1
        ];
38
    }
39
}
40