Failed Conditions
Push — master ( 044ed2...482608 )
by Adrien
03:59
created

ExportAccountingReport::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.3349

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
ccs 9
cts 16
cp 0.5625
rs 9.7666
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2.3349
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' => _types()->get('Date'),
23 1
                'showBudget' => Type::nonNull(Type::boolean()),
24 1
            ],
25 1
            'resolve' => function ($root, array $args, SessionInterface $session): string {
26
                global $container;
27
28
                /** @var AccountingReport $exporter */
29
                $exporter = $container->get(AccountingReport::class);
30
31
                if ($args['date']) {
32
                    $exporter->setDate($args['date']);
33
                }
34
                $exporter->showBudget($args['showBudget']);
35
36
                // Select root accounts
37
                /** @var AccountRepository $accountRepository */
38
                $accountRepository = _em()->getRepository(Account::class);
39
                $rootAccountsQuery = $accountRepository->getRootAccountsQuery();
40
41
                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

41
                return $exporter->export(/** @scrutinizer ignore-type */ $rootAccountsQuery->getResult());
Loading history...
42 1
            },
43 1
        ];
44
    }
45
}
46