Failed Conditions
Push — master ( 41301b...74c660 )
by Jonathan
19s queued 11s
created

ChangelogConfig::showContributors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 bool */
29
    private $includeOpen;
30
31
    /** @var bool */
32
    private $showContributors = false;
33
34
    /** @var mixed[] */
35
    private $options = ['rootGitHubUrl' => self::DEFAULT_ROOT_GITHUB_URL];
36
37
    /**
38
     * @param string[] $labels
39
     * @param mixed[]  $options
40
     */
41 37
    public function __construct(
42
        string $user = '',
43
        string $repository = '',
44
        string $milestone = '',
45
        array $labels = [],
46
        bool $includeOpen = false,
47
        array $options = []
48
    ) {
49 37
        $this->user        = $user;
50 37
        $this->repository  = $repository;
51 37
        $this->milestone   = $milestone;
52 37
        $this->labels      = $labels;
53 37
        $this->includeOpen = $includeOpen;
54 37
        $this->options     = array_merge($this->options, $options);
55 37
    }
56
57 1
    public function getUser() : string
58
    {
59 1
        return $this->user;
60
    }
61
62 16
    public function setUser(string $user) : self
63
    {
64 16
        $this->user = $user;
65
66 16
        return $this;
67
    }
68
69 1
    public function getRepository() : string
70
    {
71 1
        return $this->repository;
72
    }
73
74 16
    public function setRepository(string $repository) : self
75
    {
76 16
        $this->repository = $repository;
77
78 16
        return $this;
79
    }
80
81 2
    public function getMilestone() : string
82
    {
83 2
        return $this->milestone;
84
    }
85
86 16
    public function setMilestone(string $milestone) : self
87
    {
88 16
        $this->milestone = $milestone;
89
90 16
        return $this;
91
    }
92
93
    /**
94
     * @return string[]
95
     */
96 4
    public function getLabels() : array
97
    {
98 4
        return $this->labels;
99
    }
100
101
    /**
102
     * @param string[] $labels
103
     */
104 8
    public function setLabels(array $labels) : self
105
    {
106 8
        $this->labels = $labels;
107
108 8
        return $this;
109
    }
110
111 1
    public function shouldIncludeOpen() : bool
112
    {
113 1
        return $this->includeOpen;
114
    }
115
116 5
    public function setIncludeOpen(bool $includeOpen) : self
117
    {
118 5
        $this->includeOpen = $includeOpen;
119
120 5
        return $this;
121
    }
122
123 1
    public function showContributors() : bool
124
    {
125 1
        return $this->showContributors;
126
    }
127
128 2
    public function setShowContributors(bool $showContributors) : self
129
    {
130 2
        $this->showContributors = $showContributors;
131
132 2
        return $this;
133
    }
134
135
    /**
136
     * @return mixed[]
137
     */
138 1
    public function getOptions() : array
139
    {
140 1
        return $this->options;
141
    }
142
143
    /**
144
     * @param mixed[] $options
145
     */
146 3
    public function setOptions(array $options) : self
147
    {
148 3
        $this->options = $options;
149
150 3
        return $this;
151
    }
152
153
    /**
154
     * @return mixed
155
     */
156 1
    public function getOption(string $name)
157
    {
158 1
        return $this->options[$name] ?? null;
159
    }
160
161
    /**
162
     * @param mixed $value
163
     */
164 1
    public function setOption(string $name, $value) : self
165
    {
166 1
        $this->options[$name] = $value;
167
168 1
        return $this;
169
    }
170
171 6
    public function getMilestoneIssuesUrl(string $label) : string
172
    {
173 6
        $query = urlencode(sprintf(
174 6
            'milestone:"%s" repo:%s/%s%s%s',
175 6
            str_replace('"', '\"', $this->milestone),
176 6
            $this->user,
177 6
            $this->repository,
178 6
            $this->includeOpen ? '' : ' state:closed',
179 6
            $label !== '' ? ' label:' . $label : ''
180
        ));
181
182 6
        return sprintf('%s/search/issues?q=%s', $this->getRootGitHubUrl(), $query);
183
    }
184
185 17
    public function isValid() : bool
186
    {
187 17
        return $this->user !== '' && $this->repository !== '' && $this->milestone !== '';
188
    }
189
190 6
    private function getRootGitHubUrl() : string
191
    {
192 6
        return $this->options['rootGitHubUrl'] ?? self::DEFAULT_ROOT_GITHUB_URL;
193
    }
194
}
195