Completed
Push — master ( 899eaf...7feae9 )
by Dave
29s queued 14s
created

Severity::isValueValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common;
6
7
use Webmozart\Assert\Assert;
8
9
class Severity
10
{
11
    public const WARNING = 'warning';
12
    public const ERROR = 'error';
13
14
    /**
15
     * @var string
16
     */
17
    private $severity;
18
19
    public static function fromStringOrNull(?string $severity): self
20
    {
21
        if (null === $severity) {
22
            return new self(self::ERROR);
23
        }
24
25
        return new self($severity);
26
    }
27
28
    public static function error(): self
29
    {
30
        return new self(self::ERROR);
31
    }
32
33
    public static function warning(): self
34
    {
35
        return new self(self::WARNING);
36
    }
37
38
    private function __construct(string $severity)
39
    {
40
        Assert::true(self::isValueValid($severity), "Invalid severity: $severity");
41
        $this->severity = $severity;
42
    }
43
44
    public function getSeverity(): string
45
    {
46
        return $this->severity;
47
    }
48
49
    public static function isValueValid(string $severity): bool
50
    {
51
        return in_array($severity, [self::ERROR, self::WARNING], true);
52
    }
53
54
    public function isWarning(): bool
55
    {
56
        return self::WARNING === $this->severity;
57
    }
58
}
59