Failed Conditions
Push — master ( 27554e...857869 )
by Luca
09:08
created

CreateCards   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 44%

Importance

Changes 0
Metric Value
wmc 2
eloc 25
c 0
b 0
f 0
dl 0
loc 39
ccs 11
cts 25
cp 0.44
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 37 2
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\Card;
9
use Application\Model\Collection;
10
use Application\Service\Importer;
11
use Ecodev\Felix\Api\Field\FieldInterface;
12
use GraphQL\Type\Definition\Type;
13
14
class CreateCards implements FieldInterface
15
{
16 1
    public static function build(): array
17
    {
18 1
        return [
19 1
            'name' => 'createCards',
20 1
            'type' => Type::nonNull(Type::listOf(Type::nonNull(_types()->getOutput(Card::class)))),
21 1
            'description' => 'Create multiple cards from an excel files and several images',
22 1
            'args' => [
23 1
                'excel' => Type::nonNull(_types()->get('Upload')),
0 ignored issues
show
Bug introduced by
_types()->get('Upload') of type GraphQL\Type\Definition\Type is incompatible with the type GraphQL\Type\Definition\NullableType|callable expected by parameter $wrappedType of GraphQL\Type\Definition\Type::nonNull(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
                'excel' => Type::nonNull(/** @scrutinizer ignore-type */ _types()->get('Upload')),
Loading history...
24 1
                'images' => Type::nonNull(Type::listOf(Type::nonNull(_types()->get('Upload')))),
25 1
                'collection' => _types()->getId(Collection::class),
26 1
            ],
27 1
            'resolve' => function (array $root, array $args): array {
28
                $site = $root['site'];
29
30
                // Check ACL
31
                $object = new Card();
32
                $object->setSite($site);
33
                Helper::throwIfDenied($object, 'create');
34
35
                // Get optional collection
36
                if ($args['collection'] ?? false) {
37
                    $collection = $args['collection']->getEntity();
38
                    Helper::throwIfDenied($collection, 'update');
39
                } else {
40
                    $collection = null;
41
                }
42
43
                // Do it
44
                $excel = $args['excel'];
45
                $images = $args['images'];
46
47
                $importer = new Importer();
48
                $cards = $importer->import($excel, $images, $site, $collection);
49
50
                _em()->flush();
51
52
                return $cards;
53 1
            },
54 1
        ];
55
    }
56
}
57