Passed
Push — master ( a8b983...5b3176 )
by Adrien
10:48
created

BankingInfos   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 33
ccs 6
cts 21
cp 0.2857
rs 10
c 0
b 0
f 0
wmc 1

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\Query;
6
7
use Application\Model\User;
8
use Ecodev\Felix\Api\Field\FieldInterface;
9
use Ecodev\Felix\Service\Bvr;
10
use GraphQL\Type\Definition\Type;
11
12
abstract class BankingInfos implements FieldInterface
13
{
14 1
    public static function build(): array
15
    {
16
        return
17
            [
18 1
                'name' => 'bankingInfos',
19 1
                'type' => Type::nonNull(_types()->get('BankingInfos')),
20 1
                'description' => 'Represents currently logged-in user',
21
                'args' => [
22 1
                    'user' => Type::nonNull(_types()->getId(User::class)),
23 1
                    'amount' => _types()->get('CHF'),
24
                ],
25
                'resolve' => function ($root, array $args): array {
26
                    global $container;
27
                    $config = $container->get('config')['banking'];
28
                    $bankAccount = $config['bankAccount'];
29
                    $postAccount = $config['postAccount'];
30
                    $paymentTo = $config['paymentTo'];
31
                    $paymentFor = $config['paymentFor'];
32
33
                    $userId = $args['user']->getId();
34
                    $amount = $args['amount'] ?? null;
35
36
                    $referenceNumber = Bvr::getReferenceNumber($bankAccount, $userId);
37
                    $encodingLine = Bvr::getEncodingLine($bankAccount, $userId, $postAccount, $amount);
38
39
                    return [
40
                        'postAccount' => $postAccount,
41
                        'paymentTo' => $paymentTo,
42
                        'paymentFor' => $paymentFor,
43
                        'referenceNumber' => $referenceNumber,
44
                        'encodingLine' => $encodingLine,
45
                    ];
46 1
                },
47
            ];
48
    }
49
}
50