Passed
Push — master ( fd7c1e...90cfdb )
by Adrien
14:46
created

ExportAccountingReport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 27
ccs 9
cts 15
cp 0.6
rs 10
c 0
b 0
f 0

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\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
            ],
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
35
                // Select root accounts
36
                /** @var AccountRepository $accountRepository */
37
                $accountRepository = _em()->getRepository(Account::class);
38
                $rootAccountsQuery = $accountRepository->getRootAccountsQuery();
39
40
                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 array, 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

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