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 ( 26c340...9e24cf )
by Anton
02:30
created

Changelog   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
dl 0
loc 92
ccs 18
cts 39
cp 0.4615
rs 10
c 0
b 0
f 0
wmc 12
lcom 2
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A prependVersion() 0 4 1
A findMaster() 0 15 3
A findLatest() 0 10 3
A addReferences() 0 4 1
A __toString() 0 19 1
A setTitle() 0 4 1
A addVersion() 0 4 1
A setReferences() 0 4 1
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Support\Changelog;
9
10
class Changelog
11
{
12
    /**
13
     * @var string
14
     */
15
    private $title;
16
17
    /**
18
     * @var Version[]
19
     */
20
    private $versions = [];
21
22
    /**
23
     * @var array
24
     */
25
    private $references = [];
26
27 1
    public function __toString()
28
    {
29 1
        $versions = join("\n", $this->versions);
30
31 1
        krsort($this->references, SORT_NUMERIC);
32
33 1
        $references = join("\n", array_map(function ($link, $ref) {
34 1
            return "[#$ref]: $link";
35 1
        }, $this->references, array_keys($this->references)));
36
37
        return <<<MD
38 1
# {$this->title}
39
40
41 1
{$versions}
42 1
{$references}
43
44
MD;
45
    }
46
47 2
    public function setTitle(string $title)
48
    {
49 2
        $this->title = $title;
50 2
    }
51
52 2
    public function addVersion(Version $version)
53
    {
54 2
        $this->versions[] = $version;
55 2
    }
56
57
    public function prependVersion(Version $version)
58
    {
59
        array_unshift($this->versions, $version);
60
    }
61
62
    public function findMaster(): Version
63
    {
64
        foreach ($this->versions as $version) {
65
            if ($version->getVersion() === 'master') {
66
                return $version;
67
            }
68
        }
69
70
        $version = new Version();
71
        $version->setVersion('master');
72
        $version->setPrevious($this->findLatest()->getVersion());
73
        $this->prependVersion($version);
74
75
        return $version;
76
    }
77
78
    public function findLatest(): Version
79
    {
80
        foreach ($this->versions as $version) {
81
            if ($version->getVersion() === 'master') {
82
                continue;
83
            }
84
            return $version;
85
        }
86
        throw new \RuntimeException('There no versions.');
87
    }
88
89
    /**
90
     * @param array $references
91
     */
92 2
    public function setReferences(array $references)
93
    {
94 2
        $this->references = $references;
95 2
    }
96
97
    public function addReferences(int $ref, string $url)
98
    {
99
        $this->references[$ref] = $url;
100
    }
101
}
102