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

DeferredInterceptor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A match() 4 4 1
A resolve() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\DeferredInterface;
15
use Railt\SDL\Frontend\Deferred\DeferredCollection;
16
17
/**
18
 * Class DeferredInterceptor
19
 */
20 View Code Duplication
class DeferredInterceptor 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...
21
{
22
    /**
23
     * @var DeferredCollection
24
     */
25
    private $storage;
26
27
    /**
28
     * DeferredInterceptor constructor.
29
     * @param DeferredCollection $storage
30
     */
31
    public function __construct(DeferredCollection $storage)
32
    {
33
        $this->storage = $storage;
34
    }
35
36
    /**
37
     * @param RuleInterface $value
38
     * @return bool
39
     */
40
    public function match($value): bool
41
    {
42
        return $value instanceof DeferredInterface;
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
        $this->storage->add($value);
53
54
        return [$context, $value];
55
    }
56
}
57