getHighestWeightStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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