Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proofs/file/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static function($assert) use ($io) {
));

$count = 0;
$content->foreach(static function() use (&$count) {
$_ = $content->foreach(static function() use (&$count) {
$count++;
});

Expand Down
2 changes: 1 addition & 1 deletion properties/Adapter/AddDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function assertSame(
}

if ($target instanceof Directory) {
$target->foreach(function($file) use ($assert, $source) {
$_ = $target->foreach(function($file) use ($assert, $source) {
$assert->true($source->contains($file->name()));

$this->assertSame(
Expand Down
2 changes: 1 addition & 1 deletion properties/Content/ForeachExposeAllLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function applicableTo(object $systemUnderTest): bool
public function ensureHeldBy(Assert $assert, object $systemUnderTest): object
{
$count = 0;
$systemUnderTest->foreach(static function($line) use ($assert, &$count) {
$_ = $systemUnderTest->foreach(static function($line) use ($assert, &$count) {
$assert->object($line)->instance(Line::class);
$count++;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function applicableTo(object $directory): bool

public function ensureHeldBy(Assert $assert, object $directory): object
{
$directory->foreach(static function($file) use ($assert, $directory) {
$_ = $directory->foreach(static function($file) use ($assert, $directory) {
$assert->same(
$file->name(),
$directory->get($file->name())->match(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function applicableTo(object $directory): bool

public function ensureHeldBy(Assert $assert, object $directory): object
{
$directory->foreach(static function($file) use ($assert, $directory) {
$_ = $directory->foreach(static function($file) use ($assert, $directory) {
$assert->true($directory->contains($file->name()));
});

Expand Down
6 changes: 3 additions & 3 deletions properties/Directory/FilteringDoesntAffectTheDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function ensureHeldBy(Assert $assert, object $directory): object
$all = $directory->filter(static fn(): bool => true);
$none = $directory->filter(static fn(): bool => false);

$directory->foreach(static fn($file) => $assert->false($none->contains($file->name())));
$directory->foreach(static fn($file) => $assert->true($all->contains($file->name())));
$all->foreach(static fn($file) => $assert->true($directory->contains($file->name())));
$_ = $directory->foreach(static fn($file) => $assert->false($none->contains($file->name())));
$_ = $directory->foreach(static fn($file) => $assert->true($all->contains($file->name())));
$_ = $all->foreach(static fn($file) => $assert->true($directory->contains($file->name())));
$assert->same($directory->removed(), $all->removed());
$assert->same($directory->removed(), $none->removed());

Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
8 changes: 8 additions & 0 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private function __construct(
/**
* @return Attempt<self>
*/
#[\NoDiscard]
public static function mount(
Path $path,
CaseSensitivity $case = CaseSensitivity::sensitive,
Expand All @@ -65,6 +66,7 @@ public static function mount(
});
}

#[\NoDiscard]
public static function inMemory(): self
{
return new self(
Expand All @@ -73,6 +75,7 @@ public static function inMemory(): self
);
}

#[\NoDiscard]
public static function logger(
self $adapter,
LoggerInterface $logger,
Expand All @@ -86,6 +89,7 @@ public static function logger(
/**
* @return Attempt<SideEffect>
*/
#[\NoDiscard]
public function add(File|Directory $file): Attempt
{
return $this->write(TreePath::root(), $file);
Expand All @@ -94,6 +98,7 @@ public function add(File|Directory $file): Attempt
/**
* @return Maybe<File|Directory>
*/
#[\NoDiscard]
public function get(Name $file): Maybe
{
return $this->access(
Expand All @@ -102,6 +107,7 @@ public function get(Name $file): Maybe
);
}

#[\NoDiscard]
public function contains(Name $file): bool
{
return $this->implementation->exists(TreePath::of($file))->match(
Expand All @@ -113,11 +119,13 @@ public function contains(Name $file): bool
/**
* @return Attempt<SideEffect>
*/
#[\NoDiscard]
public function remove(Name $file): Attempt
{
return $this->implementation->remove(TreePath::root(), $file);
}

#[\NoDiscard]
public function root(): Directory
{
$root = TreePath::root();
Expand Down
16 changes: 16 additions & 0 deletions src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private function __construct(
*
* @param Sequence<File|self>|null $files
*/
#[\NoDiscard]
public static function of(Name $name, ?Sequence $files = null): self
{
return new self(
Expand All @@ -46,6 +47,7 @@ public static function of(Name $name, ?Sequence $files = null): self
* @param non-empty-string $name
* @param Sequence<File|self>|null $files
*/
#[\NoDiscard]
public static function named(string $name, ?Sequence $files = null): self
{
return new self(
Expand All @@ -61,6 +63,7 @@ public static function named(string $name, ?Sequence $files = null): self
*
* @param Sequence<File|self> $files
*/
#[\NoDiscard]
public static function lazy(Name $name, Sequence $files): self
{
// we prevent the contrusctor from checking for duplicates when
Expand All @@ -71,11 +74,13 @@ public static function lazy(Name $name, Sequence $files): self
return new self($name, $files, Set::of());
}

#[\NoDiscard]
public function name(): Name
{
return $this->name;
}

#[\NoDiscard]
public function rename(Name $name): self
{
return new self(
Expand All @@ -85,6 +90,7 @@ public function rename(Name $name): self
);
}

#[\NoDiscard]
public function add(File|self $file): self
{
return new self(
Expand All @@ -100,11 +106,13 @@ public function add(File|self $file): self
/**
* @return Maybe<File|self>
*/
#[\NoDiscard]
public function get(Name $name): Maybe
{
return $this->files->find(static fn($file) => $file->name()->equals($name));
}

#[\NoDiscard]
public function contains(Name $name): bool
{
return $this->get($name)->match(
Expand All @@ -113,6 +121,7 @@ public function contains(Name $name): bool
);
}

#[\NoDiscard]
public function remove(Name $name): self
{
return new self(
Expand All @@ -125,6 +134,7 @@ public function remove(Name $name): self
/**
* @param callable(File|self): void $function
*/
#[\NoDiscard]
public function foreach(callable $function): SideEffect
{
return $this->files->foreach($function);
Expand All @@ -133,6 +143,7 @@ public function foreach(callable $function): SideEffect
/**
* @param callable(File|self): bool $predicate
*/
#[\NoDiscard]
public function filter(callable $predicate): self
{
// it is safe to not check for duplicates here as either the current
Expand All @@ -150,6 +161,7 @@ public function filter(callable $predicate): self
/**
* @param callable(File|self): File $map
*/
#[\NoDiscard]
public function map(callable $map): self
{
return new self(
Expand All @@ -162,6 +174,7 @@ public function map(callable $map): self
/**
* @param callable(File|self): self $map
*/
#[\NoDiscard]
public function flatMap(callable $map): self
{
/** @var callable(File|self): Sequence<File|self> */
Expand All @@ -182,6 +195,7 @@ public function flatMap(callable $map): self
*
* @return R
*/
#[\NoDiscard]
public function reduce($carry, callable $reducer)
{
return $this->files->reduce($carry, $reducer);
Expand All @@ -195,6 +209,7 @@ public function reduce($carry, callable $reducer)
*
* @return Set<Name>
*/
#[\NoDiscard]
public function removed(): Set
{
return $this->removed;
Expand All @@ -203,6 +218,7 @@ public function removed(): Set
/**
* @return Sequence<File|self>
*/
#[\NoDiscard]
public function all(): Sequence
{
return $this->files;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/MountPathDoesntExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(
/**
* @return Attempt<Implementation>
*/
#[\NoDiscard]
public function recover(): Attempt
{
return ($this->recover)();
Expand Down
1 change: 1 addition & 0 deletions src/Exception/RecoverMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(
/**
* @return Attempt<Adapter>
*/
#[\NoDiscard]
public function recover(): Attempt
{
return ($this->recover)();
Expand Down
8 changes: 8 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private function __construct(
/**
* @psalm-pure
*/
#[\NoDiscard]
public static function of(
Name $name,
Content $content,
Expand All @@ -34,6 +35,7 @@ public static function of(
*
* @param non-empty-string $name
*/
#[\NoDiscard]
public static function named(
string $name,
Content $content,
Expand All @@ -42,26 +44,31 @@ public static function named(
return self::of(Name::of($name), $content, $mediaType);
}

#[\NoDiscard]
public function name(): Name
{
return $this->name;
}

#[\NoDiscard]
public function content(): Content
{
return $this->content;
}

#[\NoDiscard]
public function mediaType(): MediaType
{
return $this->mediaType;
}

#[\NoDiscard]
public function rename(Name $name): self
{
return new self($name, $this->content, $this->mediaType);
}

#[\NoDiscard]
public function withContent(Content $content, ?MediaType $mediaType = null): self
{
return new self(
Expand All @@ -74,6 +81,7 @@ public function withContent(Content $content, ?MediaType $mediaType = null): sel
/**
* @param callable(Content): Content $map
*/
#[\NoDiscard]
public function mapContent(callable $map): self
{
/** @psalm-suppress ImpureFunctionCall */
Expand Down
Loading