Passed
Push — master ( 3ca513...8938d5 )
by Sylvain
12:59
created

ReconcileTransactionLine::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 22
rs 9.7998
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Api\Helper;
8
use Application\Model\Transaction;
9
use Application\Model\TransactionLine;
10
use Application\Repository\TransactionRepository;
11
use Ecodev\Felix\Api\Field\FieldInterface;
12
use GraphQL\Type\Definition\Type;
13
use Mezzio\Session\SessionInterface;
14
15
abstract class ReconcileTransactionLine implements FieldInterface
16
{
17
    public static function build(): array
18
    {
19
        return [
20
            'name' => 'reconcileTransactionLine',
21
            'type' => Type::nonNull(_types()->getOutput(TransactionLine::class)),
22
            'description' => 'Update the reconcile flag of a line of transaction',
23
            'args' => [
24
                'id' => Type::nonNull(_types()->getId(TransactionLine::class)),
25
                'isReconciled' => Type::nonNull(Type::boolean()),
26
            ],
27
            'resolve' => function ($root, array $args, SessionInterface $session): TransactionLine {
28
                /** @var TransactionLine $line */
29
                $line = $args['id']->getEntity();
30
                $isReconciled = (bool) $args['isReconciled'];
31
32
                // Check ACL
33
                Helper::throwIfDenied($line->getTransaction(), 'update');
34
                $line->setIsReconciled($isReconciled);
35
36
                _em()->flush();
37
38
                return $line;
39
            },
40
        ];
41
    }
42
}
43