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