Completed
Pull Request — master (#15)
by James
02:25
created

Change::__toString()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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