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

AccountingReport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 27
ccs 6
cts 12
cp 0.5
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 25 2
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