DeferredResolverTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A deferredResolver() 0 20 2
1
<?php declare(strict_types=1);
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
12
    /** @noinspection PhpUnusedPrivateMethodInspection */
13
    private function deferredResolver(DeferredResolverInterface $resolver): \Closure
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
14
    {
15 4
        return function ($root, array $args = [], $context = null, $info = null) use ($resolver): Deferred {
16 4
            $resolverName                = \get_class($resolver);
17 4
            self::$buffer[$resolverName] = self::$buffer[$resolverName] ?? [];
18
19 4
            $buffer            = &self::$buffer[$resolverName];
20 4
            $buffer['results'] = [];
21 4
            $buffer['roots'][] = $root;
22
23 4
            return new Deferred(function () use (&$buffer, $resolver, $root, $args, $context, $info) {
24 4
                if (empty($buffer['results'])) {
25 4
                    $buffer['results'] = $resolver->fetch($buffer['roots'], $args, $context, $info);
26 4
                    $buffer['roots']   = [];
27
                }
28
29 4
                return $resolver->pluck($root, $buffer['results']);
30 4
            });
31 4
        };
32
    }
33
}
34