Completed
Pull Request — master (#4)
by Billie
02:41
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
/**
8
 * A GitHub Commit Message
9
 *
10
 * @package PurpleBooth\GitGitHubLint
11
 */
12
class GitHubMessageImplementation extends MessageImplementation implements GitHubMessage
13
{
14
    /**
15
     * @var string
16
     */
17
    private $sha;
18
19
    /**
20
     * GitHubMessageImplementation constructor.
21
     *
22
     * @param string $message
23
     * @param string $sha
24
     */
25
    public function __construct(string $message, string $sha)
26
    {
27
        parent::__construct($message);
28
        $this->sha = $sha;
29
    }
30
31
    /**
32
     * Get the highest weight status associated with this message
33
     *
34
     * @return Status
35
     */
36
    public function getHighestWeightStatus() : Status
37
    {
38
        $statuses = $this->getStatuses();
39
40
        usort(
41
            $statuses,
42
            function (Status $statusA, Status $statusB) {
43
                return $statusA->getWeight() <=> $statusB->getWeight();
44
            }
45
        );
46
47
        return array_pop($statuses);
48
    }
49
50
    /**
51
     * Get the SHA for this commit
52
     *
53
     * @return string
54
     */
55
    public function getSha() : string
56
    {
57
        return $this->sha;
58
    }
59
}
60