Passed
Push — master ( c8a2a2...d940c2 )
by Sylvain
37:54 queued 29:19
created

ExportAccountingReport::build()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.9566

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 30
ccs 10
cts 19
cp 0.5263
rs 9.6666
cc 3
nc 1
nop 0
crap 3.9566
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Model\Account;
8
use Application\Repository\AccountRepository;
9
use Application\Service\Exporter\AccountingReport;
10
use Ecodev\Felix\Api\Field\FieldInterface;
11
use GraphQL\Type\Definition\Type;
12
use Mezzio\Session\SessionInterface;
13
14
abstract class ExportAccountingReport implements FieldInterface
15
{
16 1
    public static function build(): iterable
17
    {
18 1
        yield 'exportAccountingReport' => fn () => [
19 1
            'type' => Type::nonNull(Type::string()),
20 1
            'description' => 'Prepare an accounting report and return the URL to download it',
21 1
            'args' => [
22 1
                'date' => Type::nonNull(_types()->get('Date')),
23 1
                'datePrevious' => _types()->get('Date'),
24 1
                'showBudget' => Type::nonNull(Type::boolean()),
25 1
            ],
26 1
            'resolve' => function ($root, array $args, SessionInterface $session): string {
27
                global $container;
28
29
                /** @var AccountingReport $exporter */
30
                $exporter = $container->get(AccountingReport::class);
31
32
                if ($args['date']) {
33
                    $exporter->setDate($args['date']);
34
                }
35
                if ($args['datePrevious']) {
36
                    $exporter->setDatePrevious($args['datePrevious']);
37
                }
38
                $exporter->showBudget($args['showBudget']);
39
40
                // Select root accounts
41
                /** @var AccountRepository $accountRepository */
42
                $accountRepository = _em()->getRepository(Account::class);
43
                $rootAccountsQuery = $accountRepository->getRootAccountsQuery();
44
45
                return $exporter->export($rootAccountsQuery->getResult());
0 ignored issues
show
Bug introduced by
It seems like $rootAccountsQuery->getResult() can also be of type integer; however, parameter $items of Application\Service\Expo...tractExporter::export() does only seem to accept iterable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
                return $exporter->export(/** @scrutinizer ignore-type */ $rootAccountsQuery->getResult());
Loading history...
46 1
            },
47 1
        ];
48
    }
49
}
50