Passed
Pull Request — master (#45)
by Andrey
13:21
created

ConcatService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getArguments() 0 18 1
A complexity() 0 3 1
A resolve() 0 3 1
A getType() 0 3 1
A getMode() 0 3 1
A getDeprecationReason() 0 3 1
A getDescription() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Field;
6
7
use Andi\GraphQL\Argument\Argument;
8
use Andi\GraphQL\Definition\Field\ArgumentsAwareInterface;
9
use Andi\GraphQL\Definition\Field\ComplexityAwareInterface;
10
use Andi\GraphQL\Definition\Field\ResolveAwareInterface;
11
use Andi\GraphQL\Definition\Field\TypeAwareInterface;
12
use Andi\GraphQL\Field\MutationFieldInterface;
13
use Andi\GraphQL\Field\QueryFieldInterface;
14
use GraphQL\Type\Definition as Webonyx;
15
16
final class ConcatService implements
17
    QueryFieldInterface,
18
    MutationFieldInterface,
19
    ArgumentsAwareInterface,
20
    ResolveAwareInterface,
21
    ComplexityAwareInterface
22
{
23
    public function getName(): string
24
    {
25
        return 'concat';
26
    }
27
28
    public function getDescription(): ?string
29
    {
30
        return null;
31
    }
32
33
    public function getDeprecationReason(): ?string
34
    {
35
        return null;
36
    }
37
38
    public function getType(): string
39
    {
40
        return Webonyx\StringType::class;
41
    }
42
43
    public function getMode(): int
44
    {
45
        return TypeAwareInterface::IS_REQUIRED;
46
    }
47
48
    public function getArguments(): iterable
49
    {
50
        yield [
51
            'name' => 'parts',
52
            'type' => Webonyx\Type::nonNull(
53
                Webonyx\Type::listOf(
54
                    Webonyx\Type::nonNull(
55
                        Webonyx\Type::string()
56
                    )
57
                )
58
            ),
59
        ];
60
61
        yield new Argument(
62
            name: 'separator',
63
            type: 'String',
64
            mode: TypeAwareInterface::IS_REQUIRED,
65
            defaultValue: ' ',
66
        );
67
    }
68
69
    public function resolve(mixed $objectValue, array $args, mixed $context, Webonyx\ResolveInfo $info): mixed
70
    {
71
        return implode($args['separator'], $args['parts']);
72
    }
73
74
    public function complexity(int $childrenComplexity, array $args): int
75
    {
76
        return $childrenComplexity + 1;
77
    }
78
}
79