Issues (169)

src/Field/ObjectField.php (1 issue)

Labels
Severity
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
/**
13
 * @see Webonyx\FieldDefinition
14
 *
15
 * @phpstan-import-type FieldDefinitionConfig from Webonyx\FieldDefinition
16
 */
17
final class ObjectField extends Webonyx\FieldDefinition
18
{
19
    /**
20
     * @param FieldDefinitionConfig $config
0 ignored issues
show
The type Andi\GraphQL\Field\FieldDefinitionConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
     * @param string $method
22
     * @param array<string,string> $argumentsMap
23
     * @param ScopeInterface $scope
24
     * @param InvokerInterface $invoker
25
     */
26 3
    public function __construct(
27
        array $config,
28
        private readonly string $method,
29
        private readonly array $argumentsMap,
30
        private readonly ScopeInterface $scope,
31
        private readonly InvokerInterface $invoker,
32
    ) {
33 3
        $config['resolve'] = $this->resolve(...);
34
35 3
        parent::__construct($config);
36
    }
37
38
    /**
39
     * @param mixed $object
40
     * @param array<string,mixed> $args
41
     * @param mixed $context
42
     * @param Webonyx\ResolveInfo $info
43
     *
44
     * @return mixed
45
     */
46 3
    private function resolve(
47
        mixed $object,
48
        array $args,
49
        mixed $context,
50
        Webonyx\ResolveInfo $info,
51
    ): mixed {
52 3
        $parameters = [];
53 3
        foreach ($args as $name => $value) {
54 3
            $parameters[$this->argumentsMap[$name] ?? $name] = $value;
55
        }
56
57 3
        return $this->scope->runScope(
58 3
            [ResolverArguments::class => new ResolverArguments($object, $args, $context, $info)],
59 3
            fn () => $this->invoker->invoke([$object, $this->method], $parameters),
60 3
        );
61
    }
62
}
63