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

RuleInterceptor::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
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\Builder;
14
use Railt\SDL\Frontend\Context\ContextInterface;
15
16
/**
17
 * Class RuleInterceptor
18
 */
19
class RuleInterceptor implements InterceptorInterface
20
{
21
    /**
22
     * @var \Closure
23
     */
24
    private $reducer;
25
26
    /**
27
     * RuleInterceptor constructor.
28
     * @param \Closure $reduce
29
     */
30
    public function __construct(\Closure $reduce)
31
    {
32
        $this->reducer = $reduce;
33
    }
34
35
    /**
36
     * @param RuleInterface $value
37
     * @return bool
38
     */
39
    public function match($value): bool
40
    {
41
        return $value instanceof RuleInterface;
42
    }
43
44
    /**
45
     * @param ContextInterface $context
46
     * @param mixed $value
47
     * @return array
48
     */
49
    public function resolve(ContextInterface $context, $value): array
50
    {
51
        return ($this->reducer)($context, $value);
52
    }
53
}
54