Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| SynchronizeResult | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
| addCreatedLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addPreservedLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| addRemovedBrokenLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| markFailed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCreatedLinks | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPreservedLinks | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRemovedBrokenLinks | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| failed | |
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\Sync; |
| 21 | |
| 22 | /** |
| 23 | * Result object for packaged directory synchronization operations. |
| 24 | * |
| 25 | * This value object tracks the outcome of a synchronization run by recording |
| 26 | * which links were created, which existing links or directories were |
| 27 | * preserved, and which broken links were removed before recreation. It also |
| 28 | * carries a failure flag so callers can distinguish successful runs from |
| 29 | * aborted or invalid synchronization attempts. |
| 30 | */ |
| 31 | class SynchronizeResult |
| 32 | { |
| 33 | /** |
| 34 | * Stores the entry names for symlinks created during synchronization. |
| 35 | * |
| 36 | * @var list<string> |
| 37 | */ |
| 38 | private array $createdLinks = []; |
| 39 | |
| 40 | /** |
| 41 | * Stores the entry names that were already valid and therefore preserved. |
| 42 | * |
| 43 | * @var list<string> |
| 44 | */ |
| 45 | private array $preservedLinks = []; |
| 46 | |
| 47 | /** |
| 48 | * Stores the entry names for broken links removed during repair. |
| 49 | * |
| 50 | * @var list<string> |
| 51 | */ |
| 52 | private array $removedBrokenLinks = []; |
| 53 | |
| 54 | /** |
| 55 | * Indicates whether the synchronization process encountered a fatal failure. |
| 56 | */ |
| 57 | private bool $failed = false; |
| 58 | |
| 59 | /** |
| 60 | * Records the name of a link that was newly created. |
| 61 | * |
| 62 | * @param string $link Entry name identifying the created link |
| 63 | * |
| 64 | * @return void |
| 65 | */ |
| 66 | public function addCreatedLink(string $link): void |
| 67 | { |
| 68 | $this->createdLinks[] = $link; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Records the name of an entry that was preserved as-is. |
| 73 | * |
| 74 | * @param string $link Entry name identifying the preserved link or directory |
| 75 | * |
| 76 | * @return void |
| 77 | */ |
| 78 | public function addPreservedLink(string $link): void |
| 79 | { |
| 80 | $this->preservedLinks[] = $link; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Records the name of a broken link that was removed before recreation. |
| 85 | * |
| 86 | * @param string $link Entry name identifying the repaired broken link |
| 87 | * |
| 88 | * @return void |
| 89 | */ |
| 90 | public function addRemovedBrokenLink(string $link): void |
| 91 | { |
| 92 | $this->removedBrokenLinks[] = $link; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Marks the synchronization as failed. |
| 97 | * |
| 98 | * Callers SHOULD use this when a precondition or runtime error prevents |
| 99 | * the synchronization result from being considered successful. |
| 100 | * |
| 101 | * @return void |
| 102 | */ |
| 103 | public function markFailed(): void |
| 104 | { |
| 105 | $this->failed = true; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the names of links created during synchronization. |
| 110 | * |
| 111 | * @return list<string> |
| 112 | */ |
| 113 | public function getCreatedLinks(): array |
| 114 | { |
| 115 | return $this->createdLinks; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Returns the names of links or directories preserved during synchronization. |
| 120 | * |
| 121 | * @return list<string> |
| 122 | */ |
| 123 | public function getPreservedLinks(): array |
| 124 | { |
| 125 | return $this->preservedLinks; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns the names of broken links removed during synchronization repair. |
| 130 | * |
| 131 | * @return list<string> |
| 132 | */ |
| 133 | public function getRemovedBrokenLinks(): array |
| 134 | { |
| 135 | return $this->removedBrokenLinks; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Indicates whether the synchronization result represents a failed run. |
| 140 | * |
| 141 | * @return bool |
| 142 | */ |
| 143 | public function failed(): bool |
| 144 | { |
| 145 | return $this->failed; |
| 146 | } |
| 147 | } |