Failed Conditions
Push — master ( 4b335d...ccf9db )
by Sylvain
07:33
created

AccountingReport::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 12
cp 0.5
rs 9.7998
cc 2
nc 1
nop 0
crap 2.5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Handler\ExportAccountingReportHandler;
8
use Application\Model\Account;
9
use Application\Repository\AccountRepository;
10
use Ecodev\Felix\Api\Field\FieldInterface;
11
use GraphQL\Type\Definition\Type;
12
use Mezzio\Session\SessionInterface;
13
14
abstract class AccountingReport implements FieldInterface
15
{
16 1
    public static function build(): array
17
    {
18
        return [
19 1
            'name' => 'accountingReport',
20 1
            'type' => Type::string(),
21 1
            'description' => 'Prepare an accounting report and return the URL to download it',
22
            'args' => [
23 1
                'date' => _types()->get('Date'),
24
            ],
25 1
            'resolve' => function ($root, array $args, SessionInterface $session): string {
26
                global $container;
27
28
                /** @var ExportAccountingReportHandler $exporter */
29
                $exporter = $container->get(ExportAccountingReportHandler::class);
30
31
                if ($args['date']) {
32
                    $exporter->setDate($args['date']);
33
                }
34
35
                // Select root accounts
36
                /** @var AccountRepository $accountRepository */
37
                $accountRepository = _em()->getRepository(Account::class);
38
                $rootAccountsQuery = $accountRepository->getRootAccountsQuery();
39
40
                return $exporter->generate($rootAccountsQuery);
41 1
            },
42
        ];
43
    }
44
}
45