Passed
Push — master ( f8361b...5ed10a )
by Adrien
07:04
created

NextAccountCode::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.037

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
ccs 4
cts 6
cp 0.6667
rs 10
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\Model\Account;
8
use Application\Repository\AccountRepository;
9
use Ecodev\Felix\Api\Field\FieldInterface;
10
use GraphQL\Type\Definition\Type;
11
12
abstract class NextAccountCode implements FieldInterface
13
{
14 1
    public static function build(): array
15
    {
16
        return
17
            [
18 1
                'name' => 'nextAccountCode',
19 1
                'type' => Type::nonNull(Type::int()),
20
                'description' => 'Next available account code for creation',
21
                'args' => [],
22 1
                'resolve' => function ($root, array $args): int {
23
                    /** @var AccountRepository $repository */
24
                    $repository = _em()->getRepository(Account::class);
25
26
                    return $repository->getNextCodeAvailable();
27
                },
28
            ];
29
    }
30
}
31