Completed
Push — master ( b2a65d...63a169 )
by Kirill
02:18
created

CallbackInterceptor::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 8
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\Interceptor;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Railt\SDL\Frontend\Context\ContextInterface;
14
use Railt\SDL\Frontend\Deferred\Deferred;
15
use Railt\SDL\Frontend\Deferred\DeferredInterface;
16
use Railt\SDL\Frontend\Deferred\DeferredCollection;
17
18
/**
19
 * Class CallbackInterceptor
20
 */
21 View Code Duplication
class CallbackInterceptor implements InterceptorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    /**
24
     * @var DeferredCollection
25
     */
26
    private $storage;
27
28
    /**
29
     * DeferredInterceptor constructor.
30
     * @param DeferredCollection $storage
31
     */
32
    public function __construct(DeferredCollection $storage)
33
    {
34
        $this->storage = $storage;
35
    }
36
37
    /**
38
     * @param RuleInterface $value
39
     * @return bool
40
     */
41
    public function match($value): bool
42
    {
43
        return $value instanceof \Closure;
44
    }
45
46
    /**
47
     * @param ContextInterface $context
48
     * @param mixed $value
49
     * @return array
50
     */
51
    public function resolve(ContextInterface $context, $value): array
52
    {
53
        $deferred = new Deferred($value);
54
55
        $this->storage->add($deferred);
56
57
        return [$context, $deferred];
58
    }
59
}
60