Lines
100.00%
5 / 5
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| FileChangeCollection | 100.00% | 5 / 5 | 100.00% | 5 / 5 | 5 | 100.00% | 1 / 1 | |||
| fromChangesSortedByPath | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| filterStale | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| countWithOutcome | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| countExistingFiles | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| isClean | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Codegen\Output\Collection; | |
| 6 | ||
| 7 | use Stewart\Codegen\Output\FileChange; | |
| 8 | use Stewart\Codegen\Output\FileOutcome; | |
| 9 | use Stewart\Contracts\Collection\ListCollection; | |
| 10 | ||
| 11 | /** @extends ListCollection<FileChange> */ | |
| 12 | final readonly class FileChangeCollection extends ListCollection | |
| 13 | { | |
| 14 | /** @param iterable<FileChange> $changes */ | |
| 15 | public static function fromChangesSortedByPath(iterable $changes): self | |
| 16 | { | |
| 17 | return self::fromList($changes)->sortedBy(static fn(FileChange $a, FileChange $b): int => strcmp($a->path, $b->path)); | |
| 18 | } | |
| 19 | ||
| 20 | public function filterStale(): self | |
| 21 | { | |
| 22 | return $this->filter(static fn(FileChange $change): bool => $change->outcome->isChange()); | |
| 23 | } | |
| 24 | ||
| 25 | public function countWithOutcome(FileOutcome $outcome): int | |
| 26 | { | |
| 27 | return $this->filter(static fn(FileChange $change): bool => $change->outcome === $outcome)->count(); | |
| 28 | } | |
| 29 | ||
| 30 | public function countExistingFiles(): int | |
| 31 | { | |
| 32 | return $this->filter(static fn(FileChange $change): bool => $change->outcome !== FileOutcome::Created)->count(); | |
| 33 | } | |
| 34 | ||
| 35 | public function isClean(): bool | |
| 36 | { | |
| 37 | return !$this->containsWhere(static fn(FileChange $change): bool => $change->outcome->isChange()); | |
| 38 | } | |
| 39 | } |