Passed
Pull Request — master (#35)
by James
02:02
created

Change::isRemoved()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Roave\ApiCompare;
5
6
use Assert\Assert;
7
8
/**
9
 * @todo this class probably needs subclassing or being turned into an interface
10
 */
11
final class Change
12
{
13
    private const ADDED = 'added';
14
    private const CHANGED = 'changed';
15
    private const REMOVED = 'removed';
16
17
    /**
18
     * @var string[]
19
     */
20
    private static $validModificationTypes = [self::ADDED, self::CHANGED, self::REMOVED];
21
22
    /**
23
     * @var string
24
     */
25
    private $modificationType;
26
27
    /**
28
     * @var string
29
     */
30
    private $description;
31
32
    /**
33
     * @var bool
34
     */
35
    private $isBcBreak;
36
37
    private function __construct(string $modificationType, string $description, bool $isBcBreak)
38
    {
39
        Assert::that($modificationType)->inArray(self::$validModificationTypes);
40
        $this->modificationType = $modificationType;
41
        $this->description = $description;
42
        $this->isBcBreak = $isBcBreak;
43
    }
44
45
    public static function added(string $description, bool $isBcBreak): self
46
    {
47
        return new self(self::ADDED, $description, $isBcBreak);
48
    }
49
50
    public static function changed(string $description, bool $isBcBreak): self
51
    {
52
        return new self(self::CHANGED, $description, $isBcBreak);
53
    }
54
55
    public static function removed(string $description, bool $isBcBreak): self
56
    {
57
        return new self(self::REMOVED, $description, $isBcBreak);
58
    }
59
60
    public function isAdded() : bool
61
    {
62
        return $this->modificationType === self::ADDED;
63
    }
64
65
    public function isRemoved() : bool
66
    {
67
        return $this->modificationType === self::REMOVED;
68
    }
69
70
    public function isChanged() : bool
71
    {
72
        return $this->modificationType === self::CHANGED;
73
    }
74
75
    public function __toString(): string
76
    {
77
        return sprintf(
78
            '%s%s: %s',
79
            $this->isBcBreak ? '[BC] ' : '     ',
80
            strtoupper($this->modificationType),
81
            $this->description
82
        );
83
    }
84
}
85