Completed
Push — master ( 383c64...d37ce4 )
by brian
03:46
created

ParseSimpleRange   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
cbo 5
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseSimpleVersionRange() 0 22 2
1
<?php
2
3
/**
4
 * @copyright   (c) 2014-2017 brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ptlis\SemanticVersion\Parse\RangeParser;
13
14
use ptlis\SemanticVersion\Comparator\ComparatorInterface;
15
use ptlis\SemanticVersion\Parse\Token;
16
use ptlis\SemanticVersion\Parse\VersionParser;
17
use ptlis\SemanticVersion\Version\Version;
18
use ptlis\SemanticVersion\VersionRange\ComparatorVersion;
19
use ptlis\SemanticVersion\VersionRange\LogicalAnd;
20
21
/**
22
 * Trait implementing method to parse a simple range (branch, tilde and wildcard) after a normalisation step.
23
 */
24
trait ParseSimpleRange
25
{
26
    /**
27
     * Parse a simple version range
28
     *
29
     * @param VersionParser $versionParser
30
     * @param ComparatorInterface $greaterOrEqualTo
31
     * @param ComparatorInterface $lessThan
32
     * @param Token[] $lowerVersionTokenList
33
     *
34
     * @return LogicalAnd
35
     */
36 4
    protected function parseSimpleVersionRange(
37
        VersionParser $versionParser,
38
        ComparatorInterface $greaterOrEqualTo,
39
        ComparatorInterface $lessThan,
40
        array $lowerVersionTokenList
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $lowerVersionTokenList exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
41
    ) {
42 4
        $lowerVersion = $versionParser->parse($lowerVersionTokenList);
43
44
        // Upto minor version
45 4
        if (count($lowerVersionTokenList) > 3) {
46 3
            $upperVersion = new Version($lowerVersion->getMajor(), $lowerVersion->getMinor() + 1);
47
48
        // Upto patch version
49
        } else {
50 1
            $upperVersion = new Version($lowerVersion->getMajor() + 1);
51
        }
52
53 4
        return new LogicalAnd(
54 4
            new ComparatorVersion($greaterOrEqualTo, $lowerVersion),
55 4
            new ComparatorVersion($lessThan, $upperVersion)
56
        );
57
    }
58
}
59