Skip to content

Commit

Permalink
rename Directory::files() to ::all()
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Oct 15, 2023
1 parent 80a3de8 commit 5bd8e41
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
- `Innmind\Filesystem\Directory` no longer extends `File`, all previous function typed against `File` are now typed `File|Directory`
- `Innmind\Filesystem\File` is now a final class instead of an interface
- `Innmind\Filesystem\Directory` is now a final class instead of an interface
- `Innmind\Filesystem\Directory::files()` has been renamed to `::all()`

### Removed

Expand Down
1 change: 0 additions & 1 deletion properties/Adapter/AllRootFilesAreAccessible.php
Expand Up @@ -32,7 +32,6 @@ public function ensureHeldBy(Assert $assert, object $adapter): object
{
$adapter
->root()
->files()
->foreach(static function($file) use ($assert, $adapter) {
$assert->true($adapter->contains($file->name()));

Expand Down
1 change: 0 additions & 1 deletion properties/Adapter/ReAddingFilesHasNoSideEffect.php
Expand Up @@ -32,7 +32,6 @@ public function ensureHeldBy(Assert $assert, object $adapter): object
{
$adapter
->root()
->files()
->foreach(static function($file) use ($assert, $adapter) {
$adapter->add($file);
$assert->true($adapter->contains($file->name()));
Expand Down
2 changes: 1 addition & 1 deletion properties/Directory/AllFilesAreAccessible.php
Expand Up @@ -32,7 +32,7 @@ public function ensureHeldBy(Assert $assert, object $directory): object
[],
static fn($all, $file) => \array_merge($all, [$file]),
),
$directory->files()->toList(),
$directory->all()->toList(),
);

return $directory;
Expand Down
10 changes: 5 additions & 5 deletions properties/Directory/FlatMapFiles.php
Expand Up @@ -42,7 +42,7 @@ public static function any(): Set

public function applicableTo(object $directory): bool
{
return !$directory->files()->empty();
return !$directory->all()->empty();
}

public function ensureHeldBy(Assert $assert, object $directory): object
Expand All @@ -62,14 +62,14 @@ public function ensureHeldBy(Assert $assert, object $directory): object
->same($directory2);
$assert->same($directory->name()->toString(), $directory2->name()->toString());
$assert
->expected($directory->files())
->expected($directory->all())
->not()
->same($directory2->files());
$assert->same($directory->files()->size() * 2, $directory2->files()->size());
->same($directory2->all());
$assert->same($directory->all()->size() * 2, $directory2->all()->size());
$assert->same(
[$this->file1->content(), $this->file2->content()],
$directory2
->files()
->all()
->map(static fn($file) => $file->content())
->distinct()
->toList(),
Expand Down
10 changes: 5 additions & 5 deletions properties/Directory/MapFiles.php
Expand Up @@ -33,7 +33,7 @@ public static function any(): Set

public function applicableTo(object $directory): bool
{
return !$directory->files()->empty();
return !$directory->all()->empty();
}

public function ensureHeldBy(Assert $assert, object $directory): object
Expand All @@ -46,14 +46,14 @@ public function ensureHeldBy(Assert $assert, object $directory): object
->same($directory2);
$assert->same($directory->name()->toString(), $directory2->name()->toString());
$assert
->expected($directory->files())
->expected($directory->all())
->not()
->same($directory2->files());
$assert->same($directory->files()->size(), $directory2->files()->size());
->same($directory2->all());
$assert->same($directory->all()->size(), $directory2->all()->size());
$assert->same(
[$this->file->content()],
$directory2
->files()
->all()
->map(static fn($file) => $file->content())
->distinct()
->toList(),
Expand Down
4 changes: 2 additions & 2 deletions properties/Directory/Rename.php
Expand Up @@ -50,8 +50,8 @@ public function ensureHeldBy(Assert $assert, object $directory): object
->same($directory->name());
$assert->same($this->name, $directory2->name());
$assert->same(
$directory->files(),
$directory2->files(),
$directory->all(),
$directory2->all(),
);
$assert->same(
$directory->removed(),
Expand Down
4 changes: 2 additions & 2 deletions properties/Directory/ThrowWhenFlatMappingToSameFileTwice.php
Expand Up @@ -42,7 +42,7 @@ public static function any(): Set

public function applicableTo(object $directory): bool
{
return $directory->files()->size() >= 2;
return $directory->all()->size() >= 2;
}

public function ensureHeldBy(Assert $assert, object $directory): object
Expand All @@ -64,7 +64,7 @@ public function ensureHeldBy(Assert $assert, object $directory): object
),
),
))
->files()
->all()
->toList();

$assert->fail('It should throw');
Expand Down
8 changes: 4 additions & 4 deletions properties/Directory/ThrowWhenMappingToSameFileTwice.php
Expand Up @@ -34,20 +34,20 @@ public static function any(): Set

public function applicableTo(object $directory): bool
{
return $directory->files()->size() >= 2;
return $directory->all()->size() >= 2;
}

public function ensureHeldBy(Assert $assert, object $directory): object
{
try {
// calling toList in case it uses a lazy Set of files, so we need to
// unwrap the list to trigger the safeguard
// calling toList in case it uses a lazy Sequence of files, so we
// need to unwrap the list to trigger the safeguard
$directory
->map(fn() => File::of(
$this->file->name(),
$this->file->content(),
))
->files()
->all()
->toList();

$assert->fail('It should throw');
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Filesystem.php
Expand Up @@ -136,7 +136,7 @@ private function createFileAt(Path $path, File|Directory $file): void
if ($file instanceof Directory) {
$this->filesystem->mkdir($path->toString());
$persisted = $file
->files()
->all()
->map(function($file) use ($path) {
$this->createFileAt($path, $file);

Expand Down
4 changes: 2 additions & 2 deletions src/Directory.php
Expand Up @@ -177,7 +177,7 @@ public function map(callable $map): self
public function flatMap(callable $map): self
{
/** @var callable(File|self): Sequence<File|self> */
$map = static fn(File|self $file): Sequence => $map($file)->files();
$map = static fn(File|self $file): Sequence => $map($file)->all();

return new self(
$this->name,
Expand Down Expand Up @@ -213,7 +213,7 @@ public function removed(): Set
/**
* @return Sequence<File|self>
*/
public function files(): Sequence
public function all(): Sequence
{
return $this->files;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Adapter/FilesystemTest.php
Expand Up @@ -220,7 +220,7 @@ public function testRoot()
\mkdir('/tmp/test/baz');
\file_put_contents('/tmp/test/baz/foobar', 'baz');

$all = $adapter->root()->files();
$all = $adapter->root()->all();
$this->assertCount(3, $all);
$all = Map::of(
...$all
Expand Down Expand Up @@ -427,7 +427,7 @@ public function testThrowsWhenListContainsALink()
$this->expectException(LinksAreNotSupported::class);
$this->expectExceptionMessage($path.'bar');

$filesystem->root()->files()->toList();
$filesystem->root()->all()->toList();
}

public function testDotFilesAreListed()
Expand All @@ -442,7 +442,7 @@ public function testDotFilesAreListed()

$filesystem = Filesystem::mount(Path::of($path));

$all = $filesystem->root()->files()->toList();
$all = $filesystem->root()->all()->toList();
$this->assertCount(1, $all);
$this->assertSame($name, $all[0]->name()->toString());
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Adapter/InMemoryTest.php
Expand Up @@ -65,7 +65,7 @@ public function testRoot()
Content::ofString('bar'),
));

$all = $adapter->root()->files();
$all = $adapter->root()->all();
$this->assertSame(
[$foo, $bar],
$all->toList(),
Expand Down
2 changes: 1 addition & 1 deletion tests/Adapter/LoggerTest.php
Expand Up @@ -129,6 +129,6 @@ public function testRoot()
$all,
));

$this->assertSame([$file], $adapter->root()->files()->toList());
$this->assertSame([$file], $adapter->root()->all()->toList());
}
}

0 comments on commit 5bd8e41

Please sign in to comment.