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