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

GitHubMessageImplementation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHighestWeightStatus() 0 13 1
A getSha() 0 4 1
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