Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| FileDiff | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSummary | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDiff | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isUnchanged | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isChanged | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Resource; |
| 21 | |
| 22 | /** |
| 23 | * Carries the result of comparing source and target file contents. |
| 24 | */ |
| 25 | class FileDiff |
| 26 | { |
| 27 | /** |
| 28 | * @var string indicates that the source and target differ and a text diff is available |
| 29 | */ |
| 30 | public const string STATUS_CHANGED = 'changed'; |
| 31 | |
| 32 | /** |
| 33 | * @var string indicates that the source and target already match |
| 34 | */ |
| 35 | public const string STATUS_UNCHANGED = 'unchanged'; |
| 36 | |
| 37 | /** |
| 38 | * @var string indicates that a text diff should not be rendered for the compared files |
| 39 | */ |
| 40 | public const string STATUS_BINARY = 'binary'; |
| 41 | |
| 42 | /** |
| 43 | * @var string indicates that the compared files could not be read safely |
| 44 | */ |
| 45 | public const string STATUS_UNREADABLE = 'unreadable'; |
| 46 | |
| 47 | /** |
| 48 | * Creates a new file diff result. |
| 49 | * |
| 50 | * @param string $status the comparison status for the source and target files |
| 51 | * @param string $summary the human-readable summary for console output |
| 52 | * @param string|null $diff the optional unified diff payload |
| 53 | */ |
| 54 | public function __construct( |
| 55 | private string $status, |
| 56 | private string $summary, |
| 57 | private ?string $diff = null, |
| 58 | ) {} |
| 59 | |
| 60 | /** |
| 61 | * Returns the comparison status. |
| 62 | * |
| 63 | * @return string the comparison status value |
| 64 | */ |
| 65 | public function getStatus(): string |
| 66 | { |
| 67 | return $this->status; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the human-readable summary. |
| 72 | * |
| 73 | * @return string the summary for console output |
| 74 | */ |
| 75 | public function getSummary(): string |
| 76 | { |
| 77 | return $this->summary; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the optional unified diff payload. |
| 82 | * |
| 83 | * @return string|null the diff payload, or null when no text diff is available |
| 84 | */ |
| 85 | public function getDiff(): ?string |
| 86 | { |
| 87 | return $this->diff; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Reports whether the compared files already match. |
| 92 | * |
| 93 | * @return bool true when the source and target contents are identical |
| 94 | */ |
| 95 | public function isUnchanged(): bool |
| 96 | { |
| 97 | return self::STATUS_UNCHANGED === $this->status; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Reports whether the compared files produced a text diff. |
| 102 | * |
| 103 | * @return bool true when a text diff is available |
| 104 | */ |
| 105 | public function isChanged(): bool |
| 106 | { |
| 107 | return self::STATUS_CHANGED === $this->status; |
| 108 | } |
| 109 | } |