Cancelled
Push — master ( a8b464...2fc3a5 )
by Billie
06:55
created

StatusSendServiceImplementation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
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\Api\Repo;
7
use Github\Client;
8
use PurpleBooth\GitGitHubLint\Status\Status;
9
10
/**
11
 * Sets statuses on a SHA on GitHub
12
 *
13
 * @package PurpleBooth\GitGitHubLint
14
 */
15
class StatusSendServiceImplementation implements StatusSendService
16
{
17
    const CONTEXT = 'git-git-hub-lint';
18
    /**
19
     * @var Client
20
     */
21
    private $client;
22
23
    /**
24
     * StatusSendServiceImplementation constructor.
25
     *
26
     * @param Client $client
27
     */
28
    public function __construct(Client $client)
29
    {
30
        $this->client = $client;
31
    }
32
33
    /**
34
     * Set a SHA in GitHub to a state
35
     *
36
     * @param string $organisation
37
     * @param string $repository
38
     * @param string $sha
39
     * @param Status $status
40
     */
41
    public function updateStatus(string $organisation, string $repository, string $sha, Status $status)
42
    {
43
        /** @var Repo $repoApi */
44
        $repoApi = $this->client->api('repo');
45
        $repoApi->statuses()
46
                ->create(
47
                    $organisation,
48
                    $repository,
49
                    $sha,
50
                    [
51
                        'state' => $status->getState(),
52
                        'description' => $status->getMessage(),
53
                        'context' => self::CONTEXT
54
                    ]
55
                );
56
    }
57
}
58