-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve object constructors parameters types inferring
The collision system that checks object constructors parameters types is now way more clever, as it no longer checks for parameters' names only. Types are now also checked, and only true collision will be detected, for instance when two constructors share a parameter with the same name and type. Note that when two parameters share the same name, the following type priority operates: 1. Non-scalar type 2. Integer type 3. Float type 4. String type 5. Boolean type With this change, the code below is now valid: ```php final readonly class Money { private function __construct( public int $value, ) {} #[\CuyZ\Valinor\Mapper\Object\Constructor] public static function fromInt(int $value): self { return new self($value); } #[\CuyZ\Valinor\Mapper\Object\Constructor] public static function fromString(string $value): self { if (! preg_match('/^\d+€$/', $value)) { throw new \InvalidArgumentException('Invalid money format'); } return new self((int)rtrim($value, '€')); } } $mapper = (new \CuyZ\Valinor\MapperBuilder())->mapper(); $mapper->map(Money::class, 42); // ✅ $mapper->map(Money::class, '42€'); // ✅ ```
- Loading branch information
Showing
24 changed files
with
582 additions
and
524 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
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
24 changes: 0 additions & 24 deletions
24
src/Mapper/Object/Exception/SeveralObjectBuildersFound.php
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
src/Mapper/Object/Factory/CollisionObjectBuilderFactory.php
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
Oops, something went wrong.