Completed
Push — master ( 21b622...3b01e2 )
by Jose Manuel
01:29
created

DeferredResolverTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A deferredResolver() 0 16 2
1
<?php
2
3
namespace Joskfg\GraphQLBulk;
4
5
use GraphQL\Deferred;
6
use Joskfg\GraphQLBulk\Interfaces\DeferredResolverInterface;
7
8
trait DeferredResolverTrait
9
{
10
    private static $buffer = [
11
        'roots'   => [],
12
        'results' => [],
13
    ];
14
15
    protected function deferredResolver(DeferredResolverInterface $resolver):\Closure
16
    {
17 2
        return function ($root, array $args = [], $context = null, $info = null) use ($resolver):Deferred {
18 2
            self::$buffer['roots'][] = $root;
19
20 2
            $buffer = &self::$buffer;
21
22 2
            return new Deferred(function () use (&$buffer, $resolver, $root, $args, $context, $info) {
23 2
                if (empty($buffer['results'])) {
24 2
                    $buffer['results'] = $resolver->fetch($buffer['roots'], $args, $context, $info);
0 ignored issues
show
Unused Code introduced by
The call to DeferredResolverInterface::fetch() has too many arguments starting with $args.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
                }
26
27 2
                return $resolver->pluck($root, $buffer['results']);
28 2
            });
29 2
        };
30
    }
31
}