forked from CuyZ/Valinor
-
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.
Composite types are composed of other types and must now implement a method to recursively traverse all sub-types.
- Loading branch information
Showing
24 changed files
with
451 additions
and
15 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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CuyZ\Valinor\Type; | ||
|
||
/** @api */ | ||
interface CompositeType extends Type | ||
{ | ||
/** | ||
* @return iterable<Type> | ||
*/ | ||
public function traverse(): iterable; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CuyZ\Valinor\Tests\Fake\Type; | ||
|
||
use CuyZ\Valinor\Type\CompositeType; | ||
use CuyZ\Valinor\Type\Type; | ||
|
||
final class FakeCompositeType implements CompositeType | ||
{ | ||
/** @var Type[] */ | ||
private array $types; | ||
|
||
public function __construct(Type ...$types) | ||
{ | ||
$this->types = $types; | ||
} | ||
|
||
public function traverse(): iterable | ||
{ | ||
yield from $this->types; | ||
} | ||
|
||
public function accepts($value): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function matches(Type $other): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return 'FakeCompositeType'; | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CuyZ\Valinor\Tests\Fake\Type; | ||
|
||
use CuyZ\Valinor\Type\CompositeType; | ||
use CuyZ\Valinor\Type\ObjectType; | ||
use CuyZ\Valinor\Type\Type; | ||
use stdClass; | ||
|
||
final class FakeObjectCompositeType implements ObjectType, CompositeType | ||
{ | ||
/** @var class-string */ | ||
private string $className; | ||
|
||
/** @var array<string, Type> */ | ||
private array $generics; | ||
|
||
/** | ||
* @param class-string $className | ||
* @param array<string, Type> $generics | ||
*/ | ||
public function __construct(string $className = stdClass::class, array $generics = []) | ||
{ | ||
$this->className = $className; | ||
$this->generics = $generics; | ||
} | ||
|
||
public function className(): string | ||
{ | ||
return $this->className; | ||
} | ||
|
||
public function generics(): array | ||
{ | ||
return $this->generics; | ||
} | ||
|
||
public function accepts($value): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function matches(Type $other): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function traverse(): iterable | ||
{ | ||
yield from $this->generics; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->className; | ||
} | ||
} |
Oops, something went wrong.