CommitMessageServiceImplementation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PurpleBooth\GitGitHubLint;
5
6
use Github\Client;
7
8
/**
9
 * Get commit messages from GitHub and turns them into messages
10
 *
11
 * @package PurpleBooth\GitGitHubLint
12
 */
13
class CommitMessageServiceImplementation implements CommitMessageService
14
{
15
    /**
16
     * @var Client
17
     */
18
    private $client;
19
20
21
    /**
22
     * CommitMessageServiceImplementation constructor.
23
     *
24
     * @param Client $client
25
     */
26
    public function __construct(Client $client)
27
    {
28
        $this->client = $client;
29
    }
30
31
    /**
32
     * Get an array of commit messages for a specific PR
33
     *
34
     * @param string $username
35
     * @param string $repository
36
     * @param int    $pullRequestId
37
     *
38
     * @return array
39
     */
40
    public function getMessages(string $username, string $repository, int $pullRequestId) : array
41
    {
42
        /** @var \Github\Api\PullRequest $prApi */
43
        $prApi    = $this->client->api('pr');
44
        $response = $prApi->commits($username, $repository, $pullRequestId);
45
46
        $messages = [];
47
48
        foreach ($response as $commit) {
49
            $messages[] = new GitHubMessageImplementation($commit['commit']['message'], $commit['sha']);
50
        }
51
52
        return $messages;
53
    }
54
}
55