Conditions | 3 |
Paths | 1 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3.004 |
Changes | 0 |
1 | <?php |
||
16 | 1 | public static function build(): array |
|
17 | { |
||
18 | return [ |
||
19 | 1 | 'name' => 'invoice', |
|
20 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
21 | 1 | 'description' => 'Create transactions and send a notification to invoice the given user. It may do nothing at all if not necessary', |
|
22 | 'args' => [ |
||
23 | 1 | 'id' => Type::nonNull(_types()->getId(User::class)), |
|
24 | ], |
||
25 | 'resolve' => function ($root, array $args, SessionInterface $session): bool { |
||
26 | 1 | global $container; |
|
27 | |||
28 | // TODO: poor way to do ACL check, we should find something better integrated in real ACL |
||
29 | 1 | $user = User::getCurrent(); |
|
30 | 1 | if (!$user || !in_array($user->getRole(), [User::ROLE_RESPONSIBLE, User::ROLE_ADMINISTRATOR], true)) { |
|
31 | throw new Exception('Not allowed to send invoices'); |
||
32 | } |
||
33 | |||
34 | /** @var Invoicer $invoicer */ |
||
35 | 1 | $invoicer = $container->get(Invoicer::class); |
|
36 | 1 | $userToInvoice = $args['id']->getEntity(); |
|
37 | |||
38 | 1 | $invoicer->invoice($userToInvoice); |
|
39 | |||
40 | 1 | return true; |
|
41 | 1 | }, |
|
45 |