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

ExportAccountingReport   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 52.63%

Importance

Changes 0
Metric Value
wmc 3
eloc 19
c 0
b 0
f 0
dl 0
loc 32
ccs 10
cts 19
cp 0.5263
rs 10

1 Method

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