Completed
Pull Request — master (#4)
by Billie
03:15
created

GitHubMessageImplementation::getSha()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
namespace PurpleBooth\GitGitHubLint;
4
5
use PurpleBooth\GitGitHubLint\Status\Status;
6
7
class GitHubMessageImplementation extends MessageImplementation implements GitHubMessage
8
{
9
    /**
10
     * @var string
11
     */
12
    private $sha;
13
14
    /**
15
     * GitHubMessageImplementation constructor.
16
     *
17
     * @param string $message
18
     * @param string $sha
19
     */
20
    public function __construct(string $message, string $sha)
21
    {
22
        parent::__construct($message);
23
        $this->sha = $sha;
24
    }
25
26
    /**
27
     * Get the highest weight status associated with this message
28
     *
29
     * @return Status
30
     */
31
    public function getHighestWeightStatus() : Status
32
    {
33
        $statuses = $this->getStatuses();
34
35
        usort(
36
            $statuses,
37
            function (Status $statusA, Status $statusB) {
38
                return $statusA->getWeight() <=> $statusB->getWeight();
39
            }
40
        );
41
42
        return array_pop($statuses);
43
    }
44
45
    /**
46
     * Get the SHA for this commit
47
     *
48
     * @return string
49
     */
50
    public function getSha() : string
51
    {
52
        return $this->sha;
53
    }
54
}
55