Passed
Push — master ( 898411...5b804b )
by Andrey
56s queued 13s
created

OuterObjectField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 45
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A resolve() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Field;
6
7
use Andi\GraphQL\Common\ResolverArguments;
8
use GraphQL\Type\Definition as Webonyx;
9
use Spiral\Core\InvokerInterface;
10
use Spiral\Core\ScopeInterface;
11
12
final class OuterObjectField extends Webonyx\FieldDefinition
13
{
14
    /**
15
     * @param array $config
16
     * @param class-string $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
17
     * @param string $method
18
     * @param array<string,string> $argumentsMap
19
     * @param ScopeInterface $scope
20
     * @param InvokerInterface $invoker
21
     */
22 3
    public function __construct(
23
        array $config,
24
        private readonly string $class,
25
        private readonly string $method,
26
        private readonly array $argumentsMap,
27
        private readonly ScopeInterface $scope,
28
        private readonly InvokerInterface $invoker,
29
    ) {
30 3
        $config['resolve'] = $this->resolve(...);
31
32 3
        parent::__construct($config);
33
    }
34
35
    /**
36
     * @param mixed $object
37
     * @param array<string,mixed> $args
38
     * @param mixed $context
39
     * @param Webonyx\ResolveInfo $info
40
     *
41
     * @return mixed
42
     */
43 3
    private function resolve(
44
        mixed $object,
45
        array $args,
46
        mixed $context,
47
        Webonyx\ResolveInfo $info,
48
    ): mixed {
49 3
        $parameters = [];
50 3
        foreach ($args as $name => $value) {
51 3
            $parameters[$this->argumentsMap[$name] ?? $name] = $value;
52
        }
53
54 3
        return $this->scope->runScope(
55 3
            [ResolverArguments::class => new ResolverArguments($object, $args, $context, $info)],
56 3
            fn () => $this->invoker->invoke([$this->class, $this->method], $parameters),
57 3
        );
58
    }
59
}
60