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

DefinitionInterceptor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 4 1
A resolve() 0 8 1
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\SDL\Frontend\Context\ContextInterface;
13
use Railt\SDL\Frontend\Deferred\Deferred;
14
use Railt\SDL\Frontend\Definition\DefinitionInterface;
15
use Railt\SDL\Frontend\Definition\Storage;
16
17
/**
18
 * Class DefinitionInterceptor
19
 */
20
class DefinitionInterceptor implements InterceptorInterface
21
{
22
    /**
23
     * @var Storage
24
     */
25
    private $definitions;
26
27
    /**
28
     * DefinitionInterceptor constructor.
29
     * @param Storage $definitions
30
     */
31
    public function __construct(Storage $definitions)
32
    {
33
        $this->definitions = $definitions;
34
    }
35
36
    /**
37
     * @param mixed $value
38
     * @return bool
39
     */
40
    public function match($value): bool
41
    {
42
        return $value instanceof DefinitionInterface;
43
    }
44
45
    /**
46
     * @param ContextInterface $context
47
     * @param mixed $value
48
     * @return array
49
     */
50
    public function resolve(ContextInterface $context, $value): array
51
    {
52
        $deferred = new Deferred();
53
54
        $this->definitions->remember($value, $deferred);
55
56
        return [$context, $deferred];
57
    }
58
}
59