Completed
Push — master ( e3bdde...4905fa )
by Jonathan
10s
created

ChangelogConfig   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 120
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0
wmc 17

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setRepository() 0 3 1
A setOptions() 0 3 1
A getRepository() 0 3 1
A __construct() 0 12 1
A getLabels() 0 3 1
A getMilestone() 0 3 1
A getRootGitHubUrl() 0 3 1
A setUser() 0 3 1
A setMilestone() 0 3 1
A isValid() 0 3 3
A getUser() 0 3 1
A getMilestoneIssuesUrl() 0 11 2
A getOptions() 0 3 1
A setLabels() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator;
6
7
use function array_merge;
8
use function sprintf;
9
use function str_replace;
10
use function urlencode;
11
12
class ChangelogConfig
13
{
14
    private const DEFAULT_ROOT_GITHUB_URL = 'https://api.github.com';
15
16
    /** @var string */
17
    private $user;
18
19
    /** @var string */
20
    private $repository;
21
22
    /** @var string */
23
    private $milestone;
24
25
    /** @var string[] */
26
    private $labels;
27
28
    /** @var mixed[] */
29
    private $options = ['rootGitHubUrl' => self::DEFAULT_ROOT_GITHUB_URL];
30
31
    /**
32
     * @param string[] $labels
33
     * @param mixed[]  $options
34
     */
35 27
    public function __construct(
36
        string $user,
37
        string $repository,
38
        string $milestone,
39
        array $labels = [],
40
        array $options = []
41
    ) {
42 27
        $this->user       = $user;
43 27
        $this->repository = $repository;
44 27
        $this->milestone  = $milestone;
45 27
        $this->labels     = $labels;
46 27
        $this->options    = array_merge($this->options, $options);
47 27
    }
48
49 1
    public function getUser() : string
50
    {
51 1
        return $this->user;
52
    }
53
54 4
    public function setUser(string $user) : void
55
    {
56 4
        $this->user = $user;
57 4
    }
58
59 1
    public function getRepository() : string
60
    {
61 1
        return $this->repository;
62
    }
63
64 4
    public function setRepository(string $repository) : void
65
    {
66 4
        $this->repository = $repository;
67 4
    }
68
69 2
    public function getMilestone() : string
70
    {
71 2
        return $this->milestone;
72
    }
73
74 4
    public function setMilestone(string $milestone) : void
75
    {
76 4
        $this->milestone = $milestone;
77 4
    }
78
79
    /**
80
     * @return string[]
81
     */
82 2
    public function getLabels() : array
83
    {
84 2
        return $this->labels;
85
    }
86
87
    /**
88
     * @param string[] $labels
89
     */
90 3
    public function setLabels(array $labels) : void
91
    {
92 3
        $this->labels = $labels;
93 3
    }
94
95
    /**
96
     * @return mixed[]
97
     */
98 1
    public function getOptions() : array
99
    {
100 1
        return $this->options;
101
    }
102
103
    /**
104
     * @param mixed[] $options
105
     */
106 3
    public function setOptions(array $options) : void
107
    {
108 3
        $this->options = $options;
109 3
    }
110
111 5
    public function getMilestoneIssuesUrl(string $label) : string
112
    {
113 5
        $query = urlencode(sprintf(
114 5
            'milestone:"%s" repo:%s/%s state:closed%s',
115 5
            str_replace('"', '\"', $this->milestone),
116 5
            $this->user,
117 5
            $this->repository,
118 5
            $label !== '' ? ' label:' . $label : ''
119
        ));
120
121 5
        return sprintf('%s/search/issues?q=%s', $this->getRootGitHubUrl(), $query);
122
    }
123
124 12
    public function isValid() : bool
125
    {
126 12
        return $this->user !== '' && $this->repository !== '' && $this->milestone !== '';
127
    }
128
129 5
    private function getRootGitHubUrl() : string
130
    {
131 5
        return $this->options['rootGitHubUrl'] ?? self::DEFAULT_ROOT_GITHUB_URL;
132
    }
133
}
134