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

VariableFixedCG   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 10
loc 57
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A isFixed() 0 4 1
A compareLength() 0 17 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 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
 * - variable length character group
11
 * - fixed length character group
12
 *
13
 * @author Vitaly Egorov <[email protected]>
14
 */
15
class VariableFixedCG extends AbstractCharacterGroup
16
{
17
    /** string Character group matching regexp pattern matching group name */
18
    const PATTERN_GROUP = 'variableFixed';
19
20
    /** string Character group matching regexp pattern */
21
    const PATTERN = '(?<'.self::PATTERN_GROUP.'>'.VariableCG::PATTERN_REGEXP.FixedCG::PATTERN_REGEXP.')';
22
23
    /** @var VariableCG */
24
    protected $variableCG;
25
26
    /** @var FixedCG */
27
    protected $fixedCG;
28
29
    /**
30
     * @inheritdoc
31
     */
32 8 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...
33
    {
34 8
        $this->size = 2;
35
36 8
        parent::__construct($string, $length);
37
38
        // Parse internal character groups
39 8
        $this->variableCG = VariableCG::fromString($string);
40 8
        $this->fixedCG = FixedCG::fromString($string);
41 8
    }
42
43
    /**
44
     * @return bool True if character group is fixed length otherwise false
45
     */
46 4
    public function isFixed(): bool
47
    {
48 4
        return $this instanceof self;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 7
    protected function compareLength(AbstractCharacterGroup $group): int
55
    {
56
        /** @var VariableFixedCG $group */
57
58
        // Shorter FCG has higher priority
59 7
        $return = $this->fixedCG->length <=> $group->fixedCG->length;
0 ignored issues
show
Bug introduced by
The property fixedCG 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
        // Fixed CG are equal
62
//        if ($return === 0) {
63
//            // Longer first VCG has higher priority
64
//            $return = $this->variableCG->length <=> $group->variableCG->length;
65
//        }
66
        // TODO: Check for filtering pattern and VCG with filter has priority
67
        // TODO: But how to compare filters if present?
68
69 7
        return $return;
70
    }
71
}
72