Completed
Push — master ( e2d05f...edeffb )
by Vitaly
09:12
created

FixedVariableFixedCG   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 16.36 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 9
loc 55
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A compareLength() 0 21 3

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 declare(strict_types=1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 06.04.17 at 07:34
5
 */
6
namespace samsonframework\stringconditiontree\string;
7
8
/**
9
 * This class describes character group with next structure:
10
 * - fixed length character group
11
 * - variable length character group
12
 * - fixed length character group
13
 *
14
 * @author Vitaly Egorov <[email protected]>
15
 */
16
class FixedVariableFixedCG extends AbstractCharacterGroup
17
{
18
    /** string Character group matching regexp pattern matching group name */
19
    const PATTERN_GROUP = 'fixedVariableFixed';
20
21
    /** string Character group matching regexp pattern */
22
    const PATTERN = '(?<'.self::PATTERN_GROUP.'>'.FixedCG::PATTERN_REGEXP.VariableCG::PATTERN_REGEXP.FixedCG::PATTERN_REGEXP.')';
23
24
    /** @var FixedCG */
25
    protected $firstFixedCG;
26
27
    /** @var VariableCG */
28
    protected $variableCG;
29
30
    /** @var FixedCG */
31
    protected $lastFixedCG;
32
33
    /**
34
     * @inheritdoc
35
     */
36 6 View Code Duplication
    public function __construct(string $string, int $length = 0)
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...
37
    {
38 6
        parent::__construct($string, $length);
39
40
        // Parse internal character groups
41 6
        $this->firstFixedCG = FixedCG::fromString($string);
42 6
        $this->variableCG = VariableCG::fromString($string);
43 6
        $this->lastFixedCG = FixedCG::fromString($string);
44 6
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 4
    protected function compareLength(AbstractCharacterGroup $group): int
50
    {
51
        /** @var FixedVariableFixedCG $group */
52
53
        // Shorter first FCG has higher priority
54 4
        $return = $group->firstFixedCG->length <=> $this->firstFixedCG->length;
0 ignored issues
show
Bug introduced by
The property firstFixedCG does not seem to exist in samsonframework\stringco...\AbstractCharacterGroup.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
55
56
        // First FCG are equal
57 4
        if ($return === 0) {
58
            // Longer last FCG has higher priority
59 2
            $return = $this->lastFixedCG->length <=> $group->lastFixedCG->length;
0 ignored issues
show
Bug introduced by
The property lastFixedCG does not seem to exist in samsonframework\stringco...\AbstractCharacterGroup.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
61
            // Last FCG are equal
62 2
            if ($return === 0) {
63
                // Longer VCG has higher priority
64 2
                $return = $this->variableCG->length <=> $group->variableCG->length;
0 ignored issues
show
Bug introduced by
The property variableCG does not seem to exist in samsonframework\stringco...\AbstractCharacterGroup.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
65
            }
66
        }
67
68 4
        return $return;
69
    }
70
}
71