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

DeferredResolverTrait::deferredResolver()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 1
crap 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
}