| Total Complexity | 6 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class IssueFetcher |
||
| 12 | { |
||
| 13 | private const ROOT_URL = 'https://api.github.com'; |
||
| 14 | |||
| 15 | /** @var IssueClient */ |
||
| 16 | private $issueClient; |
||
| 17 | |||
| 18 | 1 | public function __construct(IssueClient $issueClient) |
|
| 19 | { |
||
| 20 | 1 | $this->issueClient = $issueClient; |
|
| 21 | 1 | } |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @return Issue[] |
||
| 25 | */ |
||
| 26 | 1 | public function fetchMilestoneIssues(string $user, string $repository, string $milestone) : array |
|
| 27 | { |
||
| 28 | 1 | $url = $this->getMilestoneIssuesUrl($user, $repository, $milestone); |
|
| 29 | |||
| 30 | 1 | $issues = []; |
|
| 31 | |||
| 32 | 1 | while (true) { |
|
| 33 | 1 | $response = $this->issueClient->execute($url); |
|
| 34 | |||
| 35 | 1 | $body = $response->getBody(); |
|
| 36 | |||
| 37 | 1 | foreach ($body['items'] as $item) { |
|
| 38 | 1 | $issues[] = $item; |
|
| 39 | } |
||
| 40 | |||
| 41 | 1 | $nextUrl = $response->getNextUrl(); |
|
| 42 | |||
| 43 | 1 | if ($nextUrl !== null) { |
|
| 44 | 1 | $url = $nextUrl; |
|
| 45 | |||
| 46 | 1 | continue; |
|
| 47 | } |
||
| 48 | |||
| 49 | 1 | break; |
|
| 50 | } |
||
| 51 | |||
| 52 | 1 | return $issues; |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | private function getMilestoneIssuesUrl(string $user, string $repository, string $milestone) : string |
|
| 67 | } |
||
| 68 | } |
||
| 69 |