Failed Conditions
Push — master ( 9e07c2...acb8eb )
by Adrien
07:10
created

UpdateTransaction::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 1
nop 0
dl 0
loc 28
rs 9.6333
c 0
b 0
f 0
ccs 16
cts 16
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Api\Field\FieldInterface;
8
use Application\Api\Helper;
9
use Application\Model\Transaction;
10
use Application\Model\TransactionLine;
11
use GraphQL\Type\Definition\Type;
12
use Zend\Expressive\Session\SessionInterface;
13
14
abstract class UpdateTransaction implements FieldInterface
15
{
16 2
    public static function build(): array
17
    {
18
        return [
19 1
            'name' => 'updateTransaction',
20 1
            'type' => Type::nonNull(_types()->getOutput(Transaction::class)),
21 1
            'description' => 'Update a transaction, and optionally replace all its transaction lines if given any',
22
            'args' => [
23 1
                'id' => Type::nonNull(_types()->getId(Transaction::class)),
24 1
                'input' => Type::nonNull(_types()->getPartialInput(Transaction::class)),
25 1
                'lines' => Type::listOf(Type::nonNull(_types()->getInput(TransactionLine::class))),
26
            ],
27
            'resolve' => function ($root, array $args, SessionInterface $session): Transaction {
1 ignored issue
show
Unused Code introduced by
The parameter $session is not used and could be removed. ( Ignorable by Annotation )

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

27
            'resolve' => function ($root, array $args, /** @scrutinizer ignore-unused */ SessionInterface $session): Transaction {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                // Do it
29 2
                $transaction = $args['id']->getEntity();
30 2
                $input = $args['input'];
31 2
                Helper::hydrate($transaction, $input);
32
33
                // Check ACL
34 2
                Helper::throwIfDenied($transaction, 'update');
35 2
                $lines = $args['lines'];
36
37 2
                if ($lines !== null) {
38 1
                    _em()->getRepository(Transaction::class)->hydrateLinesAndFlush($transaction, $lines);
39
                } else {
40 1
                    _em()->flush();
41
                }
42
43 2
                return $transaction;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $transaction could return the type Application\Model\AbstractModel which includes types incompatible with the type-hinted return Application\Model\Transaction. Consider adding an additional type-check to rule them out.
Loading history...
44 1
            },
45
        ];
46
    }
47
}
48