UpdateOrderLine   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 0
loc 33
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 31 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\Api\Input\OrderLineInputType;
9
use Application\Model\OrderLine;
10
use Application\Service\Invoicer;
11
use Ecodev\Felix\Api\Field\FieldInterface;
12
use Ecodev\Felix\Utility;
13
use GraphQL\Type\Definition\Type;
14
use Mezzio\Session\SessionInterface;
15
16
abstract class UpdateOrderLine implements FieldInterface
17
{
18 1
    public static function build(): iterable
19
    {
20 1
        yield 'updateOrderLine' => fn () => [
21 1
            'type' => Type::nonNull(_types()->getOutput(OrderLine::class)),
22 1
            'description' => 'Update an existing orderLine.',
23 1
            'args' => [
24 1
                'id' => Type::nonNull(_types()->getId(OrderLine::class)),
25 1
                'input' => Type::nonNull(_types()->get(OrderLineInputType::class)),
26 1
            ],
27 1
            'resolve' => function ($root, array $args, SessionInterface $session): OrderLine {
28
                global $container;
29
30
                /** @var Invoicer $invoicer */
31 1
                $invoicer = $container->get(Invoicer::class);
32
33
                /** @var OrderLine $orderLine */
34 1
                $orderLine = $args['id']->getEntity();
35 1
                $args['input'] = Utility::entityIdToModel($args['input']);
36
37
                // Check ACL
38 1
                Helper::throwIfDenied($orderLine, 'update');
39
40
                // Do it
41 1
                $invoicer->updateOrderLineAndTransactionLine($orderLine, $args['input']);
42
43 1
                _em()->flush();
44
45 1
                _em()->refresh($orderLine);
46 1
                _em()->refresh($orderLine->getOrder());
47
48 1
                return $orderLine;
49 1
            },
50 1
        ];
51
    }
52
}
53