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

ValidateExport::build()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2.0094

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
ccs 13
cts 15
cp 0.8667
rs 9.7666
cc 2
nc 1
nop 0
crap 2.0094
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Query;
6
7
use Application\Api\Field\Mutation\CreateExport;
8
use Application\Api\Input\CreateExportInputType;
9
use Ecodev\Felix\Api\Field\FieldInterface;
10
use GraphQL\Error\ClientAware;
11
use GraphQL\Type\Definition\Type;
12
13
class ValidateExport implements FieldInterface
14
{
15 1
    public static function build(): array
16
    {
17 1
        return [
18 1
            'name' => 'validateExport',
19 1
            'type' => Type::string(),
20 1
            'description' => 'Validates that a new export can indeed be created. If valid return `null`, else return a message to be shown to end-user.',
21 1
            'args' => [
22 1
                'input' => Type::nonNull(_types()->get(CreateExportInputType::class)),
0 ignored issues
show
Bug introduced by
_types()->get(Applicatio...ExportInputType::class) 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

22
                'input' => Type::nonNull(/** @scrutinizer ignore-type */ _types()->get(CreateExportInputType::class)),
Loading history...
23 1
            ],
24 1
            'resolve' => function (array $root, array $args): ?string {
25 1
                _em()->beginTransaction();
26
27
                try {
28 1
                    CreateExport::create($args);
29
                } catch (ClientAware $e) {
30
                    return $e->getMessage();
31
                } finally {
32
                    // Never keep things in DB
33 1
                    _em()->rollback();
34
                }
35
36 1
                return null;
37 1
            },
38 1
        ];
39
    }
40
}
41