Completed
Push — master ( b12741...03b4a1 )
by Kirill
01:38
created

ArrayReducer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 23
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 4 4 1
A reduce() 7 7 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 Properties 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 Serafim\Properties\Reducers\TypeHint;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Serafim\Properties\Attribute\ArrayTypeHint;
14
use Serafim\Properties\Attribute\Matchable;
15
use Serafim\Properties\Attribute\TypeHint;
16
use Serafim\Properties\Reducers\ReducerInterface;
17
18
/**
19
 * Class ArrayReducer
20
 */
21 View Code Duplication
class ArrayReducer implements ReducerInterface
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
     * @param RuleInterface $rule
25
     * @return bool
26
     */
27
    public function match(RuleInterface $rule): bool
28
    {
29
        return $rule->getName() === 'Array';
30
    }
31
32
    /**
33
     * @param RuleInterface $rule
34
     * @return \Generator|Matchable
35
     */
36
    public function reduce(RuleInterface $rule): \Generator
37
    {
38
        /** @var string $name */
39
        $name = yield $rule->first('Type');
40
41
        return new ArrayTypeHint($name);
42
    }
43
}
44