UpdateOrderLine::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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