Passed
Push — master ( 047bc4...a2fa3c )
by Sylvain
06:10
created

ExportAccountingReport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 58.81%

Importance

Changes 0
Metric Value
wmc 2
eloc 17
c 0
b 0
f 0
dl 0
loc 29
ccs 10
cts 17
cp 0.5881
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 27 2
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(): array
17
    {
18 1
        return [
19 1
            'name' => 'exportAccountingReport',
20 1
            'type' => Type::nonNull(Type::string()),
21 1
            'description' => 'Prepare an accounting report and return the URL to download it',
22 1
            'args' => [
23 1
                'date' => _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
                $exporter->showBudget($args['showBudget']);
36
37
                // Select root accounts
38
                /** @var AccountRepository $accountRepository */
39
                $accountRepository = _em()->getRepository(Account::class);
40
                $rootAccountsQuery = $accountRepository->getRootAccountsQuery();
41
42
                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

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