-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Properties\Innmind\Filesystem\Adapter; | ||
|
||
use Innmind\Filesystem\{ | ||
Adapter, | ||
File, | ||
Name, | ||
Directory\Directory, | ||
}; | ||
use Innmind\BlackBox\{ | ||
Property, | ||
Set, | ||
Runner\Assert, | ||
}; | ||
use Fixtures\Innmind\Filesystem\{ | ||
File as FFile, | ||
Name as FName, | ||
}; | ||
|
||
/** | ||
* @implements Property<Adapter> | ||
*/ | ||
final class RemoveFileInDirectory implements Property | ||
{ | ||
private File $file; | ||
private Name $name; | ||
|
||
public function __construct(File $file, Name $name) | ||
{ | ||
$this->file = $file; | ||
$this->name = $name; | ||
} | ||
|
||
public static function any(): Set | ||
{ | ||
return Set\Composite::immutable( | ||
static fn(...$args) => new self(...$args), | ||
FFile::any(), | ||
FName::any(), | ||
); | ||
} | ||
|
||
public function applicableTo(object $adapter): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function ensureHeldBy(Assert $assert, object $adapter): object | ||
{ | ||
$assert->null($adapter->add(Directory::of($this->name)->add($this->file))); | ||
$assert->null($adapter->add(Directory::of($this->name)->remove($this->file->name()))); | ||
$assert->false( | ||
$adapter | ||
->get($this->name) | ||
->match( | ||
fn($directory) => $directory->contains($this->file->name()), | ||
static fn() => null, | ||
), | ||
); | ||
|
||
return $adapter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters