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

Interceptor::match()   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 1
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\Process;
11
12
/**
13
 * Class Interceptor
14
 */
15
class Interceptor implements InterceptorInterface
16
{
17
    /**
18
     * @var callable
19
     */
20
    private $matcher;
21
22
    /**
23
     * @var callable
24
     */
25
    private $resolver;
26
27
    /**
28
     * Interceptor constructor.
29
     * @param callable $matcher
30
     * @param callable $resolver
31
     */
32
    public function __construct(callable $matcher, callable $resolver)
33
    {
34
        $this->matcher = $matcher;
35
        $this->resolver = $resolver;
36
    }
37
38
    /**
39
     * @param mixed $value
40
     * @return bool
41
     */
42
    public function match($value): bool
43
    {
44
        return (bool)($this->matcher)($value);
45
    }
46
47
    /**
48
     * @param mixed $value
49
     * @return mixed
50
     */
51
    public function invoke($value)
52
    {
53
        return ($this->resolver)($value);
54
    }
55
56
    /**
57
     * @param $value
58
     * @return mixed
59
     */
60
    public function __invoke($value)
61
    {
62
        return $this->invoke($value);
63
    }
64
}
65