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.

Parser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 101
rs 10
ccs 0
cts 43
cp 0
wmc 6

3 Methods

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

110
            /** @scrutinizer ignore-type */ $components['major'],
Loading history...
111
            $components['minor'],
0 ignored issues
show
Bug introduced by
It seems like $components['minor'] can also be of type array; however, parameter $minor of Deployer\Component\PharU...\Version::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
            /** @scrutinizer ignore-type */ $components['minor'],
Loading history...
112
            $components['patch'],
0 ignored issues
show
Bug introduced by
It seems like $components['patch'] can also be of type array; however, parameter $patch of Deployer\Component\PharU...\Version::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

112
            /** @scrutinizer ignore-type */ $components['patch'],
Loading history...
113
            $components['pre'],
0 ignored issues
show
Bug introduced by
It seems like $components['pre'] can also be of type integer; however, parameter $pre of Deployer\Component\PharU...\Version::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
            /** @scrutinizer ignore-type */ $components['pre'],
Loading history...
114
            $components['build'],
0 ignored issues
show
Bug introduced by
It seems like $components['build'] can also be of type integer; however, parameter $build of Deployer\Component\PharU...\Version::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
            /** @scrutinizer ignore-type */ $components['build'],
Loading history...
115
        );
116
    }
117
}
118