GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( fba8ee...5e9ebc )
by Anton
02:06
created

Parser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 9.62 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 10
loc 104
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toBuilder() 0 6 1
B toComponents() 10 32 6
A toVersion() 0 12 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
namespace Deployer\Component\PharUpdate\Version;
4
5
use Deployer\Component\PharUpdate\Version\Exception\InvalidStringRepresentationException;
6
7
/**
8
 * Parses the string representation of a version number.
9
 *
10
 * @author Kevin Herrera <[email protected]>
11
 */
12
class Parser
13
{
14
    /**
15
     * The build metadata component.
16
     */
17
    const BUILD = 'build';
18
19
    /**
20
     * The major version number component.
21
     */
22
    const MAJOR = 'major';
23
24
    /**
25
     * The minor version number component.
26
     */
27
    const MINOR = 'minor';
28
29
    /**
30
     * The patch version number component.
31
     */
32
    const PATCH = 'patch';
33
34
    /**
35
     * The pre-release version number component.
36
     */
37
    const PRE_RELEASE = 'pre';
38
39
    /**
40
     * Returns a Version builder for the string representation.
41
     *
42
     * @param string $version The string representation.
43
     *
44
     * @return Builder A Version builder.
45
     */
46
    public static function toBuilder($version)
47
    {
48
        return Builder::create()->importComponents(
49
            self::toComponents($version)
50
        );
51
    }
52
53
    /**
54
     * Returns the components of the string representation.
55
     *
56
     * @param string $version The string representation.
57
     *
58
     * @return array The components of the version.
59
     *
60
     * @throws InvalidStringRepresentationException If the string representation
61
     *                                              is invalid.
62
     */
63
    public static function toComponents($version)
64
    {
65
        if (!Validator::isVersion($version)) {
66
            throw new InvalidStringRepresentationException($version);
67
        }
68
69 View Code Duplication
        if (false !== strpos($version, '+')) {
70
            list($version, $build) = explode('+', $version);
71
72
            $build = explode('.', $build);
73
        }
74
75 View Code Duplication
        if (false !== strpos($version, '-')) {
76
            list($version, $pre) = explode('-', $version);
77
78
            $pre = explode('.', $pre);
79
        }
80
81
        list(
82
            $major,
83
            $minor,
84
            $patch
85
        ) = explode('.', $version);
86
87
        return array(
88
            self::MAJOR => intval($major),
89
            self::MINOR => intval($minor),
90
            self::PATCH => intval($patch),
91
            self::PRE_RELEASE => isset($pre) ? $pre : array(),
92
            self::BUILD => isset($build) ? $build : array(),
93
        );
94
    }
95
96
    /**
97
     * Returns a Version instance for the string representation.
98
     *
99
     * @param string $version The string representation.
100
     *
101
     * @return Version A Version instance.
102
     */
103
    public static function toVersion($version)
104
    {
105
        $components = self::toComponents($version);
106
107
        return new Version(
108
            $components['major'],
0 ignored issues
show
Bug introduced by Anton Medvedev
It seems like $components['major'] can also be of type array; however, Deployer\Component\PharU...\Version::__construct() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
109
            $components['minor'],
0 ignored issues
show
Bug introduced by Anton Medvedev
It seems like $components['minor'] can also be of type array; however, Deployer\Component\PharU...\Version::__construct() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
110
            $components['patch'],
0 ignored issues
show
Bug introduced by Anton Medvedev
It seems like $components['patch'] can also be of type array; however, Deployer\Component\PharU...\Version::__construct() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
111
            $components['pre'],
0 ignored issues
show
Bug introduced by Anton Medvedev
It seems like $components['pre'] can also be of type integer; however, Deployer\Component\PharU...\Version::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
112
            $components['build']
0 ignored issues
show
Bug introduced by Anton Medvedev
It seems like $components['build'] can also be of type integer; however, Deployer\Component\PharU...\Version::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
113
        );
114
    }
115
}
116