ReconcileTransactionLine   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 14
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 21 1
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\TransactionLine;
9
use Ecodev\Felix\Api\Field\FieldInterface;
10
use GraphQL\Type\Definition\Type;
11
use Mezzio\Session\SessionInterface;
12
13
abstract class ReconcileTransactionLine implements FieldInterface
14
{
15 1
    public static function build(): iterable
16
    {
17 1
        yield 'reconcileTransactionLine' => fn () => [
18 1
            'type' => Type::nonNull(_types()->getOutput(TransactionLine::class)),
19 1
            'description' => 'Update the reconcile flag of a line of transaction',
20 1
            'args' => [
21 1
                'id' => Type::nonNull(_types()->getId(TransactionLine::class)),
22 1
                'isReconciled' => Type::nonNull(Type::boolean()),
23 1
            ],
24 1
            'resolve' => function ($root, array $args, SessionInterface $session): TransactionLine {
25
                /** @var TransactionLine $line */
26 1
                $line = $args['id']->getEntity();
27 1
                $isReconciled = (bool) $args['isReconciled'];
28
29
                // Check ACL
30 1
                Helper::throwIfDenied($line->getTransaction(), 'update');
31 1
                $line->setIsReconciled($isReconciled);
32
33 1
                _em()->flush();
34
35 1
                return $line;
36 1
            },
37 1
        ];
38
    }
39
}
40