Change   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A changed() 0 3 1
A isSkipped() 0 3 1
A added() 0 3 1
A skippedDueToFailure() 0 4 1
A isAdded() 0 3 1
A removed() 0 3 1
A isRemoved() 0 3 1
A isChanged() 0 3 1
A __construct() 0 5 1
A __toString() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility;
6
7
use Throwable;
8
use function Safe\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
    private const SKIPPED = 'skipped';
20
21
    /** @var string */
22
    private $modificationType;
23
24
    /** @var string */
25
    private $description;
26
27
    /** @var bool */
28
    private $isBcBreak;
29
30
    private function __construct(string $modificationType, string $description, bool $isBcBreak)
31
    {
32
        $this->modificationType = $modificationType;
33
        $this->description      = $description;
34
        $this->isBcBreak        = $isBcBreak;
35
    }
36
37
    public static function added(string $description, bool $isBcBreak) : self
38
    {
39
        return new self(self::ADDED, $description, $isBcBreak);
40
    }
41
42
    public static function changed(string $description, bool $isBcBreak) : self
43
    {
44
        return new self(self::CHANGED, $description, $isBcBreak);
45
    }
46
47
    public static function removed(string $description, bool $isBcBreak) : self
48
    {
49
        return new self(self::REMOVED, $description, $isBcBreak);
50
    }
51
52
    public static function skippedDueToFailure(Throwable $failure) : self
53
    {
54
        // @TODO Note: we may consider importing the full exception for better printing later on
55
        return new self(self::SKIPPED, $failure->getMessage(), true);
56
    }
57
58
    public function isAdded() : bool
59
    {
60
        return $this->modificationType === self::ADDED;
61
    }
62
63
    public function isRemoved() : bool
64
    {
65
        return $this->modificationType === self::REMOVED;
66
    }
67
68
    public function isChanged() : bool
69
    {
70
        return $this->modificationType === self::CHANGED;
71
    }
72
73
    public function isSkipped() : bool
74
    {
75
        return $this->modificationType === self::SKIPPED;
76
    }
77
78
    public function __toString() : string
79
    {
80
        return sprintf(
81
            '%s%s: %s',
82
            $this->isBcBreak ? '[BC] ' : '     ',
83
            strtoupper($this->modificationType),
84
            $this->description
85
        );
86
    }
87
}
88