Repetition   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 18.42 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 7
loc 38
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 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 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\Compiler\Grammar\Builder;
11
12
use Railt\Parser\Rule\Repetition as RepetitionRule;
13
use Railt\Parser\Rule\Rule;
14
15
/**
16
 * Class Repetition
17
 */
18
class Repetition extends AbstractBuilder
19
{
20
    /**
21
     * @var int
22
     */
23
    private $min;
24
25
    /**
26
     * @var int
27
     */
28
    private $max;
29
30
    /**
31
     * Repetition constructor.
32
     * @param $name
33
     * @param int $min
34
     * @param int $max
35
     * @param $children
36
     * @param string|null $nodeId
37
     */
38
    public function __construct($name, int $min, int $max, $children, string $nodeId = null)
39
    {
40
        $this->min = $min;
41
        $this->max = $max;
42
        parent::__construct($name, $children, $nodeId);
43
    }
44
45
    /**
46
     * @return Rule|RepetitionRule
47
     */
48 View Code Duplication
    public function build(): Rule
0 ignored issues
show
Duplication introduced by
This method 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...
49
    {
50
        $rule = new RepetitionRule($this->name, $this->min, $this->max, $this->children, $this->nodeId);
51
        $rule->setDefaultId($this->defaultId);
52
53
        return $rule;
54
    }
55
}
56