IssueFetcher::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator;
6
7
use function count;
8
9
class IssueFetcher
10
{
11
    private IssueClient $issueClient;
12
13 1
    public function __construct(IssueClient $issueClient)
14
    {
15 1
        $this->issueClient = $issueClient;
16 1
    }
17
18
    /**
19
     * @return mixed[]
20
     */
21 1
    public function fetchMilestoneIssues(ChangelogConfig $changelogConfig): array
22
    {
23 1
        $labels = $changelogConfig->getLabels();
24 1
        $labels = count($labels) === 0 ? [''] : $labels;
25
26 1
        $issues = [];
27
28 1
        foreach ($labels as $label) {
29 1
            $url = $changelogConfig->getMilestoneIssuesUrl($label);
30
31 1
            while (true) {
32 1
                $response = $this->issueClient->execute($url, $changelogConfig->getGitHubCredentials());
33
34 1
                $body = $response->getBody();
35
36 1
                foreach ($body['items'] as $item) {
37 1
                    $issues[] = $item;
38
                }
39
40 1
                $nextUrl = $response->getNextUrl();
41
42 1
                if ($nextUrl !== null) {
43 1
                    $url = $nextUrl;
44
45 1
                    continue;
46
                }
47
48 1
                break;
49
            }
50
        }
51
52 1
        return $issues;
53
    }
54
}
55