From 816216802a9716bb5f20cc38336313b043bf764c Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Tue, 22 Jan 2019 20:49:46 +0100 Subject: [PATCH 01/17] remove dbal from the object graph --- graph.php | 12 +- graph.svg | 3948 +++++++++++++++-------------------------------------- 2 files changed, 1096 insertions(+), 2864 deletions(-) diff --git a/graph.php b/graph.php index 4c515f8..d50e720 100644 --- a/graph.php +++ b/graph.php @@ -15,6 +15,8 @@ use Innmind\ObjectGraph\{ Graph, Visualize, + Visitor\FlagDependencies, + Visitor\RemoveDependenciesSubGraph, }; use Innmind\Immutable\Set; @@ -32,6 +34,12 @@ protected function main(Environment $env, OperatingSystem $os): void $graph = new Graph; $visualize = new Visualize; + $flag = new FlagDependencies($dbal); + $remove = new RemoveDependenciesSubGraph; + + $node = $graph($package['manager']); + $flag($node); + $remove($node); $os ->control() @@ -40,9 +48,7 @@ protected function main(Environment $env, OperatingSystem $os): void Command::foreground('dot') ->withShortOption('Tsvg') ->withShortOption('o', 'graph.svg') - ->withInput( - $visualize($graph($package['manager'])) - ) + ->withInput($visualize($node)) ) ->wait(); } diff --git a/graph.svg b/graph.svg index c0d9021..1bdcaef 100644 --- a/graph.svg +++ b/graph.svg @@ -4,3290 +4,1516 @@ - - + + G - - + + -object_00000000234bbeb9000000001569f266 +object_00000000593cb73d00000000558b3083 - -Innmind\Neo4j\ONM\Manager\Manager + +Innmind\Neo4j\ONM\Manager\Manager - + -object_00000000234bbede000000001569f266 +object_00000000593cb75a00000000558b3083 - -Innmind\Neo4j\ONM\UnitOfWork + +Innmind\Neo4j\ONM\UnitOfWork - + -object_00000000234bbeb9000000001569f266->object_00000000234bbede000000001569f266 - - -unitOfWork +object_00000000593cb73d00000000558b3083->object_00000000593cb75a00000000558b3083 + + +unitOfWork - + -object_00000000234bbf0b000000001569f266 +object_00000000593cb68f00000000558b3083 - -Innmind\Neo4j\ONM\Metadatas + +Innmind\Neo4j\ONM\Metadatas - + -object_00000000234bbeb9000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata +object_00000000593cb73d00000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata - + -object_00000000234bbeb8000000001569f266 +object_00000000593cb73c00000000558b3083 - -Innmind\Neo4j\ONM\RepositoryFactory + +Innmind\Neo4j\ONM\RepositoryFactory - + -object_00000000234bbeb9000000001569f266->object_00000000234bbeb8000000001569f266 - - -make +object_00000000593cb73d00000000558b3083->object_00000000593cb73c00000000558b3083 + + +make - + -object_00000000234bbf10000000001569f266 +object_00000000593cb69400000000558b3083 - -Innmind\Neo4j\ONM\Identity\Generators + +Innmind\Neo4j\ONM\Identity\Generators - + -object_00000000234bbeb9000000001569f266->object_00000000234bbf10000000001569f266 - - -generators +object_00000000593cb73d00000000558b3083->object_00000000593cb69400000000558b3083 + + +generators - + -object_00000000234bbede000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata +object_00000000593cb75a00000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata - + -object_00000000234bbede000000001569f266->object_00000000234bbf10000000001569f266 - - -generators +object_00000000593cb75a00000000558b3083->object_00000000593cb69400000000558b3083 + + +generators - + -object_00000000234bbf78000000001569f266 +object_00000000593cb6fc00000000558b3083 - -Innmind\Neo4j\DBAL\Connection\Connection + +Innmind\Neo4j\DBAL\Connection\Connection - + -object_00000000234bbede000000001569f266->object_00000000234bbf78000000001569f266 - - -connection +object_00000000593cb75a00000000558b3083->object_00000000593cb6fc00000000558b3083 + + +connection - + -object_00000000234bbeec000000001569f266 +object_00000000593cb76800000000558b3083 - -Innmind\Neo4j\ONM\Entity\Container + +Innmind\Neo4j\ONM\Entity\Container - + -object_00000000234bbede000000001569f266->object_00000000234bbeec000000001569f266 - - -container +object_00000000593cb75a00000000558b3083->object_00000000593cb76800000000558b3083 + + +container - + -object_00000000234bbecf000000001569f266 +object_00000000593cb74b00000000558b3083 - -Innmind\Neo4j\ONM\EntityFactory\EntityFactory + +Innmind\Neo4j\ONM\EntityFactory\EntityFactory - + -object_00000000234bbede000000001569f266->object_00000000234bbecf000000001569f266 - - -makeEntity +object_00000000593cb75a00000000558b3083->object_00000000593cb74b00000000558b3083 + + +makeEntity - + -object_00000000234bbeb3000000001569f266 +object_00000000593cb73700000000558b3083 - -Innmind\Neo4j\ONM\Translation\IdentityMatch\DelegationTranslator + +Innmind\Neo4j\ONM\Translation\IdentityMatch\DelegationTranslator - + -object_00000000234bbede000000001569f266->object_00000000234bbeb3000000001569f266 - - -match +object_00000000593cb75a00000000558b3083->object_00000000593cb73700000000558b3083 + + +match - + -object_00000000234bbee7000000001569f266 +object_00000000593cb76300000000558b3083 - -Innmind\Neo4j\ONM\Persister\DelegationPersister + +Innmind\Neo4j\ONM\Persister\DelegationPersister - + -object_00000000234bbede000000001569f266->object_00000000234bbee7000000001569f266 - - -persist - - - -object_00000000234bbeb8000000001569f266->object_00000000234bbede000000001569f266 - - -unitOfWork - - - -object_00000000234bbebb000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Match\DelegationTranslator - - - - - -object_00000000234bbeb8000000001569f266->object_00000000234bbebb000000001569f266 - - -matchTranslator - - - -object_00000000234bbeba000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\DelegationTranslator - - - - - -object_00000000234bbeb8000000001569f266->object_00000000234bbeba000000001569f266 - - -specificationTranslator - - - -object_00000000234bb158000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbf10000000001569f266->object_00000000234bb158000000001569f266 - - -mapping - - - -object_00000000234bbf79000000001569f266 - - -Innmind\Neo4j\DBAL\Transport\Http +object_00000000593cb75a00000000558b3083->object_00000000593cb76300000000558b3083 + + +persist + + + +object_00000000593cb73c00000000558b3083->object_00000000593cb75a00000000558b3083 + + +unitOfWork + + + +object_00000000593cb73f00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Match\DelegationTranslator - - -object_00000000234bbf78000000001569f266->object_00000000234bbf79000000001569f266 - - -transport + + +object_00000000593cb73c00000000558b3083->object_00000000593cb73f00000000558b3083 + + +matchTranslator - - -object_00000000234bbfa2000000001569f266 - - -Innmind\Neo4j\DBAL\Transactions + + +object_00000000593cb73e00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\DelegationTranslator - - -object_00000000234bbf78000000001569f266->object_00000000234bbfa2000000001569f266 - - -transactions - - - -object_00000000234bbddc000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbeec000000001569f266->object_00000000234bbddc000000001569f266 - - -states - - - -object_00000000234bbecf000000001569f266->object_00000000234bbf10000000001569f266 - - -generators - - - -object_00000000234bbecf000000001569f266->object_00000000234bbeec000000001569f266 - - -entities - - - -object_00000000234bbece000000001569f266 - - -Innmind\Neo4j\ONM\Translation\ResultTranslator - - - - - -object_00000000234bbecf000000001569f266->object_00000000234bbece000000001569f266 - - -translate - - - -object_00000000234bbeb1000000001569f266 - - -Innmind\Neo4j\ONM\EntityFactory\Resolver - - - - - -object_00000000234bbecf000000001569f266->object_00000000234bbeb1000000001569f266 - - -resolve - - - -object_00000000234bb068000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbeb3000000001569f266->object_00000000234bb068000000001569f266 - - -translators - - - -object_00000000234baf86000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbee7000000001569f266->object_00000000234baf86000000001569f266 - - -persisters - - - -object_00000000234bbf7b000000001569f266 - - -Innmind\Neo4j\DBAL\Translator\HttpTranslator + + +object_00000000593cb73c00000000558b3083->object_00000000593cb73e00000000558b3083 + + +specificationTranslator + + + +object_00000000593cb8db00000000558b3083 + + +ArrayObject - - -object_00000000234bbf79000000001569f266->object_00000000234bbf7b000000001569f266 - - -translate + + +object_00000000593cb69400000000558b3083->object_00000000593cb8db00000000558b3083 + + +mapping - - -object_00000000234bbfd6000000001569f266 - - -Innmind\Neo4j\DBAL\HttpTransport\Transport + + +object_00000000593cb45700000000558b3083 + + +ArrayObject - - -object_00000000234bbf79000000001569f266->object_00000000234bbfd6000000001569f266 - - -fulfill + + +object_00000000593cb76800000000558b3083->object_00000000593cb45700000000558b3083 + + +states - - -object_00000000234bbfa2000000001569f266->object_00000000234bbfd6000000001569f266 - - -fulfill + + +object_00000000593cb74b00000000558b3083->object_00000000593cb69400000000558b3083 + + +generators - + + +object_00000000593cb74b00000000558b3083->object_00000000593cb76800000000558b3083 + + +entities + + -object_00000000234bbd4c000000001569f266 - - -ArrayObject +object_00000000593cb74a00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\ResultTranslator - - -object_00000000234bbfa2000000001569f266->object_00000000234bbd4c000000001569f266 - - -headers + + +object_00000000593cb74b00000000558b3083->object_00000000593cb74a00000000558b3083 + + +translate - + -object_00000000234bbff7000000001569f266 - - -Innmind\TimeContinuum\TimeContinuum\Earth +object_00000000593cb73500000000558b3083 + + +Innmind\Neo4j\ONM\EntityFactory\Resolver - - -object_00000000234bbfa2000000001569f266->object_00000000234bbff7000000001569f266 - - -clock + + +object_00000000593cb74b00000000558b3083->object_00000000593cb73500000000558b3083 + + +resolve - - -object_00000000234bbf8e000000001569f266 - - -Innmind\Filesystem\Stream\StringStream + + +object_00000000593cb9eb00000000558b3083 + + +ArrayObject - - -object_00000000234bbfa2000000001569f266->object_00000000234bbf8e000000001569f266 - - -body + + +object_00000000593cb73700000000558b3083->object_00000000593cb9eb00000000558b3083 + + +translators - - -object_00000000234bbf7b000000001569f266->object_00000000234bbfa2000000001569f266 - - -transactions + + +object_00000000593ca60100000000558b3083 + + +ArrayObject + - - -object_00000000234bbdd6000000001569f266 - - -ArrayObject + + + +object_00000000593cb76300000000558b3083->object_00000000593ca60100000000558b3083 + + +persisters + + + +object_00000000593cb46c00000000558b3083 + + +Innmind\Immutable\Pair - - -object_00000000234bbf7b000000001569f266->object_00000000234bbdd6000000001569f266 - - -headers + + +object_00000000593cb45700000000558b3083->object_00000000593cb46c00000000558b3083 + + +0 - - -object_00000000234bbf9f000000001569f266 - - -Innmind\Url\Url + + +object_00000000593cb4d000000000558b3083 + + +Innmind\Immutable\Pair - - -object_00000000234bbfd6000000001569f266->object_00000000234bbf9f000000001569f266 - - -server + + +object_00000000593cb45700000000558b3083->object_00000000593cb4d000000000558b3083 + + +1 - - -object_00000000234bbf9c000000001569f266 - - -Innmind\Http\Header\Authorization + + +object_00000000593cb4d100000000558b3083 + + +Innmind\Immutable\Pair - - -object_00000000234bbfd6000000001569f266->object_00000000234bbf9c000000001569f266 - - -authorization + + +object_00000000593cb45700000000558b3083->object_00000000593cb4d100000000558b3083 + + +2 - - -object_00000000234bbfd0000000001569f266 - - -Innmind\HttpTransport\DefaultTransport + + +object_00000000593cb4c100000000558b3083 + + +Innmind\Immutable\Pair - - -object_00000000234bbfd6000000001569f266->object_00000000234bbfd0000000001569f266 - - -fulfill + + +object_00000000593cb45700000000558b3083->object_00000000593cb4c100000000558b3083 + + +3 - + -object_00000000234bbded000000001569f266 - - -Innmind\Immutable\Pair +object_00000000593cb76a00000000558b3083 + + +Innmind\Neo4j\ONM\Entity\Container\State - - -object_00000000234bbdd6000000001569f266->object_00000000234bbded000000001569f266 - - -0 + + +object_00000000593cb46c00000000558b3083->object_00000000593cb76a00000000558b3083 + + +key - + -object_00000000234bbdea000000001569f266 - - -Innmind\Immutable\Pair +object_00000000593cb76b00000000558b3083 + + +Innmind\Neo4j\ONM\Entity\Container\State - - -object_00000000234bbdd6000000001569f266->object_00000000234bbdea000000001569f266 - - -1 + + +object_00000000593cb4d000000000558b3083->object_00000000593cb76b00000000558b3083 + + +key - + -object_00000000234bbf7a000000001569f266 - - -Innmind\Http\Header\ContentType +object_00000000593cb75200000000558b3083 + + +Innmind\Neo4j\ONM\Entity\Container\State - - -object_00000000234bbded000000001569f266->object_00000000234bbf7a000000001569f266 - - -value + + +object_00000000593cb4d100000000558b3083->object_00000000593cb75200000000558b3083 + + +key - + -object_00000000234bbf67000000001569f266 - - -Innmind\Http\Header\Accept +object_00000000593cb75000000000558b3083 + + +Innmind\Neo4j\ONM\Entity\Container\State - - -object_00000000234bbdea000000001569f266->object_00000000234bbf67000000001569f266 - - -value - - - -object_00000000234bbd5d000000001569f266 - - -Innmind\Immutable\Pair - - + + +object_00000000593cb4c100000000558b3083->object_00000000593cb75000000000558b3083 + + +key - - -object_00000000234bbd4c000000001569f266->object_00000000234bbd5d000000001569f266 - - -0 + + +object_00000000593cb76a00000000558b3083->object_00000000593cb76a00000000558b3083 + + +managed - - -object_00000000234bbff1000000001569f266 - - -Innmind\TimeContinuum\Timezone\Earth\UTC - + + +object_00000000593cb76a00000000558b3083->object_00000000593cb76b00000000558b3083 + + +new + + +object_00000000593cb76a00000000558b3083->object_00000000593cb75200000000558b3083 + + +toBeRemoved - - -object_00000000234bbff7000000001569f266->object_00000000234bbff1000000001569f266 - - -timezone + + +object_00000000593cb76a00000000558b3083->object_00000000593cb75000000000558b3083 + + +removed - - -object_00000000234bbf8c000000001569f266 - - -Innmind\Stream\Readable\Stream - + + +object_00000000593cb76b00000000558b3083->object_00000000593cb76a00000000558b3083 + + +managed + + +object_00000000593cb76b00000000558b3083->object_00000000593cb76b00000000558b3083 + + +new - - -object_00000000234bbf8e000000001569f266->object_00000000234bbf8c000000001569f266 - - -stream + + +object_00000000593cb76b00000000558b3083->object_00000000593cb75200000000558b3083 + + +toBeRemoved - - -object_00000000234bbfae000000001569f266 - - -Innmind\Http\Header\ContentType - + + +object_00000000593cb76b00000000558b3083->object_00000000593cb75000000000558b3083 + + +removed + + +object_00000000593cb75200000000558b3083->object_00000000593cb76a00000000558b3083 + + +managed - + -object_00000000234bbd5d000000001569f266->object_00000000234bbfae000000001569f266 - - -value - - - -object_00000000234bbfad000000001569f266 - - -Innmind\Url\Scheme - +object_00000000593cb75200000000558b3083->object_00000000593cb76b00000000558b3083 + + +new + + +object_00000000593cb75200000000558b3083->object_00000000593cb75200000000558b3083 + + +toBeRemoved - - -object_00000000234bbf9f000000001569f266->object_00000000234bbfad000000001569f266 - - -scheme + + +object_00000000593cb75200000000558b3083->object_00000000593cb75000000000558b3083 + + +removed - - -object_00000000234bbf90000000001569f266 - - -Innmind\Url\Authority - + + +object_00000000593cb75000000000558b3083->object_00000000593cb76a00000000558b3083 + + +managed + + +object_00000000593cb75000000000558b3083->object_00000000593cb76b00000000558b3083 + + +new - + -object_00000000234bbf9f000000001569f266->object_00000000234bbf90000000001569f266 - - -authority - - - -object_00000000234bbf92000000001569f266 - - -Innmind\Url\NullPath - +object_00000000593cb75000000000558b3083->object_00000000593cb75200000000558b3083 + + +toBeRemoved - - + -object_00000000234bbf9f000000001569f266->object_00000000234bbf92000000001569f266 - - -path - - - -object_00000000234bbf93000000001569f266 - - -Innmind\Url\NullQuery - - +object_00000000593cb75000000000558b3083->object_00000000593cb75000000000558b3083 + + +removed - - -object_00000000234bbf9f000000001569f266->object_00000000234bbf93000000001569f266 - - -query - - - -object_00000000234bbf9d000000001569f266 - - -Innmind\Url\NullFragment - - - - - -object_00000000234bbf9f000000001569f266->object_00000000234bbf9d000000001569f266 - - -fragment - - - -object_00000000234bbfd1000000001569f266 - - -GuzzleHttp\Client + + +object_00000000593cb85b00000000558b3083 + + +ArrayObject - + -object_00000000234bbfd0000000001569f266->object_00000000234bbfd1000000001569f266 - - -client - - - -object_00000000234bbfc7000000001569f266 - - -Innmind\Http\Translator\Response\Psr7Translator - - +object_00000000593cb74a00000000558b3083->object_00000000593cb85b00000000558b3083 + + +translators - - -object_00000000234bbfd0000000001569f266->object_00000000234bbfc7000000001569f266 - - -translator - - - -object_00000000234bbf97000000001569f266 - - -Innmind\Url\Authority\NullUserInformation - - - - - -object_00000000234bbf90000000001569f266->object_00000000234bbf97000000001569f266 - - -userInformation - - - -object_00000000234bbfa8000000001569f266 - - -Innmind\Url\Authority\Host - - - - - -object_00000000234bbf90000000001569f266->object_00000000234bbfa8000000001569f266 - - -host - - - -object_00000000234bbfab000000001569f266 - - -Innmind\Url\Authority\Port - - - - - -object_00000000234bbf90000000001569f266->object_00000000234bbfab000000001569f266 - - -port - - - -object_00000000234bbf96000000001569f266 - - -Innmind\Url\Authority\UserInformation\NullUser + + +object_00000000593cb97900000000558b3083 + + +ArrayObject - - -object_00000000234bbf97000000001569f266->object_00000000234bbf96000000001569f266 - - -user + + +object_00000000593cb73500000000558b3083->object_00000000593cb97900000000558b3083 + + +mapping - - -object_00000000234bbf91000000001569f266 - - -Innmind\Url\Authority\UserInformation\NullPassword + + +object_00000000593cb86a00000000558b3083 + + +Innmind\Immutable\Pair - - -object_00000000234bbf97000000001569f266->object_00000000234bbf91000000001569f266 - - -password + + +object_00000000593cb85b00000000558b3083->object_00000000593cb86a00000000558b3083 + + +0 - - -object_00000000234bbb9e000000001569f266 - - -ArrayObject + + +object_00000000593cb85800000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbfd1000000001569f266->object_00000000234bbb9e000000001569f266 - - -config - - - -object_00000000234bbfc6000000001569f266 - - -Innmind\Http\Factory\Header\TryFactory - - +object_00000000593cb85b00000000558b3083->object_00000000593cb85800000000558b3083 + + +1 - - -object_00000000234bbfc7000000001569f266->object_00000000234bbfc6000000001569f266 - - -headerFactory - - - -object_00000000234bbb97000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb6c600000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Result\AggregateTranslator - + -object_00000000234bbb9e000000001569f266->object_00000000234bbb97000000001569f266 - - -0 +object_00000000593cb86a00000000558b3083->object_00000000593cb6c600000000558b3083 + + +value - - -object_00000000234bbfd3000000001569f266 - - -GuzzleHttp\HandlerStack + + +object_00000000593cb6cd00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Result\RelationshipTranslator - + -object_00000000234bbb97000000001569f266->object_00000000234bbfd3000000001569f266 - - -value +object_00000000593cb85800000000558b3083->object_00000000593cb6cd00000000558b3083 + + +value - - -object_00000000234bbb31000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbfd3000000001569f266->object_00000000234bbb31000000001569f266 - - -stack - - - -object_00000000234bbfd8000000001569f266 - - -Closure + + +object_00000000593cb8e800000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbfd3000000001569f266->object_00000000234bbfd8000000001569f266 - - -handler +object_00000000593cb8db00000000558b3083->object_00000000593cb8e800000000558b3083 + + +0 - - -object_00000000234bbb37000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb69e00000000558b3083 + + +Innmind\Neo4j\ONM\Identity\Generator\UuidGenerator - + -object_00000000234bbb31000000001569f266->object_00000000234bbb37000000001569f266 - - -0 - - - -object_00000000234bbb35000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bbb31000000001569f266->object_00000000234bbb35000000001569f266 - - -1 +object_00000000593cb8e800000000558b3083->object_00000000593cb69e00000000558b3083 + + +value - - -object_00000000234bbb4c000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb88300000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbb31000000001569f266->object_00000000234bbb4c000000001569f266 - - -2 +object_00000000593cb97900000000558b3083->object_00000000593cb88300000000558b3083 + + +0 - - -object_00000000234bbb4a000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb96700000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbb31000000001569f266->object_00000000234bbb4a000000001569f266 - - -3 +object_00000000593cb97900000000558b3083->object_00000000593cb96700000000558b3083 + + +1 - - -object_00000000234bbaf7000000001569f266 - - -ArrayObject + + +object_00000000593cb69700000000558b3083 + + +Innmind\Neo4j\ONM\EntityFactory\AggregateFactory - + -object_00000000234bbb37000000001569f266->object_00000000234bbaf7000000001569f266 - - -value +object_00000000593cb88300000000558b3083->object_00000000593cb69700000000558b3083 + + +value - - -object_00000000234bba84000000001569f266 - - -ArrayObject + + +object_00000000593cb69a00000000558b3083 + + +Innmind\Neo4j\ONM\EntityFactory\RelationshipFactory - + -object_00000000234bbb35000000001569f266->object_00000000234bba84000000001569f266 - - -value - - - -object_00000000234bba2a000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbb4c000000001569f266->object_00000000234bba2a000000001569f266 - - -value - - - -object_00000000234bb9b8000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbb4a000000001569f266->object_00000000234bb9b8000000001569f266 - - -value +object_00000000593cb96700000000558b3083->object_00000000593cb69a00000000558b3083 + + +value - - -object_00000000234bbb09000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb69b00000000558b3083 + + +Innmind\Reflection\Instanciator\ConstructorLessInstanciator - + -object_00000000234bbaf7000000001569f266->object_00000000234bbb09000000001569f266 - - -0 +object_00000000593cb69700000000558b3083->object_00000000593cb69b00000000558b3083 + + +instanciator - - -object_00000000234bbfdb000000001569f266 - - -Closure + + +object_00000000593cb69d00000000558b3083 + + +Innmind\Reflection\InjectionStrategy\ReflectionStrategy - + -object_00000000234bbb09000000001569f266->object_00000000234bbfdb000000001569f266 - - -value - - - -object_00000000234bbaa4000000001569f266 - - -Innmind\Immutable\Pair - +object_00000000593cb69700000000558b3083->object_00000000593cb69d00000000558b3083 + + +injectionStrategy - - + -object_00000000234bba84000000001569f266->object_00000000234bbaa4000000001569f266 - - -0 +object_00000000593cb69a00000000558b3083->object_00000000593cb69400000000558b3083 + + +generators - - -object_00000000234bbfda000000001569f266 - - -Closure + + +object_00000000593cb69f00000000558b3083 + + +Innmind\Reflection\Instanciator\ConstructorLessInstanciator - + -object_00000000234bbaa4000000001569f266->object_00000000234bbfda000000001569f266 - - -value +object_00000000593cb69a00000000558b3083->object_00000000593cb69f00000000558b3083 + + +instanciator - - -object_00000000234bba4a000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb69c00000000558b3083 + + +Innmind\Reflection\InjectionStrategy\ReflectionStrategy - - -object_00000000234bba2a000000001569f266->object_00000000234bba4a000000001569f266 - - -0 + + +object_00000000593cb69a00000000558b3083->object_00000000593cb69c00000000558b3083 + + +injectionStrategy - - -object_00000000234bbfc5000000001569f266 - - -Closure + + +object_00000000593cb8fa00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bba4a000000001569f266->object_00000000234bbfc5000000001569f266 - - -value +object_00000000593cb9eb00000000558b3083->object_00000000593cb8fa00000000558b3083 + + +0 - - -object_00000000234bb9d8000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb9e600000000558b3083 + + +Innmind\Immutable\Pair + + + + + +object_00000000593cb9eb00000000558b3083->object_00000000593cb9e600000000558b3083 + + +1 + + + +object_00000000593cb6b400000000558b3083 + + +Innmind\Neo4j\ONM\Translation\IdentityMatch\AggregateTranslator - + -object_00000000234bb9b8000000001569f266->object_00000000234bb9d8000000001569f266 - - -0 +object_00000000593cb8fa00000000558b3083->object_00000000593cb6b400000000558b3083 + + +value - - -object_00000000234bbfc4000000001569f266 - - -Closure + + +object_00000000593cb6b500000000558b3083 + + +Innmind\Neo4j\ONM\Translation\IdentityMatch\RelationshipTranslator - + -object_00000000234bb9d8000000001569f266->object_00000000234bbfc4000000001569f266 - - -value +object_00000000593cb9e600000000558b3083->object_00000000593cb6b500000000558b3083 + + +value - - -object_00000000234bbfc1000000001569f266 - - -Innmind\Http\Factory\Header\DelegationFactory + + +object_00000000593ca63e00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbfc6000000001569f266->object_00000000234bbfc1000000001569f266 - - -try +object_00000000593ca60100000000558b3083->object_00000000593ca63e00000000558b3083 + + +0 - - -object_00000000234bbfa6000000001569f266 - - -Innmind\Http\Factory\Header\HeaderFactory + + +object_00000000593ca62f00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbfc6000000001569f266->object_00000000234bbfa6000000001569f266 - - -fallback +object_00000000593ca60100000000558b3083->object_00000000593ca62f00000000558b3083 + + +1 - - -object_00000000234bb7d3000000001569f266 - - -ArrayObject + + +object_00000000593ca60500000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bbfc1000000001569f266->object_00000000234bb7d3000000001569f266 - - -factories +object_00000000593ca60100000000558b3083->object_00000000593ca60500000000558b3083 + + +2 - - -object_00000000234bb7f5000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76200000000558b3083 + + +Innmind\Neo4j\ONM\Persister\InsertPersister - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7f5000000001569f266 - - -0 +object_00000000593ca63e00000000558b3083->object_00000000593cb76200000000558b3083 + + +value - - -object_00000000234bb7f2000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76400000000558b3083 + + +Innmind\Neo4j\ONM\Persister\UpdatePersister - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7f2000000001569f266 - - -1 + + +object_00000000593ca62f00000000558b3083->object_00000000593cb76400000000558b3083 + + +value - - -object_00000000234bb7fd000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76600000000558b3083 + + +Innmind\Neo4j\ONM\Persister\RemovePersister - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7fd000000001569f266 - - -2 + + +object_00000000593ca60500000000558b3083->object_00000000593cb76600000000558b3083 + + +value - - -object_00000000234bb7f3000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76200000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata + + + +object_00000000593cb77100000000558b3083 + + +Innmind\Neo4j\ONM\Entity\ChangesetComputer - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7f3000000001569f266 - - -3 + + +object_00000000593cb76200000000558b3083->object_00000000593cb77100000000558b3083 + + +changeset - - -object_00000000234bb7f7000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb6db00000000558b3083 + + +Innmind\EventBus\EventBus\NullEventBus - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7f7000000001569f266 - - -4 + + +object_00000000593cb76200000000558b3083->object_00000000593cb6db00000000558b3083 + + +dispatch - - -object_00000000234bb80a000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb77a00000000558b3083 + + +Innmind\Neo4j\ONM\Entity\DataExtractor\DataExtractor - - -object_00000000234bb7d3000000001569f266->object_00000000234bb80a000000001569f266 - - -5 + + +object_00000000593cb76200000000558b3083->object_00000000593cb77a00000000558b3083 + + +extract - - -object_00000000234bb7f0000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76500000000558b3083 + + +Innmind\Immutable\Str - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7f0000000001569f266 - - -6 + + +object_00000000593cb76200000000558b3083->object_00000000593cb76500000000558b3083 + + +name - - -object_00000000234bb7e6000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb77a00000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata + + + +object_00000000593ca75b00000000558b3083 + + +ArrayObject - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7e6000000001569f266 - - -7 + + +object_00000000593cb77a00000000558b3083->object_00000000593ca75b00000000558b3083 + + +extractors - - -object_00000000234bb7e1000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593ca76a00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7e1000000001569f266 - - -8 +object_00000000593ca75b00000000558b3083->object_00000000593ca76a00000000558b3083 + + +0 - - -object_00000000234bb7e0000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593ca75700000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7e0000000001569f266 - - -9 +object_00000000593ca75b00000000558b3083->object_00000000593ca75700000000558b3083 + + +1 - - -object_00000000234bb7e3000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb6ac00000000558b3083 + + +Innmind\Neo4j\ONM\Entity\DataExtractor\AggregateExtractor - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7e3000000001569f266 - - -10 - - - -object_00000000234bb7e2000000001569f266 - - -Innmind\Immutable\Pair - +object_00000000593ca76a00000000558b3083->object_00000000593cb6ac00000000558b3083 + + +value - - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7e2000000001569f266 - - -11 - - - -object_00000000234bb7ed000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb6ad00000000558b3083 + + +Innmind\Neo4j\ONM\Entity\DataExtractor\RelationshipExtractor - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7ed000000001569f266 - - -12 +object_00000000593ca75700000000558b3083->object_00000000593cb6ad00000000558b3083 + + +value - - -object_00000000234bb7ec000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb69500000000558b3083 + + +Innmind\Reflection\ExtractionStrategy\ReflectionStrategy - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7ec000000001569f266 - - -13 + + +object_00000000593cb6ac00000000558b3083->object_00000000593cb69500000000558b3083 + + +extractionStrategy - - -object_00000000234bb7ef000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb6ae00000000558b3083 + + +Innmind\Reflection\ExtractionStrategy\ReflectionStrategy - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7ef000000001569f266 - - -14 - - - -object_00000000234bb7ee000000001569f266 - - -Innmind\Immutable\Pair - + + +object_00000000593cb6ad00000000558b3083->object_00000000593cb6ae00000000558b3083 + + +extractionStrategy + + +object_00000000593cb76400000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7ee000000001569f266 - - -15 +object_00000000593cb76400000000558b3083->object_00000000593cb77100000000558b3083 + + +changeset - - -object_00000000234bb7e9000000001569f266 - - -Innmind\Immutable\Pair - - - - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7e9000000001569f266 - - -16 - - - -object_00000000234bb7e8000000001569f266 - - -Innmind\Immutable\Pair - - +object_00000000593cb76400000000558b3083->object_00000000593cb6db00000000558b3083 + + +dispatch - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7e8000000001569f266 - - -17 +object_00000000593cb76400000000558b3083->object_00000000593cb77a00000000558b3083 + + +extract - - -object_00000000234bb7eb000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7eb000000001569f266 - - -18 - - - -object_00000000234bb7ea000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76700000000558b3083 + + +Innmind\Immutable\Str - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7ea000000001569f266 - - -19 - - - -object_00000000234bb7d5000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7d5000000001569f266 - - -20 - - - -object_00000000234bb7d4000000001569f266 - - -Innmind\Immutable\Pair - +object_00000000593cb76400000000558b3083->object_00000000593cb76700000000558b3083 + + +name + + +object_00000000593cb76600000000558b3083->object_00000000593cb68f00000000558b3083 + + +metadata - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7d4000000001569f266 - - -21 +object_00000000593cb76600000000558b3083->object_00000000593cb77100000000558b3083 + + +changeset - - -object_00000000234bb7d7000000001569f266 - - -Innmind\Immutable\Pair - - - - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7d7000000001569f266 - - -22 - - - -object_00000000234bb7d6000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7d6000000001569f266 - - -23 +object_00000000593cb76600000000558b3083->object_00000000593cb6db00000000558b3083 + + +dispatch - - -object_00000000234bb7d1000000001569f266 - - -Innmind\Immutable\Pair + + +object_00000000593cb76900000000558b3083 + + +Innmind\Immutable\Str - + -object_00000000234bb7d3000000001569f266->object_00000000234bb7d1000000001569f266 - - -24 - - - -object_00000000234bb7d0000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb7d3000000001569f266->object_00000000234bb7d0000000001569f266 - - -25 +object_00000000593cb76600000000558b3083->object_00000000593cb76900000000558b3083 + + +name - - -object_00000000234bbfc3000000001569f266 - - -Innmind\Http\Factory\Header\AcceptCharsetFactory + + +object_00000000593ca40300000000558b3083 + + +ArrayObject - - -object_00000000234bb7f5000000001569f266->object_00000000234bbfc3000000001569f266 - - -value + + +object_00000000593cb73f00000000558b3083->object_00000000593ca40300000000558b3083 + + +translators - - -object_00000000234bbfc0000000001569f266 - - -Innmind\Http\Factory\Header\AcceptEncodingFactory + + +object_00000000593ca57200000000558b3083 + + +ArrayObject - - -object_00000000234bb7f2000000001569f266->object_00000000234bbfc0000000001569f266 - - -value + + +object_00000000593cb73e00000000558b3083->object_00000000593ca57200000000558b3083 + + +translators - - -object_00000000234bbfc9000000001569f266 - - -Innmind\Http\Factory\Header\AcceptFactory + + +object_00000000593cb72100000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\Validator\DelegationValidator - - -object_00000000234bb7fd000000001569f266->object_00000000234bbfc9000000001569f266 - - -value + + +object_00000000593cb73e00000000558b3083->object_00000000593cb72100000000558b3083 + + +validate - - -object_00000000234bbfc2000000001569f266 - - -Innmind\Http\Factory\Header\AcceptLanguageFactory + + +object_00000000593ca40e00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7f3000000001569f266->object_00000000234bbfc2000000001569f266 - - -value +object_00000000593ca40300000000558b3083->object_00000000593ca40e00000000558b3083 + + +0 - - -object_00000000234bbfc8000000001569f266 - - -Innmind\Http\Factory\Header\AcceptRangesFactory + + +object_00000000593ca40800000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7f7000000001569f266->object_00000000234bbfc8000000001569f266 - - -value +object_00000000593ca40300000000558b3083->object_00000000593ca40800000000558b3083 + + +1 - - -object_00000000234bbfcb000000001569f266 - - -Innmind\Http\Factory\Header\AgeFactory + + +object_00000000593cb6bc00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Match\AggregateTranslator - + -object_00000000234bb80a000000001569f266->object_00000000234bbfcb000000001569f266 - - -value +object_00000000593ca40e00000000558b3083->object_00000000593cb6bc00000000558b3083 + + +value - - -object_00000000234bbfca000000001569f266 - - -Innmind\Http\Factory\Header\AllowFactory + + +object_00000000593cb6bd00000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Match\RelationshipTranslator - + -object_00000000234bb7f0000000001569f266->object_00000000234bbfca000000001569f266 - - -value - - - -object_00000000234bbfb5000000001569f266 - - -Innmind\Http\Factory\Header\AuthorizationFactory - - - - - -object_00000000234bb7e6000000001569f266->object_00000000234bbfb5000000001569f266 - - -value - - - -object_00000000234bbfb4000000001569f266 - - -Innmind\Http\Factory\Header\CacheControlFactory - - - - - -object_00000000234bb7e1000000001569f266->object_00000000234bbfb4000000001569f266 - - -value +object_00000000593ca40800000000558b3083->object_00000000593cb6bd00000000558b3083 + + +value - - -object_00000000234bbfb7000000001569f266 - - -Innmind\Http\Factory\Header\ContentEncodingFactory + + +object_00000000593ca49d00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7e0000000001569f266->object_00000000234bbfb7000000001569f266 - - -value +object_00000000593ca57200000000558b3083->object_00000000593ca49d00000000558b3083 + + +0 - - -object_00000000234bbfb6000000001569f266 - - -Innmind\Http\Factory\Header\ContentLanguageFactory + + +object_00000000593ca48c00000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7e3000000001569f266->object_00000000234bbfb6000000001569f266 - - -value +object_00000000593ca57200000000558b3083->object_00000000593ca48c00000000558b3083 + + +1 - - -object_00000000234bbfb1000000001569f266 - - -Innmind\Http\Factory\Header\ContentLengthFactory + + +object_00000000593ca5f700000000558b3083 + + +ArrayObject - - -object_00000000234bb7e2000000001569f266->object_00000000234bbfb1000000001569f266 - - -value + + +object_00000000593cb72100000000558b3083->object_00000000593ca5f700000000558b3083 + + +validators - - -object_00000000234bbfb0000000001569f266 - - -Innmind\Http\Factory\Header\ContentLocationFactory + + +object_00000000593cb6a400000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\AggregateTranslator - - -object_00000000234bb7ed000000001569f266->object_00000000234bbfb0000000001569f266 - - -value + + +object_00000000593ca49d00000000558b3083->object_00000000593cb6a400000000558b3083 + + +value - - -object_00000000234bbfb3000000001569f266 - - -Innmind\Http\Factory\Header\ContentRangeFactory + + +object_00000000593cb6a500000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\RelationshipTranslator - - -object_00000000234bb7ec000000001569f266->object_00000000234bbfb3000000001569f266 - - -value + + +object_00000000593ca48c00000000558b3083->object_00000000593cb6a500000000558b3083 + + +value - - -object_00000000234bbfb2000000001569f266 - - -Innmind\Http\Factory\Header\ContentTypeFactory + + +object_00000000593ca5f800000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7ef000000001569f266->object_00000000234bbfb2000000001569f266 - - -value +object_00000000593ca5f700000000558b3083->object_00000000593ca5f800000000558b3083 + + +0 - - -object_00000000234bbfbd000000001569f266 - - -Innmind\Http\Factory\Header\DateFactory + + +object_00000000593ca5f900000000558b3083 + + +Innmind\Immutable\Pair - + -object_00000000234bb7ee000000001569f266->object_00000000234bbfbd000000001569f266 - - -value +object_00000000593ca5f700000000558b3083->object_00000000593ca5f900000000558b3083 + + +1 - - -object_00000000234bbfbc000000001569f266 - - -Innmind\Http\Factory\Header\ExpiresFactory + + +object_00000000593cb72300000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\Validator\AggregateValidator - + -object_00000000234bb7e9000000001569f266->object_00000000234bbfbc000000001569f266 - - -value +object_00000000593ca5f800000000558b3083->object_00000000593cb72300000000558b3083 + + +value - - -object_00000000234bbfbf000000001569f266 - - -Innmind\Http\Factory\Header\HostFactory + + +object_00000000593cb72000000000558b3083 + + +Innmind\Neo4j\ONM\Translation\Specification\Validator\RelationshipValidator - + -object_00000000234bb7e8000000001569f266->object_00000000234bbfbf000000001569f266 - - -value - - - -object_00000000234bbfbe000000001569f266 - - -Innmind\Http\Factory\Header\IfModifiedSinceFactory - - - - - -object_00000000234bb7eb000000001569f266->object_00000000234bbfbe000000001569f266 - - -value - - - -object_00000000234bbfb9000000001569f266 - - -Innmind\Http\Factory\Header\IfUnmodifiedSinceFactory - - - - - -object_00000000234bb7ea000000001569f266->object_00000000234bbfb9000000001569f266 - - -value - - - -object_00000000234bbfb8000000001569f266 - - -Innmind\Http\Factory\Header\LastModifiedFactory - - - - - -object_00000000234bb7d5000000001569f266->object_00000000234bbfb8000000001569f266 - - -value - - - -object_00000000234bbfbb000000001569f266 - - -Innmind\Http\Factory\Header\LinkFactory - - - - - -object_00000000234bb7d4000000001569f266->object_00000000234bbfbb000000001569f266 - - -value - - - -object_00000000234bbfba000000001569f266 - - -Innmind\Http\Factory\Header\LocationFactory - - - - - -object_00000000234bb7d7000000001569f266->object_00000000234bbfba000000001569f266 - - -value - - - -object_00000000234bbfa5000000001569f266 - - -Innmind\Http\Factory\Header\RangeFactory - - - - - -object_00000000234bb7d6000000001569f266->object_00000000234bbfa5000000001569f266 - - -value - - - -object_00000000234bbfa4000000001569f266 - - -Innmind\Http\Factory\Header\ReferrerFactory - - - - - -object_00000000234bb7d1000000001569f266->object_00000000234bbfa4000000001569f266 - - -value - - - -object_00000000234bbfa7000000001569f266 - - -Innmind\Http\Factory\Header\CookieFactory - - - - - -object_00000000234bb7d0000000001569f266->object_00000000234bbfa7000000001569f266 - - -value - - - -object_00000000234bbfa9000000001569f266 - - -Innmind\Stream\Stream\Stream - - - - - -object_00000000234bbf8c000000001569f266->object_00000000234bbfa9000000001569f266 - - -stream - - - -object_00000000234bbf76000000001569f266 - - -Innmind\Stream\Stream\Size - - - - - -object_00000000234bbfa9000000001569f266->object_00000000234bbf76000000001569f266 - - -size - - - -object_00000000234bbdd5000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bbddc000000001569f266->object_00000000234bbdd5000000001569f266 - - -0 - - - -object_00000000234bbd51000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bbddc000000001569f266->object_00000000234bbd51000000001569f266 - - -1 - - - -object_00000000234bbd56000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bbddc000000001569f266->object_00000000234bbd56000000001569f266 - - -2 - - - -object_00000000234bbd46000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bbddc000000001569f266->object_00000000234bbd46000000001569f266 - - -3 - - - -object_00000000234bbeee000000001569f266 - - -Innmind\Neo4j\ONM\Entity\Container\State - - - - - -object_00000000234bbdd5000000001569f266->object_00000000234bbeee000000001569f266 - - -key - - - -object_00000000234bbeef000000001569f266 - - -Innmind\Neo4j\ONM\Entity\Container\State - - - - - -object_00000000234bbd51000000001569f266->object_00000000234bbeef000000001569f266 - - -key - - - -object_00000000234bbed6000000001569f266 - - -Innmind\Neo4j\ONM\Entity\Container\State - - - - - -object_00000000234bbd56000000001569f266->object_00000000234bbed6000000001569f266 - - -key - - - -object_00000000234bbed4000000001569f266 - - -Innmind\Neo4j\ONM\Entity\Container\State - - - - - -object_00000000234bbd46000000001569f266->object_00000000234bbed4000000001569f266 - - -key - - - -object_00000000234bbeee000000001569f266->object_00000000234bbeee000000001569f266 - - -managed - - - -object_00000000234bbeee000000001569f266->object_00000000234bbeef000000001569f266 - - -new - - - -object_00000000234bbeee000000001569f266->object_00000000234bbed6000000001569f266 - - -toBeRemoved - - - -object_00000000234bbeee000000001569f266->object_00000000234bbed4000000001569f266 - - -removed - - - -object_00000000234bbeef000000001569f266->object_00000000234bbeee000000001569f266 - - -managed - - - -object_00000000234bbeef000000001569f266->object_00000000234bbeef000000001569f266 - - -new - - - -object_00000000234bbeef000000001569f266->object_00000000234bbed6000000001569f266 - - -toBeRemoved - - - -object_00000000234bbeef000000001569f266->object_00000000234bbed4000000001569f266 - - -removed - - - -object_00000000234bbed6000000001569f266->object_00000000234bbeee000000001569f266 - - -managed - - - -object_00000000234bbed6000000001569f266->object_00000000234bbeef000000001569f266 - - -new - - - -object_00000000234bbed6000000001569f266->object_00000000234bbed6000000001569f266 - - -toBeRemoved - - - -object_00000000234bbed6000000001569f266->object_00000000234bbed4000000001569f266 - - -removed - - - -object_00000000234bbed4000000001569f266->object_00000000234bbeee000000001569f266 - - -managed - - - -object_00000000234bbed4000000001569f266->object_00000000234bbeef000000001569f266 - - -new - - - -object_00000000234bbed4000000001569f266->object_00000000234bbed6000000001569f266 - - -toBeRemoved - - - -object_00000000234bbed4000000001569f266->object_00000000234bbed4000000001569f266 - - -removed - - - -object_00000000234bb1d8000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbece000000001569f266->object_00000000234bb1d8000000001569f266 - - -translators - - - -object_00000000234bb0fe000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbeb1000000001569f266->object_00000000234bb0fe000000001569f266 - - -mapping - - - -object_00000000234bb1eb000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb1d8000000001569f266->object_00000000234bb1eb000000001569f266 - - -0 - - - -object_00000000234bb1d9000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb1d8000000001569f266->object_00000000234bb1d9000000001569f266 - - -1 - - - -object_00000000234bbf42000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Result\AggregateTranslator - - - - - -object_00000000234bb1eb000000001569f266->object_00000000234bbf42000000001569f266 - - -value - - - -object_00000000234bbf49000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Result\RelationshipTranslator - - - - - -object_00000000234bb1d9000000001569f266->object_00000000234bbf49000000001569f266 - - -value - - - -object_00000000234bb169000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb158000000001569f266->object_00000000234bb169000000001569f266 - - -0 - - - -object_00000000234bbf1a000000001569f266 - - -Innmind\Neo4j\ONM\Identity\Generator\UuidGenerator - - - - - -object_00000000234bb169000000001569f266->object_00000000234bbf1a000000001569f266 - - -value - - - -object_00000000234bb100000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb0fe000000001569f266->object_00000000234bb100000000001569f266 - - -0 - - - -object_00000000234bb0ec000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb0fe000000001569f266->object_00000000234bb0ec000000001569f266 - - -1 - - - -object_00000000234bbf13000000001569f266 - - -Innmind\Neo4j\ONM\EntityFactory\AggregateFactory - - - - - -object_00000000234bb100000000001569f266->object_00000000234bbf13000000001569f266 - - -value - - - -object_00000000234bbf1e000000001569f266 - - -Innmind\Neo4j\ONM\EntityFactory\RelationshipFactory - - - - - -object_00000000234bb0ec000000001569f266->object_00000000234bbf1e000000001569f266 - - -value - - - -object_00000000234bbf1f000000001569f266 - - -Innmind\Reflection\Instanciator\ConstructorLessInstanciator - - - - - -object_00000000234bbf13000000001569f266->object_00000000234bbf1f000000001569f266 - - -instanciator - - - -object_00000000234bbf19000000001569f266 - - -Innmind\Reflection\InjectionStrategy\ReflectionStrategy - - - - - -object_00000000234bbf13000000001569f266->object_00000000234bbf19000000001569f266 - - -injectionStrategy - - - -object_00000000234bbf1e000000001569f266->object_00000000234bbf10000000001569f266 - - -generators - - - -object_00000000234bbf1b000000001569f266 - - -Innmind\Reflection\Instanciator\ConstructorLessInstanciator - - - - - -object_00000000234bbf1e000000001569f266->object_00000000234bbf1b000000001569f266 - - -instanciator - - - -object_00000000234bbf18000000001569f266 - - -Innmind\Reflection\InjectionStrategy\ReflectionStrategy - - - - - -object_00000000234bbf1e000000001569f266->object_00000000234bbf18000000001569f266 - - -injectionStrategy - - - -object_00000000234bb17b000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb068000000001569f266->object_00000000234bb17b000000001569f266 - - -0 - - - -object_00000000234bb06f000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bb068000000001569f266->object_00000000234bb06f000000001569f266 - - -1 - - - -object_00000000234bbf30000000001569f266 - - -Innmind\Neo4j\ONM\Translation\IdentityMatch\AggregateTranslator - - - - - -object_00000000234bb17b000000001569f266->object_00000000234bbf30000000001569f266 - - -value - - - -object_00000000234bbf31000000001569f266 - - -Innmind\Neo4j\ONM\Translation\IdentityMatch\RelationshipTranslator - - - - - -object_00000000234bb06f000000001569f266->object_00000000234bbf31000000001569f266 - - -value - - - -object_00000000234bafa7000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234baf86000000001569f266->object_00000000234bafa7000000001569f266 - - -0 - - - -object_00000000234baf94000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234baf86000000001569f266->object_00000000234baf94000000001569f266 - - -1 - - - -object_00000000234baf82000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234baf86000000001569f266->object_00000000234baf82000000001569f266 - - -2 - - - -object_00000000234bbee6000000001569f266 - - -Innmind\Neo4j\ONM\Persister\InsertPersister - - - - - -object_00000000234bafa7000000001569f266->object_00000000234bbee6000000001569f266 - - -value - - - -object_00000000234bbee0000000001569f266 - - -Innmind\Neo4j\ONM\Persister\UpdatePersister - - - - - -object_00000000234baf94000000001569f266->object_00000000234bbee0000000001569f266 - - -value - - - -object_00000000234bbee2000000001569f266 - - -Innmind\Neo4j\ONM\Persister\RemovePersister - - - - - -object_00000000234baf82000000001569f266->object_00000000234bbee2000000001569f266 - - -value - - - -object_00000000234bbee6000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata - - - -object_00000000234bbef5000000001569f266 - - -Innmind\Neo4j\ONM\Entity\ChangesetComputer - - - - - -object_00000000234bbee6000000001569f266->object_00000000234bbef5000000001569f266 - - -changeset - - - -object_00000000234bbf5f000000001569f266 - - -Innmind\EventBus\EventBus\NullEventBus - - - - - -object_00000000234bbee6000000001569f266->object_00000000234bbf5f000000001569f266 - - -dispatch - - - -object_00000000234bbefe000000001569f266 - - -Innmind\Neo4j\ONM\Entity\DataExtractor\DataExtractor - - - - - -object_00000000234bbee6000000001569f266->object_00000000234bbefe000000001569f266 - - -extract - - - -object_00000000234bbee1000000001569f266 - - -Innmind\Immutable\Str - - - - - -object_00000000234bbee6000000001569f266->object_00000000234bbee1000000001569f266 - - -name - - - -object_00000000234bbefe000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata - - - -object_00000000234baed8000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbefe000000001569f266->object_00000000234baed8000000001569f266 - - -extractors - - - -object_00000000234baeeb000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234baed8000000001569f266->object_00000000234baeeb000000001569f266 - - -0 - - - -object_00000000234baedc000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234baed8000000001569f266->object_00000000234baedc000000001569f266 - - -1 - - - -object_00000000234bbf28000000001569f266 - - -Innmind\Neo4j\ONM\Entity\DataExtractor\AggregateExtractor - - - - - -object_00000000234baeeb000000001569f266->object_00000000234bbf28000000001569f266 - - -value - - - -object_00000000234bbf29000000001569f266 - - -Innmind\Neo4j\ONM\Entity\DataExtractor\RelationshipExtractor - - - - - -object_00000000234baedc000000001569f266->object_00000000234bbf29000000001569f266 - - -value - - - -object_00000000234bbf11000000001569f266 - - -Innmind\Reflection\ExtractionStrategy\ReflectionStrategy - - - - - -object_00000000234bbf28000000001569f266->object_00000000234bbf11000000001569f266 - - -extractionStrategy - - - -object_00000000234bbf2a000000001569f266 - - -Innmind\Reflection\ExtractionStrategy\ReflectionStrategy - - - - - -object_00000000234bbf29000000001569f266->object_00000000234bbf2a000000001569f266 - - -extractionStrategy - - - -object_00000000234bbee0000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata - - - -object_00000000234bbee0000000001569f266->object_00000000234bbef5000000001569f266 - - -changeset - - - -object_00000000234bbee0000000001569f266->object_00000000234bbf5f000000001569f266 - - -dispatch - - - -object_00000000234bbee0000000001569f266->object_00000000234bbefe000000001569f266 - - -extract - - - -object_00000000234bbee3000000001569f266 - - -Innmind\Immutable\Str - - - - - -object_00000000234bbee0000000001569f266->object_00000000234bbee3000000001569f266 - - -name - - - -object_00000000234bbee2000000001569f266->object_00000000234bbf0b000000001569f266 - - -metadata - - - -object_00000000234bbee2000000001569f266->object_00000000234bbef5000000001569f266 - - -changeset - - - -object_00000000234bbee2000000001569f266->object_00000000234bbf5f000000001569f266 - - -dispatch - - - -object_00000000234bbeed000000001569f266 - - -Innmind\Immutable\Str - - - - - -object_00000000234bbee2000000001569f266->object_00000000234bbeed000000001569f266 - - -name - - - -object_00000000234bad80000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbebb000000001569f266->object_00000000234bad80000000001569f266 - - -translators - - - -object_00000000234bacf3000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbeba000000001569f266->object_00000000234bacf3000000001569f266 - - -translators - - - -object_00000000234bbea5000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\Validator\DelegationValidator - - - - - -object_00000000234bbeba000000001569f266->object_00000000234bbea5000000001569f266 - - -validate - - - -object_00000000234bad77000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bad80000000001569f266->object_00000000234bad77000000001569f266 - - -0 - - - -object_00000000234bad89000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bad80000000001569f266->object_00000000234bad89000000001569f266 - - -1 - - - -object_00000000234bbf38000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Match\AggregateTranslator - - - - - -object_00000000234bad77000000001569f266->object_00000000234bbf38000000001569f266 - - -value - - - -object_00000000234bbf39000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Match\RelationshipTranslator - - - - - -object_00000000234bad89000000001569f266->object_00000000234bbf39000000001569f266 - - -value - - - -object_00000000234bad1a000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bacf3000000001569f266->object_00000000234bad1a000000001569f266 - - -0 - - - -object_00000000234bacf5000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bacf3000000001569f266->object_00000000234bacf5000000001569f266 - - -1 - - - -object_00000000234bac7c000000001569f266 - - -ArrayObject - - - - - -object_00000000234bbea5000000001569f266->object_00000000234bac7c000000001569f266 - - -validators - - - -object_00000000234bbf20000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\AggregateTranslator - - - - - -object_00000000234bad1a000000001569f266->object_00000000234bbf20000000001569f266 - - -value - - - -object_00000000234bbf21000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\RelationshipTranslator - - - - - -object_00000000234bacf5000000001569f266->object_00000000234bbf21000000001569f266 - - -value - - - -object_00000000234bac79000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bac7c000000001569f266->object_00000000234bac79000000001569f266 - - -0 - - - -object_00000000234bac7e000000001569f266 - - -Innmind\Immutable\Pair - - - - - -object_00000000234bac7c000000001569f266->object_00000000234bac7e000000001569f266 - - -1 - - - -object_00000000234bbea7000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\Validator\AggregateValidator - - - - - -object_00000000234bac79000000001569f266->object_00000000234bbea7000000001569f266 - - -value - - - -object_00000000234bbea4000000001569f266 - - -Innmind\Neo4j\ONM\Translation\Specification\Validator\RelationshipValidator - - - - - -object_00000000234bac7e000000001569f266->object_00000000234bbea4000000001569f266 - - -value +object_00000000593ca5f900000000558b3083->object_00000000593cb72000000000558b3083 + + +value From 40825d49944deeac917d34e527dd42d4f2a6068a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 11:15:28 +0100 Subject: [PATCH 02/17] add docker compose to boot a neo4j database --- docker-compose.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fc2d370 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '2' +services: + neo4j: + image: neo4j:3.4 + ports: + - '7474:7474' + - '7687:7687' From 347380ad366e06027ff9eaa4bb4f6c4a372722df Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 11:15:49 +0100 Subject: [PATCH 03/17] remove useless script --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index f4259e9..d473e2e 100644 --- a/composer.json +++ b/composer.json @@ -43,9 +43,6 @@ "innmind/object-graph": "^1.2", "innmind/server-control": "^2.7" }, - "scripts": { - "test": "vendor/bin/phpunit --colors=always" - }, "suggest": { "innmind/time-continuum": "To be able to use point_in_time type", "innmind/command-bus": "To dispatch entities domain events" From f3f5abfcf65748fe10078e43e28bb20f49912891 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 11:22:33 +0100 Subject: [PATCH 04/17] update to phpunit 8 --- .gitignore | 1 + composer.json | 2 +- tests/BootstrapTest.php | 8 ++++---- tests/Entity/ChangesetComputerTest.php | 2 +- tests/Entity/DataExtractor/AggregateExtractorTest.php | 2 +- tests/Entity/DataExtractor/DataExtractorTest.php | 2 +- tests/Entity/DataExtractor/RelationshipExtractorTest.php | 2 +- tests/EntityFactory/EntityFactoryTest.php | 2 +- tests/Metadata/ClassNameTest.php | 3 --- tests/Persister/InsertPersisterTest.php | 2 +- tests/Persister/RemovePersisterTest.php | 2 +- tests/Persister/UpdatePersisterTest.php | 2 +- tests/Repository/RepositoryTest.php | 2 +- tests/RepositoryFactoryTest.php | 2 +- tests/Translation/Result/AggregateTranslatorTest.php | 2 +- .../Translation/Specification/AggregateTranslatorTest.php | 2 +- .../Specification/RelationshipTranslatorTest.php | 2 +- .../Specification/Validator/DelegationValidatorTest.php | 2 +- .../Specification/Visitor/Cypher/AggregateVisitorTest.php | 2 +- .../Visitor/Cypher/RelationshipVisitorTest.php | 2 +- .../Visitor/PropertyMatch/AggregateVisitorTest.php | 2 +- .../Visitor/PropertyMatch/RelationshipVisitorTest.php | 2 +- tests/UnitOfWorkTest.php | 2 +- 23 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 86a02ea..ff1f8cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor cache +.phpunit.result.cache diff --git a/composer.json b/composer.json index d473e2e..e3119d0 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ } }, "require-dev": { - "phpunit/phpunit": "~7.0", + "phpunit/phpunit": "~8.0", "innmind/time-continuum": "^1.0", "innmind/command-bus": "^3.0", "innmind/cli": "^1.5", diff --git a/tests/BootstrapTest.php b/tests/BootstrapTest.php index 3d00dbc..701269d 100644 --- a/tests/BootstrapTest.php +++ b/tests/BootstrapTest.php @@ -30,22 +30,22 @@ public function testBootstrap() $this->assertInstanceOf(Manager::class, $services['manager']); $bus = $this->createMock(CommandBus::class); - $this->assertInternalType('callable', $services['command_bus']['clear_domain_events']); + $this->assertIsCallable($services['command_bus']['clear_domain_events']); $this->assertInstanceOf( ClearDomainEvents::class, $services['command_bus']['clear_domain_events']($bus) ); - $this->assertInternalType('callable', $services['command_bus']['dispatch_domain_events']); + $this->assertIsCallable($services['command_bus']['dispatch_domain_events']); $this->assertInstanceOf( DispatchDomainEvents::class, $services['command_bus']['dispatch_domain_events']($bus) ); - $this->assertInternalType('callable', $services['command_bus']['flush']); + $this->assertIsCallable($services['command_bus']['flush']); $this->assertInstanceOf( Flush::class, $services['command_bus']['flush']($bus) ); - $this->assertInternalType('callable', $services['command_bus']['transaction']); + $this->assertIsCallable($services['command_bus']['transaction']); $this->assertInstanceOf( Transaction::class, $services['command_bus']['transaction']($bus) diff --git a/tests/Entity/ChangesetComputerTest.php b/tests/Entity/ChangesetComputerTest.php index 903b1ce..7bf77a2 100644 --- a/tests/Entity/ChangesetComputerTest.php +++ b/tests/Entity/ChangesetComputerTest.php @@ -17,7 +17,7 @@ class ChangesetComputerTest extends TestCase { private $computer; - public function setUp() + public function setUp(): void { $this->computer = new ChangesetComputer; } diff --git a/tests/Entity/DataExtractor/AggregateExtractorTest.php b/tests/Entity/DataExtractor/AggregateExtractorTest.php index cd737d7..7109259 100644 --- a/tests/Entity/DataExtractor/AggregateExtractorTest.php +++ b/tests/Entity/DataExtractor/AggregateExtractorTest.php @@ -30,7 +30,7 @@ class AggregateExtractorTest extends TestCase private $extract; private $meta; - public function setUp() + public function setUp(): void { $this->extract = new AggregateExtractor; $this->meta = Aggregate::of( diff --git a/tests/Entity/DataExtractor/DataExtractorTest.php b/tests/Entity/DataExtractor/DataExtractorTest.php index aa7a377..2fec8d5 100644 --- a/tests/Entity/DataExtractor/DataExtractorTest.php +++ b/tests/Entity/DataExtractor/DataExtractorTest.php @@ -33,7 +33,7 @@ class DataExtractorTest extends TestCase private $relationshipClass; private $metadatas; - public function setUp() + public function setUp(): void { $aggregateRoot = new class { public $uuid; diff --git a/tests/Entity/DataExtractor/RelationshipExtractorTest.php b/tests/Entity/DataExtractor/RelationshipExtractorTest.php index fb5540e..8581df1 100644 --- a/tests/Entity/DataExtractor/RelationshipExtractorTest.php +++ b/tests/Entity/DataExtractor/RelationshipExtractorTest.php @@ -29,7 +29,7 @@ class RelationshipExtractorTest extends TestCase private $extract; private $meta; - public function setUp() + public function setUp(): void { $this->extract = new RelationshipExtractor; $this->meta = Relationship::of( diff --git a/tests/EntityFactory/EntityFactoryTest.php b/tests/EntityFactory/EntityFactoryTest.php index 848dff3..5343dd5 100644 --- a/tests/EntityFactory/EntityFactoryTest.php +++ b/tests/EntityFactory/EntityFactoryTest.php @@ -39,7 +39,7 @@ class EntityFactoryTest extends TestCase { private $make; - public function setUp() + public function setUp(): void { $this->make = new EntityFactory( new ResultTranslator, diff --git a/tests/Metadata/ClassNameTest.php b/tests/Metadata/ClassNameTest.php index 90c6ab3..afe4b65 100644 --- a/tests/Metadata/ClassNameTest.php +++ b/tests/Metadata/ClassNameTest.php @@ -18,9 +18,6 @@ public function testInterface() $this->assertSame('Class\Name\Space', (string) $className); } - /** - * @expectedException Innmind\Neo4j\ONM\Exception\DomainException - */ public function testThrowWhenEmptyClass() { $this->expectException(DomainException::class); diff --git a/tests/Persister/InsertPersisterTest.php b/tests/Persister/InsertPersisterTest.php index b48079b..a3614ce 100644 --- a/tests/Persister/InsertPersisterTest.php +++ b/tests/Persister/InsertPersisterTest.php @@ -43,7 +43,7 @@ class InsertPersisterTest extends TestCase private $aggregateRootClass; private $relationshipClass; - public function setUp() + public function setUp(): void { $aggregateRoot = new class { public $uuid; diff --git a/tests/Persister/RemovePersisterTest.php b/tests/Persister/RemovePersisterTest.php index bad6a2a..5e8bfc0 100644 --- a/tests/Persister/RemovePersisterTest.php +++ b/tests/Persister/RemovePersisterTest.php @@ -36,7 +36,7 @@ class RemovePersisterTest extends TestCase private $aggregateRootClass; private $relationshipClass; - public function setUp() + public function setUp(): void { $aggregateRoot = new class { public $uuid; diff --git a/tests/Persister/UpdatePersisterTest.php b/tests/Persister/UpdatePersisterTest.php index 0247c52..e62032d 100644 --- a/tests/Persister/UpdatePersisterTest.php +++ b/tests/Persister/UpdatePersisterTest.php @@ -44,7 +44,7 @@ class UpdatePersisterTest extends TestCase private $aggregateRootClass; private $relationshipClass; - public function setUp() + public function setUp(): void { $aggregateRoot = new class { public $uuid; diff --git a/tests/Repository/RepositoryTest.php b/tests/Repository/RepositoryTest.php index 0ab911a..7027eba 100644 --- a/tests/Repository/RepositoryTest.php +++ b/tests/Repository/RepositoryTest.php @@ -55,7 +55,7 @@ class RepositoryTest extends TestCase private $class; private $uow; - public function setUp() + public function setUp(): void { $entity = new class { public $uuid; diff --git a/tests/RepositoryFactoryTest.php b/tests/RepositoryFactoryTest.php index f5c14c5..a6ec17f 100644 --- a/tests/RepositoryFactoryTest.php +++ b/tests/RepositoryFactoryTest.php @@ -28,7 +28,7 @@ class RepositoryFactoryTest extends TestCase { private $make; - public function setUp() + public function setUp(): void { $this->make = new RepositoryFactory( new UnitOfWork( diff --git a/tests/Translation/Result/AggregateTranslatorTest.php b/tests/Translation/Result/AggregateTranslatorTest.php index d071623..2975520 100644 --- a/tests/Translation/Result/AggregateTranslatorTest.php +++ b/tests/Translation/Result/AggregateTranslatorTest.php @@ -36,7 +36,7 @@ class AggregateTranslatorTest extends TestCase private $translate; private $meta; - public function setUp() + public function setUp(): void { $this->translate = new AggregateTranslator; $this->meta = Aggregate::of( diff --git a/tests/Translation/Specification/AggregateTranslatorTest.php b/tests/Translation/Specification/AggregateTranslatorTest.php index 24f49bf..18ae8e6 100644 --- a/tests/Translation/Specification/AggregateTranslatorTest.php +++ b/tests/Translation/Specification/AggregateTranslatorTest.php @@ -29,7 +29,7 @@ class AggregateTranslatorTest extends TestCase { private $meta; - public function setUp() + public function setUp(): void { $this->meta = Aggregate::of( new ClassName('FQCN'), diff --git a/tests/Translation/Specification/RelationshipTranslatorTest.php b/tests/Translation/Specification/RelationshipTranslatorTest.php index 6896e49..7da3fbf 100644 --- a/tests/Translation/Specification/RelationshipTranslatorTest.php +++ b/tests/Translation/Specification/RelationshipTranslatorTest.php @@ -29,7 +29,7 @@ class RelationshipTranslatorTest extends TestCase { private $meta; - public function setUp() + public function setUp(): void { $this->meta = Relationship::of( new ClassName('foo'), diff --git a/tests/Translation/Specification/Validator/DelegationValidatorTest.php b/tests/Translation/Specification/Validator/DelegationValidatorTest.php index 45295f4..5e33faf 100644 --- a/tests/Translation/Specification/Validator/DelegationValidatorTest.php +++ b/tests/Translation/Specification/Validator/DelegationValidatorTest.php @@ -31,7 +31,7 @@ class DelegationValidatorTest extends TestCase private $aggregate; private $relationship; - public function setUp() + public function setUp(): void { $this->aggregate = Aggregate::of( new ClassName('FQCN'), diff --git a/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php b/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php index 1557281..95b372d 100644 --- a/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php +++ b/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php @@ -27,7 +27,7 @@ class AggregateVisitorTest extends TestCase { private $visitor; - public function setUp() + public function setUp(): void { $this->visitor = new AggregateVisitor( Aggregate::of( diff --git a/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php b/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php index c4f3918..9ab69c1 100644 --- a/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php +++ b/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php @@ -29,7 +29,7 @@ class RelationshipVisitorTest extends TestCase { private $visitor; - public function setUp() + public function setUp(): void { $this->visitor = new RelationshipVisitor( Relationship::of( diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php index 4a4c99c..e00d6cd 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php @@ -30,7 +30,7 @@ class AggregateVisitorTest extends TestCase { private $visitor; - public function setUp() + public function setUp(): void { $this->visitor = new AggregateVisitor( Aggregate::of( diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php index 19f961f..7a3210e 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php @@ -32,7 +32,7 @@ class RelationshipVisitorTest extends TestCase { private $visitor; - public function setUp() + public function setUp(): void { $this->visitor = new RelationshipVisitor( Relationship::of( diff --git a/tests/UnitOfWorkTest.php b/tests/UnitOfWorkTest.php index e3a7386..8b51d4f 100644 --- a/tests/UnitOfWorkTest.php +++ b/tests/UnitOfWorkTest.php @@ -55,7 +55,7 @@ class UnitOfWorkTest extends TestCase private $metadata; private $generators; - public function setUp() + public function setUp(): void { $entity = new class { public $uuid; From ead688d5d5bec60e29d2b16eb56f5f7c92e73ca0 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 11:43:03 +0100 Subject: [PATCH 05/17] require php 7.4 --- composer.json | 2 +- src/CommandBus/ClearDomainEvents.php | 4 ++-- src/CommandBus/DispatchDomainEvents.php | 6 +++--- src/CommandBus/Flush.php | 4 ++-- src/CommandBus/Transaction.php | 5 +++-- src/Entity/ChangesetComputer.php | 2 +- src/Entity/Container.php | 2 +- src/Entity/Container/State.php | 18 +++++++++--------- .../DataExtractor/AggregateExtractor.php | 2 +- src/Entity/DataExtractor/DataExtractor.php | 4 ++-- .../DataExtractor/RelationshipExtractor.php | 2 +- src/EntityFactory/AggregateFactory.php | 4 ++-- src/EntityFactory/EntityFactory.php | 8 ++++---- src/EntityFactory/RelationshipFactory.php | 6 +++--- src/EntityFactory/Resolver.php | 2 +- src/Event/EntityAboutToBePersisted.php | 4 ++-- src/Event/EntityAboutToBeRemoved.php | 4 ++-- src/Event/EntityAboutToBeUpdated.php | 6 +++--- src/Event/EntityPersisted.php | 4 ++-- src/Event/EntityRemoved.php | 4 ++-- src/Event/EntityUpdated.php | 6 +++--- src/Exception/MoreThanOneRelationshipFound.php | 4 ++-- src/Identity/Generator/UuidGenerator.php | 2 +- src/Identity/Generators.php | 2 +- src/Identity/Uuid.php | 2 +- src/IdentityMatch.php | 4 ++-- src/Manager/Manager.php | 8 ++++---- src/Metadata/Aggregate.php | 14 +++++++------- src/Metadata/Aggregate/Child.php | 8 ++++---- src/Metadata/Aggregate/Child/Relationship.php | 10 +++++----- src/Metadata/ClassName.php | 2 +- src/Metadata/Factory.php | 2 +- src/Metadata/Identity.php | 4 ++-- src/Metadata/Property.php | 4 ++-- src/Metadata/Relationship.php | 16 ++++++++-------- src/Metadata/RelationshipEdge.php | 2 +- src/Metadata/RelationshipType.php | 2 +- src/Metadata/Repository.php | 2 +- src/Metadatas.php | 2 +- src/Persister/DelegationPersister.php | 2 +- src/Persister/InsertPersister.php | 12 ++++++------ src/Persister/RemovePersister.php | 10 +++++----- src/Persister/UpdatePersister.php | 12 ++++++------ src/Query/PropertiesMatch.php | 4 ++-- src/Query/Where.php | 4 ++-- src/Repository/Repository.php | 10 +++++----- src/RepositoryFactory.php | 8 ++++---- .../IdentityMatch/DelegationTranslator.php | 2 +- src/Translation/Match/DelegationTranslator.php | 2 +- src/Translation/ResultTranslator.php | 2 +- .../Specification/DelegationTranslator.php | 4 ++-- .../Validator/DelegationValidator.php | 2 +- .../Visitor/Cypher/AggregateVisitor.php | 6 +++--- .../Visitor/Cypher/RelationshipVisitor.php | 6 +++--- .../Visitor/PropertyMatch/AggregateVisitor.php | 2 +- .../PropertyMatch/RelationshipVisitor.php | 2 +- src/Type/ArrayType.php | 4 ++-- src/Type/BooleanType.php | 2 +- src/Type/DateType.php | 6 +++--- src/Type/FloatType.php | 2 +- src/Type/IntType.php | 2 +- src/Type/PointInTimeType.php | 4 ++-- src/Type/SetType.php | 6 +++--- src/Type/StringType.php | 2 +- src/UnitOfWork.php | 14 +++++++------- 65 files changed, 161 insertions(+), 160 deletions(-) diff --git a/composer.json b/composer.json index e3119d0..b1a25f5 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "issues": "http://github.com/Innmind/neo4j-onm/issues" }, "require": { - "php": "~7.2", + "php": "~7.4", "innmind/neo4j-dbal": "~5.0", "innmind/immutable": "~2.10", "ramsey/uuid": "^3.2", diff --git a/src/CommandBus/ClearDomainEvents.php b/src/CommandBus/ClearDomainEvents.php index a59d6ed..f68b0a2 100644 --- a/src/CommandBus/ClearDomainEvents.php +++ b/src/CommandBus/ClearDomainEvents.php @@ -13,8 +13,8 @@ final class ClearDomainEvents implements CommandBus { - private $handle; - private $entities; + private CommandBus $handle; + private Container $entities; public function __construct(CommandBus $handle, Container $entities) { diff --git a/src/CommandBus/DispatchDomainEvents.php b/src/CommandBus/DispatchDomainEvents.php index 96b712a..fceb952 100644 --- a/src/CommandBus/DispatchDomainEvents.php +++ b/src/CommandBus/DispatchDomainEvents.php @@ -20,9 +20,9 @@ final class DispatchDomainEvents implements CommandBus { - private $handle; - private $dispatch; - private $entities; + private CommandBus $handle; + private EventBus $dispatch; + private Container $entities; public function __construct( CommandBus $handle, diff --git a/src/CommandBus/Flush.php b/src/CommandBus/Flush.php index f9ece8e..339dd1c 100644 --- a/src/CommandBus/Flush.php +++ b/src/CommandBus/Flush.php @@ -8,8 +8,8 @@ final class Flush implements CommandBus { - private $handle; - private $manager; + private CommandBus $handle; + private Manager $manager; public function __construct(CommandBus $handle, Manager $manager) { diff --git a/src/CommandBus/Transaction.php b/src/CommandBus/Transaction.php index a808a16..8841961 100644 --- a/src/CommandBus/Transaction.php +++ b/src/CommandBus/Transaction.php @@ -4,12 +4,13 @@ namespace Innmind\Neo4j\ONM\CommandBus; use Innmind\Neo4j\ONM\Manager; +use Innmind\Neo4j\DBAL\Connection; use Innmind\CommandBus\CommandBus; final class Transaction implements CommandBus { - private $handle; - private $connection; + private CommandBus $handle; + private Connection $connection; public function __construct(CommandBus $handle, Manager $manager) { diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index c7951f5..b5be0ee 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -14,7 +14,7 @@ final class ChangesetComputer { - private $sources; + private Map $sources; public function __construct() { diff --git a/src/Entity/Container.php b/src/Entity/Container.php index eb7ca4f..adec37d 100644 --- a/src/Entity/Container.php +++ b/src/Entity/Container.php @@ -16,7 +16,7 @@ final class Container { - private $states; + private Map $states; public function __construct() { diff --git a/src/Entity/Container/State.php b/src/Entity/Container/State.php index 9564c42..c430428 100644 --- a/src/Entity/Container/State.php +++ b/src/Entity/Container/State.php @@ -10,12 +10,12 @@ final class State private const TO_BE_REMOVED = 3; private const REMOVED = 4; - private static $managed; - private static $new; - private static $toBeRemoved; - private static $removed; + private static ?self $managed = null; + private static ?self $new = null; + private static ?self $toBeRemoved = null; + private static ?self $removed = null; - private $value; + private int $value; private function __construct(int $value) { @@ -24,18 +24,18 @@ private function __construct(int $value) public static function managed(): self { - return self::$managed ?? self::$managed = new self(self::MANAGED); + return self::$managed ??= new self(self::MANAGED); } public static function new(): self { - return self::$new ?? self::$new = new self(self::NEW); + return self::$new ??= new self(self::NEW); } public static function toBeRemoved(): self { - return self::$toBeRemoved ?? self::$toBeRemoved = new self(self::TO_BE_REMOVED); + return self::$toBeRemoved ??= new self(self::TO_BE_REMOVED); } public static function removed(): self { - return self::$removed ?? self::$removed = new self(self::REMOVED); + return self::$removed ??= new self(self::REMOVED); } } diff --git a/src/Entity/DataExtractor/AggregateExtractor.php b/src/Entity/DataExtractor/AggregateExtractor.php index 350f3da..411e14a 100644 --- a/src/Entity/DataExtractor/AggregateExtractor.php +++ b/src/Entity/DataExtractor/AggregateExtractor.php @@ -22,7 +22,7 @@ final class AggregateExtractor implements DataExtractorInterface { - private $extractionStrategy; + private ReflectionStrategy $extractionStrategy; public function __construct() { diff --git a/src/Entity/DataExtractor/DataExtractor.php b/src/Entity/DataExtractor/DataExtractor.php index 3a3d092..a7b934b 100644 --- a/src/Entity/DataExtractor/DataExtractor.php +++ b/src/Entity/DataExtractor/DataExtractor.php @@ -16,8 +16,8 @@ final class DataExtractor { - private $metadata; - private $extractors; + private Metadatas $metadata; + private Map $extractors; public function __construct( Metadatas $metadata, diff --git a/src/Entity/DataExtractor/RelationshipExtractor.php b/src/Entity/DataExtractor/RelationshipExtractor.php index 6dda354..6b74952 100644 --- a/src/Entity/DataExtractor/RelationshipExtractor.php +++ b/src/Entity/DataExtractor/RelationshipExtractor.php @@ -18,7 +18,7 @@ final class RelationshipExtractor implements DataExtractorInterface { - private $extractionStrategy; + private ReflectionStrategy $extractionStrategy; public function __construct() { diff --git a/src/EntityFactory/AggregateFactory.php b/src/EntityFactory/AggregateFactory.php index a16e2e1..9011b5d 100644 --- a/src/EntityFactory/AggregateFactory.php +++ b/src/EntityFactory/AggregateFactory.php @@ -24,8 +24,8 @@ final class AggregateFactory implements EntityFactoryInterface { - private $instanciator; - private $injectionStrategy; + private ConstructorLessInstanciator $instanciator; + private ReflectionStrategy $injectionStrategy; public function __construct() { diff --git a/src/EntityFactory/EntityFactory.php b/src/EntityFactory/EntityFactory.php index 6c37245..c304acb 100644 --- a/src/EntityFactory/EntityFactory.php +++ b/src/EntityFactory/EntityFactory.php @@ -20,10 +20,10 @@ final class EntityFactory { - private $translate; - private $generators; - private $resolve; - private $entities; + private ResultTranslator $translate; + private Generators $generators; + private Resolver $resolve; + private Container $entities; public function __construct( ResultTranslator $translate, diff --git a/src/EntityFactory/RelationshipFactory.php b/src/EntityFactory/RelationshipFactory.php index 4c8f74d..4875169 100644 --- a/src/EntityFactory/RelationshipFactory.php +++ b/src/EntityFactory/RelationshipFactory.php @@ -21,9 +21,9 @@ final class RelationshipFactory implements EntityFactoryInterface { - private $generators; - private $instanciator; - private $injectionStrategy; + private Generators $generators; + private ConstructorLessInstanciator $instanciator; + private ReflectionStrategy $injectionStrategy; public function __construct(Generators $generators) { diff --git a/src/EntityFactory/Resolver.php b/src/EntityFactory/Resolver.php index 29c8ce8..33b3fd0 100644 --- a/src/EntityFactory/Resolver.php +++ b/src/EntityFactory/Resolver.php @@ -11,7 +11,7 @@ final class Resolver { - private $mapping; + private Map $mapping; public function __construct(EntityFactoryInterface ...$factories) { diff --git a/src/Event/EntityAboutToBePersisted.php b/src/Event/EntityAboutToBePersisted.php index 583114c..17104f2 100644 --- a/src/Event/EntityAboutToBePersisted.php +++ b/src/Event/EntityAboutToBePersisted.php @@ -7,8 +7,8 @@ final class EntityAboutToBePersisted { - private $identity; - private $entity; + private Identity $identity; + private object $entity; public function __construct(Identity $identity, object $entity) { diff --git a/src/Event/EntityAboutToBeRemoved.php b/src/Event/EntityAboutToBeRemoved.php index 084fa62..04501c0 100644 --- a/src/Event/EntityAboutToBeRemoved.php +++ b/src/Event/EntityAboutToBeRemoved.php @@ -7,8 +7,8 @@ final class EntityAboutToBeRemoved { - private $identity; - private $entity; + private Identity $identity; + private object $entity; public function __construct(Identity $identity, object $entity) { diff --git a/src/Event/EntityAboutToBeUpdated.php b/src/Event/EntityAboutToBeUpdated.php index 44c7db8..e41254e 100644 --- a/src/Event/EntityAboutToBeUpdated.php +++ b/src/Event/EntityAboutToBeUpdated.php @@ -8,9 +8,9 @@ final class EntityAboutToBeUpdated { - private $identity; - private $entity; - private $changeset; + private Identity $identity; + private object $entity; + private MapInterface $changeset; public function __construct( Identity $identity, diff --git a/src/Event/EntityPersisted.php b/src/Event/EntityPersisted.php index dd181d4..b539252 100644 --- a/src/Event/EntityPersisted.php +++ b/src/Event/EntityPersisted.php @@ -7,8 +7,8 @@ final class EntityPersisted { - private $identity; - private $entity; + private Identity $identity; + private object $entity; public function __construct(Identity $identity, object $entity) { diff --git a/src/Event/EntityRemoved.php b/src/Event/EntityRemoved.php index e654c02..a455f6a 100644 --- a/src/Event/EntityRemoved.php +++ b/src/Event/EntityRemoved.php @@ -7,8 +7,8 @@ final class EntityRemoved { - private $identity; - private $entity; + private Identity $identity; + private object $entity; public function __construct(Identity $identity, object $entity) { diff --git a/src/Event/EntityUpdated.php b/src/Event/EntityUpdated.php index 095dce6..56d641b 100644 --- a/src/Event/EntityUpdated.php +++ b/src/Event/EntityUpdated.php @@ -8,9 +8,9 @@ final class EntityUpdated { - private $identity; - private $entity; - private $changeset; + private Identity $identity; + private object $entity; + private MapInterface $changeset; public function __construct( Identity $identity, diff --git a/src/Exception/MoreThanOneRelationshipFound.php b/src/Exception/MoreThanOneRelationshipFound.php index 513f80f..d00417c 100644 --- a/src/Exception/MoreThanOneRelationshipFound.php +++ b/src/Exception/MoreThanOneRelationshipFound.php @@ -10,8 +10,8 @@ final class MoreThanOneRelationshipFound extends RuntimeException { - private $child; - private $entity; + private Child $child; + private Entity $entity; public static function for(Child $child): self { diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 003e829..98b4f2f 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -17,7 +17,7 @@ final class UuidGenerator implements Generator { - private $identities; + private Map $identities; public function __construct(string $type = Uuid::class) { diff --git a/src/Identity/Generators.php b/src/Identity/Generators.php index 01f6c9a..d487c94 100644 --- a/src/Identity/Generators.php +++ b/src/Identity/Generators.php @@ -11,7 +11,7 @@ final class Generators { - private $mapping; + private MapInterface $mapping; public function __construct(MapInterface $mapping = null) { diff --git a/src/Identity/Uuid.php b/src/Identity/Uuid.php index 64cba20..2d6242a 100644 --- a/src/Identity/Uuid.php +++ b/src/Identity/Uuid.php @@ -13,7 +13,7 @@ class Uuid implements Identity { const PATTERN = '/^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/'; - private $value; + private string $value; public function __construct(string $uuid) { diff --git a/src/IdentityMatch.php b/src/IdentityMatch.php index a95d4e7..e669b4b 100644 --- a/src/IdentityMatch.php +++ b/src/IdentityMatch.php @@ -9,8 +9,8 @@ final class IdentityMatch { - private $query; - private $variables; + private Query $query; + private MapInterface $variables; public function __construct( Query $query, diff --git a/src/Manager/Manager.php b/src/Manager/Manager.php index 64cf32b..bd1e5f4 100644 --- a/src/Manager/Manager.php +++ b/src/Manager/Manager.php @@ -16,10 +16,10 @@ final class Manager implements ManagerInterface { - private $unitOfWork; - private $metadata; - private $make; - private $generators; + private UnitOfWork $unitOfWork; + private Metadatas $metadata; + private RepositoryFactory $make; + private Generators $generators; public function __construct( UnitOfWork $unitOfWork, diff --git a/src/Metadata/Aggregate.php b/src/Metadata/Aggregate.php index d430807..840ec0a 100644 --- a/src/Metadata/Aggregate.php +++ b/src/Metadata/Aggregate.php @@ -18,13 +18,13 @@ final class Aggregate implements Entity { - private $class; - private $identity; - private $repository; - private $factory; - private $properties; - private $labels; - private $children; + private ClassName $class; + private Identity $identity; + private Repository $repository; + private Factory $factory; + private Map $properties; + private SetInterface $labels; + private Map $children; public function __construct( ClassName $class, diff --git a/src/Metadata/Aggregate/Child.php b/src/Metadata/Aggregate/Child.php index 383b343..d24dac6 100644 --- a/src/Metadata/Aggregate/Child.php +++ b/src/Metadata/Aggregate/Child.php @@ -17,10 +17,10 @@ final class Child { - private $class; - private $labels; - private $relationship; - private $properties; + private ClassName $class; + private SetInterface $labels; + private Child\Relationship $relationship; + private MapInterface $properties; public function __construct( ClassName $class, diff --git a/src/Metadata/Aggregate/Child/Relationship.php b/src/Metadata/Aggregate/Child/Relationship.php index c8d9eec..a64cedf 100644 --- a/src/Metadata/Aggregate/Child/Relationship.php +++ b/src/Metadata/Aggregate/Child/Relationship.php @@ -20,11 +20,11 @@ final class Relationship { - private $class; - private $type; - private $property; - private $childProperty; - private $properties; + private ClassName $class; + private RelationshipType $type; + private string $property; + private string $childProperty; + private MapInterface $properties; public function __construct( ClassName $class, diff --git a/src/Metadata/ClassName.php b/src/Metadata/ClassName.php index f3875d7..804b65e 100644 --- a/src/Metadata/ClassName.php +++ b/src/Metadata/ClassName.php @@ -8,7 +8,7 @@ final class ClassName { - private $class; + private string $class; public function __construct(string $class) { diff --git a/src/Metadata/Factory.php b/src/Metadata/Factory.php index ba79a73..74151b8 100644 --- a/src/Metadata/Factory.php +++ b/src/Metadata/Factory.php @@ -11,7 +11,7 @@ */ final class Factory { - private $class; + private string $class; public function __construct(string $class) { diff --git a/src/Metadata/Identity.php b/src/Metadata/Identity.php index 919d7cc..e97b54d 100644 --- a/src/Metadata/Identity.php +++ b/src/Metadata/Identity.php @@ -11,8 +11,8 @@ */ class Identity { - private $property; - private $type; + private string $property; + private string $type; public function __construct(string $property, string $type) { diff --git a/src/Metadata/Property.php b/src/Metadata/Property.php index 5c0855e..647cf6c 100644 --- a/src/Metadata/Property.php +++ b/src/Metadata/Property.php @@ -11,8 +11,8 @@ final class Property { - private $name; - private $type; + private string $name; + private Type $type; public function __construct(string $name, Type $type) { diff --git a/src/Metadata/Relationship.php b/src/Metadata/Relationship.php index 3324658..8097410 100644 --- a/src/Metadata/Relationship.php +++ b/src/Metadata/Relationship.php @@ -17,14 +17,14 @@ final class Relationship implements Entity { - private $class; - private $identity; - private $repository; - private $factory; - private $type; - private $startNode; - private $endNode; - private $properties; + private ClassName $class; + private Identity $identity; + private Repository $repository; + private Factory $factory; + private RelationshipType $type; + private RelationshipEdge $startNode; + private RelationshipEdge $endNode; + private Map $properties; public function __construct( ClassName $class, diff --git a/src/Metadata/RelationshipEdge.php b/src/Metadata/RelationshipEdge.php index 80158d4..75bdb1f 100644 --- a/src/Metadata/RelationshipEdge.php +++ b/src/Metadata/RelationshipEdge.php @@ -8,7 +8,7 @@ final class RelationshipEdge extends Identity { - private $target; + private string $target; public function __construct(string $property, string $type, string $target) { diff --git a/src/Metadata/RelationshipType.php b/src/Metadata/RelationshipType.php index 4369bc8..3042083 100644 --- a/src/Metadata/RelationshipType.php +++ b/src/Metadata/RelationshipType.php @@ -8,7 +8,7 @@ final class RelationshipType { - private $type; + private string $type; public function __construct(string $type) { diff --git a/src/Metadata/Repository.php b/src/Metadata/Repository.php index 8ca5263..e3e9918 100644 --- a/src/Metadata/Repository.php +++ b/src/Metadata/Repository.php @@ -11,7 +11,7 @@ */ final class Repository { - private $class; + private string $class; public function __construct(string $class) { diff --git a/src/Metadatas.php b/src/Metadatas.php index 05a0198..7907b98 100644 --- a/src/Metadatas.php +++ b/src/Metadatas.php @@ -11,7 +11,7 @@ final class Metadatas { - private $mapping; + private Map $mapping; public function __construct(Entity ...$metas) { diff --git a/src/Persister/DelegationPersister.php b/src/Persister/DelegationPersister.php index 2bd653b..6509def 100644 --- a/src/Persister/DelegationPersister.php +++ b/src/Persister/DelegationPersister.php @@ -11,7 +11,7 @@ final class DelegationPersister implements Persister { - private $persisters; + private array $persisters; public function __construct(Persister ...$persisters) { diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index 8f2f792..cbce046 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -32,12 +32,12 @@ final class InsertPersister implements Persister { - private $changeset; - private $dispatch; - private $extract; - private $metadata; - private $name; - private $variables; + private ChangesetComputer $changeset; + private EventBus $dispatch; + private DataExtractor $extract; + private Metadatas $metadata; + private Str $name; + private ?Stream $variables = null; public function __construct( ChangesetComputer $changeset, diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 0213369..92cbd1e 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -30,11 +30,11 @@ final class RemovePersister implements Persister { - private $changeset; - private $dispatch; - private $metadata; - private $name; - private $variables; + private ChangesetComputer $changeset; + private EventBus $dispatch; + private Metadatas $metadata; + private Str $name; + private ?Stream $variables = null; public function __construct( ChangesetComputer $changeset, diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index 3e8d370..4d36bf9 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -30,12 +30,12 @@ final class UpdatePersister implements Persister { - private $changeset; - private $dispatch; - private $extract; - private $metadata; - private $name; - private $variables; + private ChangesetComputer $changeset; + private EventBus $dispatch; + private DataExtractor $extract; + private Metadatas $metadata; + private Str $name; + private ?Map $variables = null; public function __construct( ChangesetComputer $changeset, diff --git a/src/Query/PropertiesMatch.php b/src/Query/PropertiesMatch.php index 1d2032e..26efe0b 100644 --- a/src/Query/PropertiesMatch.php +++ b/src/Query/PropertiesMatch.php @@ -7,8 +7,8 @@ final class PropertiesMatch { - private $properties; - private $parameters; + private MapInterface $properties; + private MapInterface $parameters; public function __construct(MapInterface $properties, MapInterface $parameters) { diff --git a/src/Query/Where.php b/src/Query/Where.php index 52784e2..85aa5b0 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -11,8 +11,8 @@ final class Where { - private $cypher; - private $parameters; + private string $cypher; + private MapInterface $parameters; public function __construct(string $cypher, MapInterface $parameters) { diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 7f47b9a..958f196 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -21,11 +21,11 @@ final class Repository implements RepositoryInterface { - private $unitOfWork; - private $all; - private $matching; - private $metadata; - private $allowedStates; + private UnitOfWork $unitOfWork; + private MatchTranslator $all; + private SpecificationTranslator $matching; + private Entity $metadata; + private Set $allowedStates; public function __construct( UnitOfWork $unitOfWork, diff --git a/src/RepositoryFactory.php b/src/RepositoryFactory.php index 0b367fc..8d25e51 100644 --- a/src/RepositoryFactory.php +++ b/src/RepositoryFactory.php @@ -15,10 +15,10 @@ final class RepositoryFactory { - private $unitOfWork; - private $matchTranslator; - private $specificationTranslator; - private $repositories; + private UnitOfWork $unitOfWork; + private MatchTranslator $matchTranslator; + private SpecificationTranslator $specificationTranslator; + private MapInterface $repositories; public function __construct( UnitOfWork $unitOfWork, diff --git a/src/Translation/IdentityMatch/DelegationTranslator.php b/src/Translation/IdentityMatch/DelegationTranslator.php index 6928dff..e4fa00e 100644 --- a/src/Translation/IdentityMatch/DelegationTranslator.php +++ b/src/Translation/IdentityMatch/DelegationTranslator.php @@ -18,7 +18,7 @@ final class DelegationTranslator implements IdentityMatchTranslator { - private $translators; + private MapInterface $translators; public function __construct(MapInterface $translators = null) { diff --git a/src/Translation/Match/DelegationTranslator.php b/src/Translation/Match/DelegationTranslator.php index 4737636..0850f68 100644 --- a/src/Translation/Match/DelegationTranslator.php +++ b/src/Translation/Match/DelegationTranslator.php @@ -17,7 +17,7 @@ final class DelegationTranslator implements MatchTranslator { - private $translators; + private MapInterface $translators; public function __construct(MapInterface $translators = null) { diff --git a/src/Translation/ResultTranslator.php b/src/Translation/ResultTranslator.php index 4cb02d4..6987814 100644 --- a/src/Translation/ResultTranslator.php +++ b/src/Translation/ResultTranslator.php @@ -22,7 +22,7 @@ final class ResultTranslator { - private $translators; + private MapInterface $translators; public function __construct(MapInterface $translators = null) { diff --git a/src/Translation/Specification/DelegationTranslator.php b/src/Translation/Specification/DelegationTranslator.php index c0d8885..edf954b 100644 --- a/src/Translation/Specification/DelegationTranslator.php +++ b/src/Translation/Specification/DelegationTranslator.php @@ -19,8 +19,8 @@ final class DelegationTranslator implements SpecificationTranslator { - private $translators; - private $validate; + private MapInterface $translators; + private Validator $validate; public function __construct( MapInterface $translators = null, diff --git a/src/Translation/Specification/Validator/DelegationValidator.php b/src/Translation/Specification/Validator/DelegationValidator.php index 37c079e..7531dc8 100644 --- a/src/Translation/Specification/Validator/DelegationValidator.php +++ b/src/Translation/Specification/Validator/DelegationValidator.php @@ -17,7 +17,7 @@ final class DelegationValidator implements Validator { - private $validators; + private MapInterface $validators; public function __construct(MapInterface $validators = null) { diff --git a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php index c5744ac..a53a938 100644 --- a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php @@ -22,9 +22,9 @@ final class AggregateVisitor implements CypherVisitor { - private $meta; - private $convert; - private $count = 0; + private Aggregate $meta; + private ConvertSign $convert; + private int $count = 0; public function __construct(Aggregate $meta) { diff --git a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php index 151f347..91ed46a 100644 --- a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php @@ -25,9 +25,9 @@ final class RelationshipVisitor implements CypherVisitor { - private $meta; - private $convert; - private $count = 0; + private Relationship $meta; + private ConvertSign $convert; + private int $count = 0; public function __construct(Relationship $meta) { diff --git a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php index 06f7858..715c919 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php @@ -24,7 +24,7 @@ final class AggregateVisitor implements PropertyMatchVisitor { - private $meta; + private Aggregate $meta; public function __construct(Aggregate $meta) { diff --git a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php index 3b7ca50..be6c541 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php @@ -26,7 +26,7 @@ final class RelationshipVisitor implements PropertyMatchVisitor { - private $meta; + private Relationship $meta; public function __construct(Relationship $meta) { diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 70062ef..e50a293 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -10,8 +10,8 @@ final class ArrayType implements Type { - private $nullable = false; - private $inner; + private bool $nullable = false; + private Type $inner; public function __construct(Type $inner) { diff --git a/src/Type/BooleanType.php b/src/Type/BooleanType.php index dce15b0..1f0a96e 100644 --- a/src/Type/BooleanType.php +++ b/src/Type/BooleanType.php @@ -7,7 +7,7 @@ final class BooleanType implements Type { - private $nullable = false; + private bool $nullable = false; public static function nullable(): self { diff --git a/src/Type/DateType.php b/src/Type/DateType.php index 4205c6e..49d54ac 100644 --- a/src/Type/DateType.php +++ b/src/Type/DateType.php @@ -10,9 +10,9 @@ final class DateType implements Type { - private $format; - private $nullable = false; - private $immutable = true; + private string $format; + private bool $nullable = false; + private bool $immutable = true; public function __construct(string $format = null) { diff --git a/src/Type/FloatType.php b/src/Type/FloatType.php index 3c1f5b1..9fa42c2 100644 --- a/src/Type/FloatType.php +++ b/src/Type/FloatType.php @@ -7,7 +7,7 @@ final class FloatType implements Type { - private $nullable = false; + private bool $nullable = false; public static function nullable(): self { diff --git a/src/Type/IntType.php b/src/Type/IntType.php index f6e369b..742351d 100644 --- a/src/Type/IntType.php +++ b/src/Type/IntType.php @@ -7,7 +7,7 @@ final class IntType implements Type { - private $nullable = false; + private bool $nullable = false; public static function nullable(): self { diff --git a/src/Type/PointInTimeType.php b/src/Type/PointInTimeType.php index f42d17c..c24b829 100644 --- a/src/Type/PointInTimeType.php +++ b/src/Type/PointInTimeType.php @@ -16,8 +16,8 @@ final class PointInTimeType implements Type { - private $nullable = false; - private $format; + private bool $nullable = false; + private FormatInterface $format; public function __construct(FormatInterface $format = null) { diff --git a/src/Type/SetType.php b/src/Type/SetType.php index 5631fad..f40a0c9 100644 --- a/src/Type/SetType.php +++ b/src/Type/SetType.php @@ -15,9 +15,9 @@ final class SetType implements Type { - private $nullable = false; - private $inner; - private $type; + private bool $nullable = false; + private Type $inner; + private string $type; public function __construct(Type $inner, string $type) { diff --git a/src/Type/StringType.php b/src/Type/StringType.php index 935e4c4..160ccb7 100644 --- a/src/Type/StringType.php +++ b/src/Type/StringType.php @@ -7,7 +7,7 @@ final class StringType implements Type { - private $nullable = false; + private bool $nullable = false; public static function nullable(): self { diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index a3af554..80bd7de 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -24,13 +24,13 @@ final class UnitOfWork { - private $connection; - private $container; - private $makeEntity; - private $match; - private $metadata; - private $persist; - private $generators; + private Connection $connection; + private Container $container; + private EntityFactory $makeEntity; + private IdentityMatchTranslator $match; + private Metadatas $metadata; + private Persister $persist; + private Generators $generators; public function __construct( Connection $connection, From 8fa0f71cf699e40cf8e716b99806b4ffc5c27b35 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 13:04:38 +0100 Subject: [PATCH 06/17] update deps --- composer.json | 18 ++--- src/CommandBus/DispatchDomainEvents.php | 11 +-- src/Entity/ChangesetComputer.php | 31 ++++--- src/Entity/Container.php | 36 ++++++--- src/Entity/DataExtractor.php | 6 +- .../DataExtractor/AggregateExtractor.php | 25 +++--- src/Entity/DataExtractor/DataExtractor.php | 13 ++- .../DataExtractor/RelationshipExtractor.php | 6 +- src/EntityFactory.php | 6 +- src/EntityFactory/AggregateFactory.php | 12 +-- src/EntityFactory/EntityFactory.php | 24 +++--- src/EntityFactory/RelationshipFactory.php | 6 +- src/EntityFactory/Resolver.php | 2 +- src/Event/EntityAboutToBeUpdated.php | 10 +-- src/Event/EntityUpdated.php | 10 +-- src/Identity/Generator/UuidGenerator.php | 2 +- src/Identity/Generators.php | 11 +-- src/IdentityMatch.php | 12 +-- src/Metadata/Aggregate.php | 44 +++++----- src/Metadata/Aggregate/Child.php | 30 ++++--- src/Metadata/Aggregate/Child/Relationship.php | 18 ++--- src/Metadata/Entity.php | 6 +- src/Metadata/Relationship.php | 14 ++-- src/Metadatas.php | 7 +- src/Persister/InsertPersister.php | 79 +++++++++--------- src/Persister/RemovePersister.php | 57 ++++++------- src/Persister/UpdatePersister.php | 80 ++++++++++--------- src/Query/PropertiesMatch.php | 20 ++--- src/Query/Where.php | 12 +-- src/Repository.php | 10 +-- src/Repository/Repository.php | 9 +-- src/RepositoryFactory.php | 13 ++- src/Translation/EntityTranslator.php | 6 +- .../IdentityMatch/AggregateTranslator.php | 17 ++-- .../IdentityMatch/DelegationTranslator.php | 11 +-- src/Translation/Match/AggregateTranslator.php | 17 ++-- .../Match/DelegationTranslator.php | 11 +-- .../Result/AggregateTranslator.php | 33 ++++---- .../Result/RelationshipTranslator.php | 15 ++-- src/Translation/ResultTranslator.php | 23 +++--- .../Specification/AggregateTranslator.php | 38 ++++----- .../Specification/DelegationTranslator.php | 11 +-- .../Specification/RelationshipTranslator.php | 9 +-- .../Validator/AggregateValidator.php | 10 +-- .../Validator/DelegationValidator.php | 11 +-- .../Visitor/Cypher/AggregateVisitor.php | 28 ++++--- .../Visitor/Cypher/RelationshipVisitor.php | 11 ++- .../PropertyMatch/AggregateVisitor.php | 45 ++++++----- .../PropertyMatch/RelationshipVisitor.php | 26 +++--- .../Visitor/PropertyMatchVisitor.php | 6 +- src/Type/PointInTimeType.php | 14 ++-- src/Type/SetType.php | 11 +-- src/UnitOfWork.php | 15 ++-- src/bootstrap.php | 43 +++++----- tests/Entity/ChangesetComputerTest.php | 26 +++--- .../DataExtractor/AggregateExtractorTest.php | 14 ++-- .../DataExtractor/DataExtractorTest.php | 22 ++--- .../RelationshipExtractorTest.php | 10 +-- tests/EntityFactory/AggregateFactoryTest.php | 9 +-- tests/EntityFactory/EntityFactoryTest.php | 27 ++++--- .../EntityFactory/RelationshipFactoryTest.php | 14 +--- tests/Identity/GeneratorsTest.php | 10 +-- tests/IdentityMatchTest.php | 6 +- .../Aggregate/Child/RelationshipTest.php | 7 +- tests/Metadata/Aggregate/ChildTest.php | 9 +-- tests/Metadata/AggregateTest.php | 11 ++- tests/Query/PropertiesMatchTest.php | 24 +++--- tests/Query/WhereTest.php | 18 ++--- tests/Repository/RepositoryTest.php | 10 +-- tests/RepositoryFactoryTest.php | 8 +- .../IdentityMatch/AggregateTranslatorTest.php | 3 +- .../DelegationTranslatorTest.php | 9 +-- .../RelationshipTranslatorTest.php | 7 +- .../Match/AggregateTranslatorTest.php | 3 +- .../Match/DelegationTranslatorTest.php | 9 +-- .../Match/RelationshipTranslatorTest.php | 7 +- .../Result/AggregateTranslatorTest.php | 47 ++++++----- .../Result/RelationshipTranslatorTest.php | 40 +++++----- tests/Translation/ResultTranslatorTest.php | 72 +++++++++-------- .../DelegationTranslatorTest.php | 8 +- .../Validator/DelegationValidatorTest.php | 4 +- .../PropertyMatch/AggregateVisitorTest.php | 6 +- .../PropertyMatch/RelationshipVisitorTest.php | 10 +-- tests/Type/PointInTimeTypeTest.php | 8 +- tests/Type/SetTypeTest.php | 30 ++++--- tests/UnitOfWorkTest.php | 18 ++--- 86 files changed, 756 insertions(+), 801 deletions(-) diff --git a/composer.json b/composer.json index b1a25f5..dd21ab9 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ }, "require": { "php": "~7.4", - "innmind/neo4j-dbal": "~5.0", - "innmind/immutable": "~2.10", + "innmind/neo4j-dbal": "~6.0", + "innmind/immutable": "~3.5", "ramsey/uuid": "^3.2", - "innmind/reflection": "~3.0", + "innmind/reflection": "~4.0", "innmind/specification": "~2.0", - "innmind/event-bus": "~3.0" + "innmind/event-bus": "~4.0" }, "autoload": { "psr-4": { @@ -37,11 +37,11 @@ }, "require-dev": { "phpunit/phpunit": "~8.0", - "innmind/time-continuum": "^1.0", - "innmind/command-bus": "^3.0", - "innmind/cli": "^1.5", - "innmind/object-graph": "^1.2", - "innmind/server-control": "^2.7" + "innmind/time-continuum": "~2.0", + "innmind/command-bus": "~4.0", + "innmind/cli": "~2.0", + "innmind/object-graph": "~2.0", + "innmind/server-control": "~3.0" }, "suggest": { "innmind/time-continuum": "To be able to use point_in_time type", diff --git a/src/CommandBus/DispatchDomainEvents.php b/src/CommandBus/DispatchDomainEvents.php index fceb952..c8ffe28 100644 --- a/src/CommandBus/DispatchDomainEvents.php +++ b/src/CommandBus/DispatchDomainEvents.php @@ -13,10 +13,7 @@ EventBus, ContainsRecordedEvents, }; -use Innmind\Immutable\{ - StreamInterface, - Stream, -}; +use Innmind\Immutable\Sequence; final class DispatchDomainEvents implements CommandBus { @@ -47,12 +44,12 @@ public function __invoke(object $command): void return $entity instanceof ContainsRecordedEvents; }) ->reduce( - new Stream('object'), + Sequence::objects(), static function( - StreamInterface $carry, + Sequence $carry, Identity $identity, ContainsRecordedEvents $entity - ): StreamInterface { + ): Sequence { return $carry->append($entity->recordedEvents()); } ) diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index b5be0ee..3958ff1 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -7,10 +7,7 @@ Identity, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class ChangesetComputer { @@ -18,21 +15,21 @@ final class ChangesetComputer public function __construct() { - $this->sources = new Map(Identity::class, MapInterface::class); + $this->sources = Map::of(Identity::class, Map::class); } /** * Use the given collection as the original data for the given entity * - * @param MapInterface $source + * @param Map $source */ - public function use(Identity $identity, MapInterface $source): self + public function use(Identity $identity, Map $source): self { if ( (string) $source->keyType() !== 'string' || (string) $source->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 2 must be of type MapInterface'); + throw new \TypeError('Argument 2 must be of type Map'); } $this->sources = $this->sources->put($identity, $source); @@ -43,17 +40,17 @@ public function use(Identity $identity, MapInterface $source): self /** * Return the collection of data that has changed for the given identity * - * @param MapInterface $target + * @param Map $target * - * @return MapInterface + * @return Map */ - public function compute(Identity $identity, MapInterface $target): MapInterface + public function compute(Identity $identity, Map $target): Map { if ( (string) $target->keyType() !== 'string' || (string) $target->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 2 must be of type MapInterface'); + throw new \TypeError('Argument 2 must be of type Map'); } if (!$this->sources->contains($identity)) { @@ -66,9 +63,9 @@ public function compute(Identity $identity, MapInterface $target): MapInterface } private function diff( - MapInterface $source, - MapInterface $target - ): MapInterface { + Map $source, + Map $target + ): Map { $changeset = $target->filter(static function(string $property, $value) use ($source): bool { if ( !$source->contains($property) || @@ -91,7 +88,7 @@ static function(Map $carry, string $property) use ($target): Map { } ) ->map(function(string $property, $value) use ($source, $target) { - if (!$value instanceof MapInterface) { + if (!$value instanceof Map) { return $value; } @@ -101,7 +98,7 @@ static function(Map $carry, string $property) use ($target): Map { ); }) ->filter(static function(string $property, $value) { - if (!$value instanceof MapInterface) { + if (!$value instanceof Map) { return true; } diff --git a/src/Entity/Container.php b/src/Entity/Container.php index adec37d..96fb0c2 100644 --- a/src/Entity/Container.php +++ b/src/Entity/Container.php @@ -9,10 +9,7 @@ Exception\IdentityNotManaged, Exception\DomainException, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class Container { @@ -38,7 +35,7 @@ public function push(Identity $identity, object $entity, State $wished): self $this->states = $this->states->map(static function( State $state, - MapInterface $entities + Map $entities ) use ( $identity, $entity, @@ -57,9 +54,9 @@ public function push(Identity $identity, object $entity, State $wished): self /** * Return all the entities of a specific state * - * @return MapInterface + * @return Map */ - public function state(State $state): MapInterface + public function state(State $state): Map { return $this->states->get($state); } @@ -71,7 +68,7 @@ public function detach(Identity $identity): self { $this->states = $this->states->map(static function( State $state, - MapInterface $entities + Map $entities ) use ( $identity ) { @@ -88,13 +85,26 @@ public function detach(Identity $identity): self */ public function stateFor(Identity $identity): State { - foreach ($this->states as $state => $entities) { - if ($entities->contains($identity)) { - return $state; - } + $state = $this->states->reduce( + null, + static function(?State $current, State $state, Map $entities) use ($identity): ?State { + if ($current) { + return $current; + } + + if ($entities->contains($identity)) { + return $state; + } + + return null; + }, + ); + + if (!$state) { + throw new IdentityNotManaged; } - throw new IdentityNotManaged; + return $state; } /** diff --git a/src/Entity/DataExtractor.php b/src/Entity/DataExtractor.php index ea0ae2a..c589222 100644 --- a/src/Entity/DataExtractor.php +++ b/src/Entity/DataExtractor.php @@ -4,14 +4,14 @@ namespace Innmind\Neo4j\ONM\Entity; use Innmind\Neo4j\ONM\Metadata\Entity; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; interface DataExtractor { /** * Extract the data for the given entity * - * @return MapInterface + * @return Map */ - public function __invoke(object $entity, Entity $meta): MapInterface; + public function __invoke(object $entity, Entity $meta): Map; } diff --git a/src/Entity/DataExtractor/AggregateExtractor.php b/src/Entity/DataExtractor/AggregateExtractor.php index 411e14a..6b0db06 100644 --- a/src/Entity/DataExtractor/AggregateExtractor.php +++ b/src/Entity/DataExtractor/AggregateExtractor.php @@ -11,10 +11,7 @@ Metadata\Property, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use Innmind\Reflection\{ ReflectionObject, ExtractionStrategy\ReflectionStrategy, @@ -32,7 +29,7 @@ public function __construct() /** * {@inheritdoc} */ - public function __invoke(object $entity, Entity $meta): MapInterface + public function __invoke(object $entity, Entity $meta): Map { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException; @@ -53,7 +50,7 @@ public function __invoke(object $entity, Entity $meta): MapInterface ->children() ->reduce( $data, - function(MapInterface $carry, string $property, Child $child) use ($entity): MapInterface { + function(Map $carry, string $property, Child $child) use ($entity): Map { return $carry->put( $property, $this->extractRelationship( @@ -66,12 +63,12 @@ function(MapInterface $carry, string $property, Child $child) use ($entity): Map } /** - * @return MapInterface + * @return Map */ private function extractRelationship( Child $child, object $entity - ): MapInterface { + ): Map { $rel = $this ->reflection($entity) ->extract($property = $child->relationship()->property()) @@ -96,19 +93,19 @@ private function extractRelationship( } /** - * @param MapInterface $properties + * @param Map $properties * - * @return MapInterface + * @return Map */ private function extractProperties( object $object, - MapInterface $properties - ): MapInterface { + Map $properties + ): Map { $refl = $this->reflection($object); return $properties->reduce( - new Map('string', 'mixed'), - static function(MapInterface $carry, string $name, Property $property) use ($refl): MapInterface { + Map::of('string', 'mixed'), + static function(Map $carry, string $name, Property $property) use ($refl): Map { return $carry->put( $name, $property diff --git a/src/Entity/DataExtractor/DataExtractor.php b/src/Entity/DataExtractor/DataExtractor.php index a7b934b..582b57d 100644 --- a/src/Entity/DataExtractor/DataExtractor.php +++ b/src/Entity/DataExtractor/DataExtractor.php @@ -9,10 +9,7 @@ Metadata\Aggregate, Metadata\Relationship, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class DataExtractor { @@ -21,7 +18,7 @@ final class DataExtractor public function __construct( Metadatas $metadata, - MapInterface $extractors = null + Map $extractors = null ) { $this->metadata = $metadata; $this->extractors = $extractors ?? Map::of('string', DataExtractorInterface::class) @@ -33,7 +30,7 @@ public function __construct( (string) $this->extractors->valueType() !== DataExtractorInterface::class ) { throw new \TypeError(sprintf( - 'Argument 2 must be of type MapInterface', + 'Argument 2 must be of type Map', DataExtractorInterface::class )); } @@ -42,9 +39,9 @@ public function __construct( /** * Extract raw data from entity based on the defined mapping * - * @return MapInterface + * @return Map */ - public function __invoke(object $entity): MapInterface + public function __invoke(object $entity): Map { $meta = ($this->metadata)(get_class($entity)); $extract = $this->extractors->get(get_class($meta)); diff --git a/src/Entity/DataExtractor/RelationshipExtractor.php b/src/Entity/DataExtractor/RelationshipExtractor.php index 6b74952..1314d60 100644 --- a/src/Entity/DataExtractor/RelationshipExtractor.php +++ b/src/Entity/DataExtractor/RelationshipExtractor.php @@ -10,7 +10,7 @@ Metadata\Property, Exception\InvalidArgumentException, }; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; use Innmind\Reflection\{ ReflectionObject, ExtractionStrategy\ReflectionStrategy, @@ -28,7 +28,7 @@ public function __construct() /** * {@inheritdoc} */ - public function __invoke(object $entity, Entity $meta): MapInterface + public function __invoke(object $entity, Entity $meta): Map { if (!$meta instanceof Relationship) { throw new InvalidArgumentException; @@ -63,7 +63,7 @@ public function __invoke(object $entity, Entity $meta): MapInterface ->properties() ->reduce( $data, - static function(MapInterface $carry, string $name, Property $property) use ($refl): MapInterface { + static function(Map $carry, string $name, Property $property) use ($refl): Map { return $carry->put( $name, $property diff --git a/src/EntityFactory.php b/src/EntityFactory.php index d49ed5b..f033e96 100644 --- a/src/EntityFactory.php +++ b/src/EntityFactory.php @@ -4,18 +4,18 @@ namespace Innmind\Neo4j\ONM; use Innmind\Neo4j\ONM\Metadata\Entity; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; interface EntityFactory { /** * Make a new instance for the entity whien the given identity * - * @param MapInterface $data + * @param Map $data */ public function __invoke( Identity $identity, Entity $meta, - MapInterface $data + Map $data ): object; } diff --git a/src/EntityFactory/AggregateFactory.php b/src/EntityFactory/AggregateFactory.php index 9011b5d..bafe68e 100644 --- a/src/EntityFactory/AggregateFactory.php +++ b/src/EntityFactory/AggregateFactory.php @@ -13,7 +13,7 @@ Exception\InvalidArgumentException, }; use Innmind\Immutable\{ - MapInterface, + Map, Set, }; use Innmind\Reflection\{ @@ -39,7 +39,7 @@ public function __construct() public function __invoke( Identity $identity, Entity $meta, - MapInterface $data + Map $data ): object { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException; @@ -49,7 +49,7 @@ public function __invoke( (string) $data->keyType() !== 'string' || (string) $data->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 3 must be of type MapInterface'); + throw new \TypeError('Argument 3 must be of type Map'); } $reflection = $this @@ -97,7 +97,7 @@ function(ReflectionClass $carry, string $property, Child $meta) use ($data): Ref ->build(); } - private function buildChild(Child $meta, MapInterface $data) + private function buildChild(Child $meta, Map $data) { $relationship = $meta->relationship(); $data = $data->get($relationship->property()); @@ -107,7 +107,7 @@ private function buildChild(Child $meta, MapInterface $data) private function buildRelationship( Child $meta, - MapInterface $data + Map $data ) { $relationship = $meta->relationship(); @@ -148,7 +148,7 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ private function buildValueObject( Child $meta, - MapInterface $data + Map $data ): object { return $meta ->properties() diff --git a/src/EntityFactory/EntityFactory.php b/src/EntityFactory/EntityFactory.php index c304acb..75903a5 100644 --- a/src/EntityFactory/EntityFactory.php +++ b/src/EntityFactory/EntityFactory.php @@ -14,8 +14,6 @@ use Innmind\Immutable\{ Map, Set, - SetInterface, - MapInterface, }; final class EntityFactory @@ -40,39 +38,39 @@ public function __construct( /** * Translate the dbal result into a set of entities * - * @param MapInterface $variables + * @param Map $variables * - * @return SetInterface + * @return Set */ public function __invoke( Result $result, - MapInterface $variables - ): SetInterface { + Map $variables + ): Set { if ( (string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== Entity::class ) { throw new \TypeError(sprintf( - 'Argument 2 must be of type MapInterface', + 'Argument 2 must be of type Map', Entity::class )); } $structuredData = ($this->translate)($result, $variables); - $entities = new Set('object'); + $entities = Set::objects(); return $variables ->filter(static function(string $variable) use ($structuredData): bool { return $structuredData->contains($variable); }) ->reduce( - new Set('object'), - function(SetInterface $carry, string $variable, Entity $meta) use ($structuredData): SetInterface { + Set::objects(), + function(Set $carry, string $variable, Entity $meta) use ($structuredData): Set { return $structuredData ->get($variable) ->reduce( $carry, - function(SetInterface $carry, MapInterface $data) use ($meta): SetInterface { + function(Set $carry, Map $data) use ($meta): Set { return $carry->add( $this->makeEntity($meta, $data) ); @@ -83,9 +81,9 @@ function(SetInterface $carry, MapInterface $data) use ($meta): SetInterface { } /** - * @param MapInterface $data + * @param Map $data */ - private function makeEntity(Entity $meta, MapInterface $data) + private function makeEntity(Entity $meta, Map $data) { $identity = $this ->generators diff --git a/src/EntityFactory/RelationshipFactory.php b/src/EntityFactory/RelationshipFactory.php index 4875169..5def4c8 100644 --- a/src/EntityFactory/RelationshipFactory.php +++ b/src/EntityFactory/RelationshipFactory.php @@ -12,7 +12,7 @@ Identity\Generators, Exception\InvalidArgumentException, }; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; use Innmind\Reflection\{ ReflectionClass, Instanciator\ConstructorLessInstanciator, @@ -38,7 +38,7 @@ public function __construct(Generators $generators) public function __invoke( Identity $identity, Entity $meta, - MapInterface $data + Map $data ): object { if (!$meta instanceof Relationship) { throw new InvalidArgumentException; @@ -48,7 +48,7 @@ public function __invoke( (string) $data->keyType() !== 'string' || (string) $data->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 3 must be of type MapInterface'); + throw new \TypeError('Argument 3 must be of type Map'); } $reflection = ReflectionClass::of( diff --git a/src/EntityFactory/Resolver.php b/src/EntityFactory/Resolver.php index 33b3fd0..b918147 100644 --- a/src/EntityFactory/Resolver.php +++ b/src/EntityFactory/Resolver.php @@ -15,7 +15,7 @@ final class Resolver public function __construct(EntityFactoryInterface ...$factories) { - $this->mapping = new Map('string', EntityFactoryInterface::class); + $this->mapping = Map::of('string', EntityFactoryInterface::class); foreach ($factories as $factory) { $this->register($factory); diff --git a/src/Event/EntityAboutToBeUpdated.php b/src/Event/EntityAboutToBeUpdated.php index e41254e..5a45882 100644 --- a/src/Event/EntityAboutToBeUpdated.php +++ b/src/Event/EntityAboutToBeUpdated.php @@ -4,18 +4,18 @@ namespace Innmind\Neo4j\ONM\Event; use Innmind\Neo4j\ONM\Identity; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; final class EntityAboutToBeUpdated { private Identity $identity; private object $entity; - private MapInterface $changeset; + private Map $changeset; public function __construct( Identity $identity, object $entity, - MapInterface $changeset + Map $changeset ) { $this->identity = $identity; $this->entity = $entity; @@ -33,9 +33,9 @@ public function entity(): object } /** - * @return MapInterface + * @return Map */ - public function changeset(): MapInterface + public function changeset(): Map { return $this->changeset; } diff --git a/src/Event/EntityUpdated.php b/src/Event/EntityUpdated.php index 56d641b..e358f1c 100644 --- a/src/Event/EntityUpdated.php +++ b/src/Event/EntityUpdated.php @@ -4,18 +4,18 @@ namespace Innmind\Neo4j\ONM\Event; use Innmind\Neo4j\ONM\Identity; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; final class EntityUpdated { private Identity $identity; private object $entity; - private MapInterface $changeset; + private Map $changeset; public function __construct( Identity $identity, object $entity, - MapInterface $changeset + Map $changeset ) { $this->identity = $identity; $this->entity = $entity; @@ -33,9 +33,9 @@ public function entity(): object } /** - * @return MapInterface + * @return Map */ - public function changeset(): MapInterface + public function changeset(): Map { return $this->changeset; } diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 98b4f2f..705bc7c 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -25,7 +25,7 @@ public function __construct(string $type = Uuid::class) throw new DomainException; } - $this->identities = new Map('string', $type); + $this->identities = Map::of('string', $type); } /** diff --git a/src/Identity/Generators.php b/src/Identity/Generators.php index d487c94..629b6fc 100644 --- a/src/Identity/Generators.php +++ b/src/Identity/Generators.php @@ -4,18 +4,15 @@ namespace Innmind\Neo4j\ONM\Identity; use Innmind\Neo4j\ONM\Identity; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class Generators { - private MapInterface $mapping; + private Map $mapping; - public function __construct(MapInterface $mapping = null) + public function __construct(Map $mapping = null) { - $mapping = $mapping ?? new Map('string', Generator::class); + $mapping = $mapping ?? Map::of('string', Generator::class); $this->mapping = Map::of('string', Generator::class) (Uuid::class, new Generator\UuidGenerator) ->merge($mapping); diff --git a/src/IdentityMatch.php b/src/IdentityMatch.php index e669b4b..0128d49 100644 --- a/src/IdentityMatch.php +++ b/src/IdentityMatch.php @@ -5,23 +5,23 @@ use Innmind\Neo4j\ONM\Metadata\Entity; use Innmind\Neo4j\DBAL\Query; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; final class IdentityMatch { private Query $query; - private MapInterface $variables; + private Map $variables; public function __construct( Query $query, - MapInterface $variables + Map $variables ) { if ( (string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== Entity::class ) { throw new \TypeError(sprintf( - 'Argument 2 must be of type MapInterface', + 'Argument 2 must be of type Map', Entity::class )); } @@ -36,9 +36,9 @@ public function query(): Query } /** - * @return MapInterface + * @return Map */ - public function variables(): MapInterface + public function variables(): Map { return $this->variables; } diff --git a/src/Metadata/Aggregate.php b/src/Metadata/Aggregate.php index 840ec0a..f581860 100644 --- a/src/Metadata/Aggregate.php +++ b/src/Metadata/Aggregate.php @@ -10,9 +10,7 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; @@ -23,30 +21,30 @@ final class Aggregate implements Entity private Repository $repository; private Factory $factory; private Map $properties; - private SetInterface $labels; + private Set $labels; private Map $children; public function __construct( ClassName $class, Identity $identity, - SetInterface $labels, - SetInterface $properties, - SetInterface $children + Set $labels, + Set $properties, + Set $children ) { if ((string) $labels->type() !== 'string') { - throw new \TypeError('Argument 3 must be of type SetInterface'); + throw new \TypeError('Argument 3 must be of type Set'); } if ((string) $properties->type() !== Property::class) { throw new \TypeError(\sprintf( - 'Argument 4 must be of type SetInterface<%s>', + 'Argument 4 must be of type Set<%s>', Type::class )); } if ((string) $children->type() !== Child::class) { throw new \TypeError(\sprintf( - 'Argument 5 must be of type SetInterface<%s>', + 'Argument 5 must be of type Set<%s>', Child::class )); } @@ -57,14 +55,14 @@ public function __construct( $this->factory = new Factory(AggregateFactory::class); $this->properties = $properties->reduce( Map::of('string', Property::class), - static function(MapInterface $properties, Property $property): MapInterface { + static function(Map $properties, Property $property): Map { return $properties->put($property->name(), $property); } ); $this->labels = $labels; $this->children = $children->reduce( Map::of('string', Child::class), - static function(MapInterface $children, Child $child): MapInterface { + static function(Map $children, Child $child): Map { return $children->put( $child->relationship()->property(), $child @@ -74,16 +72,16 @@ static function(MapInterface $children, Child $child): MapInterface { } /** - * @param SetInterface $labels - * @param MapInterface $properties - * @param SetInterface $children + * @param Set $labels + * @param Map $properties + * @param Set $children */ public static function of( ClassName $class, Identity $identity, - SetInterface $labels, - MapInterface $properties = null, - SetInterface $children = null + Set $labels, + Map $properties = null, + Set $children = null ): self { return new self( $class, @@ -91,7 +89,7 @@ public static function of( $labels, ($properties ?? Map::of('string', Type::class))->reduce( Set::of(Property::class), - static function(SetInterface $properties, string $name, Type $type): SetInterface { + static function(Set $properties, string $name, Type $type): Set { return $properties->add(new Property($name, $type)); } ), @@ -126,7 +124,7 @@ public function factory(): Factory /** * {@inheritdoc} */ - public function properties(): MapInterface + public function properties(): Map { return $this->properties; } @@ -140,17 +138,17 @@ public function class(): ClassName } /** - * @return SetInterface + * @return Set */ - public function labels(): SetInterface + public function labels(): Set { return $this->labels; } /** - * @return MapInterface + * @return Map */ - public function children(): MapInterface + public function children(): Map { return $this->children; } diff --git a/src/Metadata/Aggregate/Child.php b/src/Metadata/Aggregate/Child.php index d24dac6..7a37f4a 100644 --- a/src/Metadata/Aggregate/Child.php +++ b/src/Metadata/Aggregate/Child.php @@ -9,32 +9,30 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; final class Child { private ClassName $class; - private SetInterface $labels; + private Set $labels; private Child\Relationship $relationship; - private MapInterface $properties; + private Map $properties; public function __construct( ClassName $class, - SetInterface $labels, + Set $labels, Child\Relationship $relationship, - SetInterface $properties + Set $properties ) { if ((string) $labels->type() !== 'string') { - throw new \TypeError('Argument 2 must be of type SetInterface'); + throw new \TypeError('Argument 2 must be of type Set'); } if ((string) $properties->type() !== Property::class) { throw new \TypeError(\sprintf( - 'Argument 4 must be of type SetInterface<%s>', + 'Argument 4 must be of type Set<%s>', Property::class )); } @@ -44,7 +42,7 @@ public function __construct( $this->relationship = $relationship; $this->properties = $properties->reduce( Map::of('string', Property::class), - static function(MapInterface $properties, Property $property): MapInterface { + static function(Map $properties, Property $property): Map { return $properties->put($property->name(), $property); } ); @@ -52,9 +50,9 @@ static function(MapInterface $properties, Property $property): MapInterface { public static function of( ClassName $class, - SetInterface $labels, + Set $labels, Child\Relationship $relationship, - MapInterface $properties = null + Map $properties = null ): self { return new self( $class, @@ -62,7 +60,7 @@ public static function of( $relationship, ($properties ?? Map::of('string', Type::class))->reduce( Set::of(Property::class), - static function(SetInterface $properties, string $property, Type $type): SetInterface { + static function(Set $properties, string $property, Type $type): Set { return $properties->add(new Property($property, $type)); } ) @@ -80,17 +78,17 @@ public function relationship(): Child\Relationship } /** - * @return SetInterface + * @return Set */ - public function labels(): SetInterface + public function labels(): Set { return $this->labels; } /** - * @return MapInterface + * @return Map */ - public function properties(): MapInterface + public function properties(): Map { return $this->properties; } diff --git a/src/Metadata/Aggregate/Child/Relationship.php b/src/Metadata/Aggregate/Child/Relationship.php index a64cedf..2e4e326 100644 --- a/src/Metadata/Aggregate/Child/Relationship.php +++ b/src/Metadata/Aggregate/Child/Relationship.php @@ -11,9 +11,7 @@ Exception\DomainException, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, Str, }; @@ -24,14 +22,14 @@ final class Relationship private RelationshipType $type; private string $property; private string $childProperty; - private MapInterface $properties; + private Map $properties; public function __construct( ClassName $class, RelationshipType $type, string $property, string $childProperty, - SetInterface $properties + Set $properties ) { if (Str::of($property)->empty() || Str::of($childProperty)->empty()) { throw new DomainException; @@ -39,7 +37,7 @@ public function __construct( if ((string) $properties->type() !== Property::class) { throw new \TypeError(\sprintf( - 'Argument 5 must be of type SetInterface<%s>', + 'Argument 5 must be of type Set<%s>', Property::class )); } @@ -50,7 +48,7 @@ public function __construct( $this->childProperty = $childProperty; $this->properties = $properties->reduce( Map::of('string', Property::class), - static function(MapInterface $properties, Property $property): MapInterface { + static function(Map $properties, Property $property): Map { return $properties->put($property->name(), $property); } ); @@ -61,7 +59,7 @@ public static function of( RelationshipType $type, string $property, string $childProperty, - MapInterface $properties = null + Map $properties = null ): self { return new self( $class, @@ -70,7 +68,7 @@ public static function of( $childProperty, ($properties ?? Map::of('string', Type::class))->reduce( Set::of(Property::class), - static function(SetInterface $properties, string $property, Type $type): SetInterface { + static function(Set $properties, string $property, Type $type): Set { return $properties->add(new Property($property, $type)); } ) @@ -101,9 +99,9 @@ public function childProperty(): string } /** - * @return MapInterface + * @return Map */ - public function properties(): MapInterface + public function properties(): Map { return $this->properties; } diff --git a/src/Metadata/Entity.php b/src/Metadata/Entity.php index 3d139b8..689688a 100644 --- a/src/Metadata/Entity.php +++ b/src/Metadata/Entity.php @@ -3,7 +3,7 @@ namespace Innmind\Neo4j\ONM\Metadata; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; interface Entity { @@ -25,9 +25,9 @@ public function identity(): Identity; /** * Return the list of properties defined for this entity * - * @return MapInterface + * @return Map */ - public function properties(): MapInterface; + public function properties(): Map; /** * Return the class name of the entity diff --git a/src/Metadata/Relationship.php b/src/Metadata/Relationship.php index 8097410..a4175f7 100644 --- a/src/Metadata/Relationship.php +++ b/src/Metadata/Relationship.php @@ -9,9 +9,7 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; @@ -32,11 +30,11 @@ public function __construct( RelationshipType $type, RelationshipEdge $startNode, RelationshipEdge $endNode, - SetInterface $properties + Set $properties ) { if ((string) $properties->type() !== Property::class) { throw new \TypeError(\sprintf( - 'Argument 6 must be of type SetInterface<%s>', + 'Argument 6 must be of type Set<%s>', Property::class )); } @@ -50,7 +48,7 @@ public function __construct( $this->endNode = $endNode; $this->properties = $properties->reduce( Map::of('string', Property::class), - static function(MapInterface $properties, Property $property): MapInterface { + static function(Map $properties, Property $property): Map { return $properties->put($property->name(), $property); } ); @@ -62,7 +60,7 @@ public static function of( RelationshipType $type, RelationshipEdge $startNode, RelationshipEdge $endNode, - MapInterface $properties = null + Map $properties = null ): self { return new self( $class, @@ -72,7 +70,7 @@ public static function of( $endNode, ($properties ?? Map::of('string', Type::class))->reduce( Set::of(Property::class), - static function(SetInterface $properties, string $property, Type $type): SetInterface { + static function(Set $properties, string $property, Type $type): Set { return $properties->add(new Property($property, $type)); } ) @@ -106,7 +104,7 @@ public function factory(): Factory /** * {@inheritdoc} */ - public function properties(): MapInterface + public function properties(): Map { return $this->properties; } diff --git a/src/Metadatas.php b/src/Metadatas.php index 7907b98..4fe780f 100644 --- a/src/Metadatas.php +++ b/src/Metadatas.php @@ -4,10 +4,7 @@ namespace Innmind\Neo4j\ONM; use Innmind\Neo4j\ONM\Metadata\Entity; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class Metadatas { @@ -15,7 +12,7 @@ final class Metadatas public function __construct(Entity ...$metas) { - $this->mapping = new Map('string', Entity::class); + $this->mapping = Map::of('string', Entity::class); foreach ($metas as $meta) { $this->register($meta); diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index cbce046..f84a30b 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -24,11 +24,11 @@ }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ - MapInterface, Map, - Stream, + Sequence, Str, }; +use function Innmind\Immutable\unwrap; final class InsertPersister implements Persister { @@ -37,7 +37,7 @@ final class InsertPersister implements Persister private DataExtractor $extract; private Metadatas $metadata; private Str $name; - private ?Stream $variables = null; + private ?Sequence $variables = null; public function __construct( ChangesetComputer $changeset, @@ -49,7 +49,7 @@ public function __construct( $this->dispatch = $dispatch; $this->extract = $extract; $this->metadata = $metadata; - $this->name = new Str('e%s'); + $this->name = Str::of('e%s'); } /** @@ -82,12 +82,12 @@ public function __invoke(Connection $connection, Container $container): void /** * Build the whole cypher query to insert at once all new nodes and relationships * - * @param MapInterface $entities + * @param Map $entities */ - private function queryFor(MapInterface $entities): Query + private function queryFor(Map $entities): Query { $query = new Query\Query; - $this->variables = new Stream('string'); + $this->variables = Sequence::strings(); $partitions = $entities->partition(function(Identity $identity, object $entity): bool { $meta = ($this->metadata)(\get_class($entity)); @@ -128,8 +128,8 @@ private function createAggregate( $varName = $this->name->sprintf(\md5($identity->value())); $query = $query->create( - (string) $varName, - $meta->labels()->toPrimitive() + $varName->toString(), + ...unwrap($meta->labels()), ); $paramKey = $varName->append('_props'); $properties = $this->buildProperties( @@ -141,10 +141,11 @@ private function createAggregate( $query = $query ->withProperty( $meta->identity()->property(), - (string) $paramKey + $paramKey ->prepend('{') ->append('}.') ->append($meta->identity()->property()) + ->toString() ) ->withProperties($properties->reduce( [], @@ -155,7 +156,7 @@ static function(array $carry, string $property, string $cypher): array { } )) ->withParameter( - (string) $paramKey, + $paramKey->toString(), $data ->filter(static function(string $key) use ($keysToKeep): bool { return $keysToKeep->contains($key); @@ -187,7 +188,7 @@ function(Query $carry, string $property, Child $child) use ($varName, $data): Qu ); } ); - $this->variables = $this->variables->add((string) $varName); + $this->variables = $this->variables->add($varName->toString()); return $query; } @@ -196,12 +197,12 @@ function(Query $carry, string $property, Child $child) use ($varName, $data): Qu * Add the cypher clause to build the relationship and the node corresponding * to a child of the aggregate * - * @param MapInterface $data + * @param Map $data */ private function createAggregateChild( Child $meta, Str $nodeName, - MapInterface $data, + Map $data, Query $query ): Query { $relationshipName = $nodeName @@ -220,10 +221,10 @@ private function createAggregateChild( ); return $query - ->create((string) $nodeName) + ->create($nodeName->toString()) ->linkedTo( - (string) $endNodeName, - $meta->labels()->toPrimitive() + $endNodeName->toString(), + ...unwrap($meta->labels()), ) ->withProperties($endNodeProperties->reduce( [], @@ -234,7 +235,7 @@ static function(array $carry, string $property, string $cypher): array { } )) ->withParameter( - (string) $endNodeParamKey, + $endNodeParamKey->toString(), $data ->get($meta->relationship()->childProperty()) ->reduce( @@ -248,7 +249,7 @@ static function(array $carry, string $key, $value): array { ) ->through( (string) $meta->relationship()->type(), - (string) $relationshipName, + $relationshipName->toString(), 'left' ) ->withProperties($relationshipProperties->reduce( @@ -260,7 +261,7 @@ static function(array $carry, string $property, string $cypher): array { } )) ->withParameter( - (string) $relationshipParamKey, + $relationshipParamKey->toString(), $data ->remove($meta->relationship()->childProperty()) ->reduce( @@ -277,22 +278,22 @@ static function(array $carry, string $key, $value): array { /** * Build the collection of properties to be injected in the query * - * @param MapInterface $properties + * @param Map $properties * - * @return MapInterface + * @return Map */ private function buildProperties( - MapInterface $properties, + Map $properties, Str $name - ): MapInterface { + ): Map { $name = $name->prepend('{')->append('}.'); return $properties->reduce( - new Map('string', 'string'), - static function(MapInterface $carry, string $property) use ($name): MapInterface { + Map::of('string', 'string'), + static function(Map $carry, string $property) use ($name): Map { return $carry->put( $property, - (string) $name->append($property) + $name->append($property)->toString(), ); } ); @@ -330,19 +331,20 @@ private function createRelationship( $query ) ) - ->create((string) $startName) - ->linkedTo((string) $endName) + ->create($startName->toString()) + ->linkedTo($endName->toString()) ->through( (string) $meta->type(), - (string) $varName, + $varName->toString(), 'right' ) ->withProperty( $meta->identity()->property(), - (string) $paramKey + $paramKey ->prepend('{') ->append('}.') ->append($meta->identity()->property()) + ->toString(), ) ->withProperties($properties->reduce( [], @@ -353,7 +355,7 @@ static function(array $carry, string $property, string $cypher): array { } )) ->withParameter( - (string) $paramKey, + $paramKey->toString(), $data ->filter(static function(string $key) use ($keysToKeep): bool { return $keysToKeep->contains($key); @@ -382,27 +384,28 @@ private function matchEdge( $value, Query $query ): Query { - if ($this->variables->contains((string) $name)) { + if ($this->variables->contains($name->toString())) { return $query; } if ($this->variables->size() > 0) { - $query = $query->with(...$this->variables->toPrimitive()); + $query = $query->with(...unwrap($this->variables)); } - $this->variables = $this->variables->add((string) $name); + $this->variables = $this->variables->add($name->toString()); return $query - ->match((string) $name) + ->match($name->toString()) ->withProperty( $meta->target(), - (string) $name + $name ->prepend('{') ->append('_props}.') ->append($meta->target()) + ->toString(), ) ->withParameter( - (string) $name->append('_props'), + $name->append('_props')->toString(), [ $meta->target() => $value, ] diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 92cbd1e..7369697 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -22,11 +22,11 @@ }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ - MapInterface, Map, - Stream, + Sequence, Str, }; +use function Innmind\Immutable\unwrap; final class RemovePersister implements Persister { @@ -34,7 +34,7 @@ final class RemovePersister implements Persister private EventBus $dispatch; private Metadatas $metadata; private Str $name; - private ?Stream $variables = null; + private ?Sequence $variables = null; public function __construct( ChangesetComputer $changeset, @@ -44,7 +44,7 @@ public function __construct( $this->changeset = $changeset; $this->dispatch = $dispatch; $this->metadata = $metadata; - $this->name = new Str('e%s'); + $this->name = Str::of('e%s'); } /** @@ -52,11 +52,10 @@ public function __construct( */ public function __invoke(Connection $connection, Container $container): void { - $entities = $container - ->state(State::toBeRemoved()) - ->foreach(function(Identity $identity, object $object): void { - ($this->dispatch)(new EntityAboutToBeRemoved($identity, $object)); - }); + $entities = $container->state(State::toBeRemoved()); + $entities->foreach(function(Identity $identity, object $object): void { + ($this->dispatch)(new EntityAboutToBeRemoved($identity, $object)); + }); if ($entities->size() === 0) { return; @@ -66,7 +65,7 @@ public function __invoke(Connection $connection, Container $container): void $entities->foreach(function(Identity $identity, object $object) use ($container): void { $container->push($identity, $object, State::removed()); - $this->changeset->use($identity, new Map('string', 'mixed')); //in case the identity is reused later on + $this->changeset->use($identity, Map::of('string', 'mixed')); //in case the identity is reused later on ($this->dispatch)(new EntityRemoved($identity, $object)); }); } @@ -74,12 +73,12 @@ public function __invoke(Connection $connection, Container $container): void /** * Build the query to delete all entities at once * - * @param MapInterface $entities + * @param Map $entities */ - private function queryFor(MapInterface $entities): Query + private function queryFor(Map $entities): Query { $query = new Query\Query; - $this->variables = new Stream('string'); + $this->variables = Sequence::strings(); $partitions = $entities->partition(function(Identity $identity, object $entity): bool { $meta = ($this->metadata)(\get_class($entity)); @@ -125,23 +124,24 @@ private function matchRelationship( ): Query { $meta = ($this->metadata)(\get_class($entity)); $name = $this->name->sprintf(\md5($identity->value())); - $this->variables = $this->variables->add((string) $name); + $this->variables = $this->variables->add($name->toString()); return $query ->match() ->linkedTo() ->through( (string) $meta->type(), - (string) $name + $name->toString(), ) ->withProperty( $meta->identity()->property(), - (string) $name + $name ->prepend('{') ->append('_identity}') + ->toString(), ) ->withParameter( - (string) $name->append('_identity'), + $name->append('_identity')->toString(), $identity->value() ); } @@ -156,21 +156,22 @@ private function matchAggregate( ): Query { $meta = ($this->metadata)(\get_class($entity)); $name = $this->name->sprintf(\md5($identity->value())); - $this->variables = $this->variables->add((string) $name); + $this->variables = $this->variables->add($name->toString()); $query = $query ->match( - (string) $name, - $meta->labels()->toPrimitive() + $name->toString(), + ...unwrap($meta->labels()), ) ->withProperty( $meta->identity()->property(), - (string) $name + $name ->prepend('{') ->append('_identity}') + ->toString() ) ->withParameter( - (string) $name->append('_identity'), + $name->append('_identity')->toString(), $identity->value() ); @@ -180,20 +181,22 @@ private function matchAggregate( $query, function(Query $carry, string $property, Child $child) use ($name): Query { $carry = $carry - ->match((string) $name) + ->match($name->toString()) ->linkedTo( - $childName = (string) $name + $childName = $name ->append('_') ->append($child->relationship()->property()) ->append('_') - ->append($child->relationship()->childProperty()), - $child->labels()->toPrimitive() + ->append($child->relationship()->childProperty()) + ->toString(), + ...unwrap($child->labels()), ) ->through( (string) $child->relationship()->type(), - $relName = (string) $name + $relName = $name ->append('_') ->append($child->relationship()->property()) + ->toString(), ); $this->variables = $this->variables ->add($childName) diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index 4d36bf9..00a157b 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -23,10 +23,10 @@ }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ - MapInterface, Map, Str, }; +use function Innmind\Immutable\unwrap; final class UpdatePersister implements Persister { @@ -47,7 +47,7 @@ public function __construct( $this->dispatch = $dispatch; $this->extract = $extract; $this->metadata = $metadata; - $this->name = new Str('e%s'); + $this->name = Str::of('e%s'); } /** @@ -57,8 +57,8 @@ public function __invoke(Connection $connection, Container $container): void { $entities = $container->state(State::managed()); $changesets = $entities->reduce( - new Map(Identity::class, MapInterface::class), - function(MapInterface $carry, Identity $identity, object $entity): MapInterface { + Map::of(Identity::class, Map::class), + function(Map $carry, Identity $identity, object $entity): Map { $data = ($this->extract)($entity); $changeset = $this->changeset->compute($identity, $data); @@ -74,7 +74,7 @@ function(MapInterface $carry, Identity $identity, object $entity): MapInterface return; } - $changesets->foreach(function(Identity $identity, MapInterface $changeset) use ($entities): void { + $changesets->foreach(function(Identity $identity, Map $changeset) use ($entities): void { ($this->dispatch)( new EntityAboutToBeUpdated( $identity, @@ -86,7 +86,7 @@ function(MapInterface $carry, Identity $identity, object $entity): MapInterface $connection->execute($this->queryFor($changesets, $entities)); - $changesets->foreach(function(Identity $identity, MapInterface $changeset) use ($entities): void { + $changesets->foreach(function(Identity $identity, Map $changeset) use ($entities): void { $entity = $entities->get($identity); $this->changeset->use( $identity, @@ -105,18 +105,18 @@ function(MapInterface $carry, Identity $identity, object $entity): MapInterface /** * Build the query to update all entities at once * - * @param MapInterface> $changesets - * @param MapInterface $entities + * @param Map> $changesets + * @param Map $entities */ private function queryFor( - MapInterface $changesets, - MapInterface $entities + Map $changesets, + Map $entities ): Query { - $this->variables = new Map(Str::class, MapInterface::class); + $this->variables = Map::of(Str::class, Map::class); $query = $changesets->reduce( new Query\Query, - function(Query $carry, Identity $identity, MapInterface $changeset) use ($entities): Query { + function(Query $carry, Identity $identity, Map $changeset) use ($entities): Query { $entity = $entities->get($identity); $meta = ($this->metadata)(\get_class($entity)); @@ -143,7 +143,7 @@ function(Query $carry, Identity $identity, MapInterface $changeset) use ($entiti ->variables ->reduce( $query, - function(Query $carry, Str $variable, MapInterface $changeset): Query { + function(Query $carry, Str $variable, Map $changeset): Query { return $this->update($variable, $changeset, $carry); } ); @@ -155,29 +155,30 @@ function(Query $carry, Str $variable, MapInterface $changeset): Query { /** * Add match clause to match all parts of the aggregate that needs to be updated * - * @param MapInterface $changeset + * @param Map $changeset */ private function matchAggregate( Identity $identity, object $entity, Aggregate $meta, - MapInterface $changeset, + Map $changeset, Query $query ): Query { $name = $this->name->sprintf(\md5($identity->value())); $query = $query ->match( - (string) $name, - $meta->labels()->toPrimitive() + $name->toString(), + ...unwrap($meta->labels()), ) ->withProperty( $meta->identity()->property(), - (string) $name + $name ->prepend('{') ->append('_identity}') + ->toString(), ) ->withParameter( - (string) $name->append('_identity'), + $name->append('_identity')->toString(), $identity->value() ); $this->variables = $this->variables->put( @@ -224,14 +225,14 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): } return $carry - ->match((string) $name) + ->match($name->toString()) ->linkedTo( - $childName ? (string) $childName : null, - $child->labels()->toPrimitive() + $childName ? $childName->toString() : null, + ...unwrap($child->labels()), ) ->through( (string) $child->relationship()->type(), - (string) $relName + $relName->toString(), ); } ); @@ -240,13 +241,13 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): /** * Add the match clause for a relationship * - * @param MapInterface $changeset + * @param Map $changeset */ private function matchRelationship( Identity $identity, object $entity, Relationship $meta, - MapInterface $changeset, + Map $changeset, Query $query ): Query { $name = $this->name->sprintf(\md5($identity->value())); @@ -263,16 +264,17 @@ private function matchRelationship( ->linkedTo() ->through( (string) $meta->type(), - (string) $name + $name->toString(), ) ->withProperty( $meta->identity()->property(), - (string) $name + $name ->prepend('{') ->append('_identity}') + ->toString(), ) ->withParameter( - (string) $name->append('_identity'), + $name->append('_identity')->toString(), $identity->value() ); } @@ -280,15 +282,15 @@ private function matchRelationship( /** * Build a collection with only the elements that are properties * - * @param MapInterface $changeset - * @param MapInterface $properties + * @param Map $changeset + * @param Map $properties * - * @return MapInterface + * @return Map */ private function buildProperties( - MapInterface $changeset, - MapInterface $properties - ): MapInterface { + Map $changeset, + Map $properties + ): Map { return $changeset->filter(static function(string $property) use ($properties) { return $properties->contains($property); }); @@ -298,24 +300,24 @@ private function buildProperties( * Add a clause to set all properties to be updated on the wished variable * * @param Str $variable - * @param MapInterface $changeset + * @param Map $changeset * @param Query $query * * @return Query */ private function update( Str $variable, - MapInterface $changeset, + Map $changeset, Query $query ): Query { return $query ->set(sprintf( '%s += {%s_props}', - $variable, - $variable + $variable->toString(), + $variable->toString(), )) ->withParameter( - (string) $variable->append('_props'), + $variable->append('_props')->toString(), $changeset->reduce( [], static function(array $carry, string $key, $value): array { diff --git a/src/Query/PropertiesMatch.php b/src/Query/PropertiesMatch.php index 26efe0b..57f8245 100644 --- a/src/Query/PropertiesMatch.php +++ b/src/Query/PropertiesMatch.php @@ -3,27 +3,27 @@ namespace Innmind\Neo4j\ONM\Query; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; final class PropertiesMatch { - private MapInterface $properties; - private MapInterface $parameters; + private Map $properties; + private Map $parameters; - public function __construct(MapInterface $properties, MapInterface $parameters) + public function __construct(Map $properties, Map $parameters) { if ( (string) $properties->keyType() !== 'string' || (string) $properties->valueType() !== 'string' ) { - throw new \TypeError('Argument 1 must be of type MapInterface'); + throw new \TypeError('Argument 1 must be of type Map'); } if ( (string) $parameters->keyType() !== 'string' || (string) $parameters->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 2 must be of type MapInterface'); + throw new \TypeError('Argument 2 must be of type Map'); } $this->properties = $properties; @@ -31,17 +31,17 @@ public function __construct(MapInterface $properties, MapInterface $parameters) } /** - * @return MapInterface + * @return Map */ - public function properties(): MapInterface + public function properties(): Map { return $this->properties; } /** - * @return MapInterface + * @return Map */ - public function parameters(): MapInterface + public function parameters(): Map { return $this->parameters; } diff --git a/src/Query/Where.php b/src/Query/Where.php index 85aa5b0..5f6bd76 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -5,16 +5,16 @@ use Innmind\Neo4j\ONM\Exception\DomainException; use Innmind\Immutable\{ - MapInterface, + Map, Str, }; final class Where { private string $cypher; - private MapInterface $parameters; + private Map $parameters; - public function __construct(string $cypher, MapInterface $parameters) + public function __construct(string $cypher, Map $parameters) { if (Str::of($cypher)->empty()) { throw new DomainException; @@ -24,7 +24,7 @@ public function __construct(string $cypher, MapInterface $parameters) (string) $parameters->keyType() !== 'string' || (string) $parameters->valueType() !== 'mixed' ) { - throw new \TypeError('Argument 2 must be of type MapInterface'); + throw new \TypeError('Argument 2 must be of type Map'); } $this->cypher = $cypher; @@ -37,9 +37,9 @@ public function cypher(): string } /** - * @return MapInterface + * @return Map */ - public function parameters(): MapInterface + public function parameters(): Map { return $this->parameters; } diff --git a/src/Repository.php b/src/Repository.php index 5b7ddab..a27beea 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -4,7 +4,7 @@ namespace Innmind\Neo4j\ONM; use Innmind\Specification\Specification; -use Innmind\Immutable\SetInterface; +use Innmind\Immutable\Set; interface Repository { @@ -38,14 +38,14 @@ public function remove(object $entity): self; /** * Return all the entities from the repository * - * @return SetInterface + * @return Set */ - public function all(): SetInterface; + public function all(): Set; /** * Return all the entities matching the given specification * - * @return SetInterface + * @return Set */ - public function matching(Specification $specification): SetInterface; + public function matching(Specification $specification): Set; } diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 958f196..584214c 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -13,10 +13,7 @@ Entity\Container\State, Exception\EntityNotFound, }; -use Innmind\Immutable\{ - SetInterface, - Set, -}; +use Innmind\Immutable\Set; use Innmind\Specification\Specification; final class Repository implements RepositoryInterface @@ -115,7 +112,7 @@ public function remove(object $entity): RepositoryInterface /** * {@inheritdoc} */ - public function all(): SetInterface + public function all(): Set { $match = ($this->all)($this->metadata()); @@ -128,7 +125,7 @@ public function all(): SetInterface /** * {@inheritdoc} */ - public function matching(Specification $specification): SetInterface + public function matching(Specification $specification): Set { $match = ($this->matching)( $this->metadata(), diff --git a/src/RepositoryFactory.php b/src/RepositoryFactory.php index 8d25e51..17a6064 100644 --- a/src/RepositoryFactory.php +++ b/src/RepositoryFactory.php @@ -8,32 +8,29 @@ Translation\SpecificationTranslator, Metadata\Entity, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class RepositoryFactory { private UnitOfWork $unitOfWork; private MatchTranslator $matchTranslator; private SpecificationTranslator $specificationTranslator; - private MapInterface $repositories; + private Map $repositories; public function __construct( UnitOfWork $unitOfWork, MatchTranslator $matchTranslator, SpecificationTranslator $specificationTranslator, - MapInterface $repositories = null + Map $repositories = null ) { - $repositories = $repositories ?? new Map(Entity::class, Repository::class); + $repositories = $repositories ?? Map::of(Entity::class, Repository::class); if ( (string) $repositories->keyType() !== Entity::class || (string) $repositories->valueType() !== Repository::class ) { throw new \TypeError(sprintf( - 'Argument 4 must be of type MapInterface<%s, %s>', + 'Argument 4 must be of type Map<%s, %s>', Entity::class, Repository::class )); diff --git a/src/Translation/EntityTranslator.php b/src/Translation/EntityTranslator.php index 615195e..396c11a 100644 --- a/src/Translation/EntityTranslator.php +++ b/src/Translation/EntityTranslator.php @@ -5,18 +5,18 @@ use Innmind\Neo4j\ONM\Metadata\Entity; use Innmind\Neo4j\DBAL\Result; -use Innmind\Immutable\SetInterface; +use Innmind\Immutable\Set; interface EntityTranslator { /** * Translate the wished variable from the result * - * @return SetInterface> + * @return Set> */ public function __invoke( string $variable, Entity $meta, Result $result - ): SetInterface; + ): Set; } diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index 90991c0..19658a7 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -16,6 +16,7 @@ Set, Str, }; +use function Innmind\Immutable\unwrap; final class AggregateTranslator implements IdentityMatchTranslator { @@ -29,7 +30,7 @@ public function __invoke( $query = (new Query) ->match( 'entity', - $meta->labels()->toPrimitive() + ...unwrap($meta->labels()) ) ->withProperty( $meta->identity()->property(), @@ -38,7 +39,7 @@ public function __invoke( ->withParameter('entity_identity', $identity->value()) ->with('entity'); - $variables = new Set('string'); + $variables = Set::strings(); $meta ->children() ->foreach(function( @@ -53,25 +54,25 @@ public function __invoke( ->append('_') ->append($child->relationship()->childProperty()); $variables = $variables - ->add((string) $relName) - ->add((string) $childName); + ->add($relName->toString()) + ->add($childName->toString()); $query = $query ->match('entity') ->linkedTo( - (string) $childName, - $child->labels()->toPrimitive() + $childName->toString(), + ...unwrap($child->labels()) ) ->through( (string) $child->relationship()->type(), - (string) $relName, + $relName->toString(), 'left' ); }); return new IdentityMatch( - $query->return('entity', ...$variables->toPrimitive()), + $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) ('entity', $meta) ); diff --git a/src/Translation/IdentityMatch/DelegationTranslator.php b/src/Translation/IdentityMatch/DelegationTranslator.php index e4fa00e..fe08de5 100644 --- a/src/Translation/IdentityMatch/DelegationTranslator.php +++ b/src/Translation/IdentityMatch/DelegationTranslator.php @@ -11,16 +11,13 @@ Identity, IdentityMatch, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class DelegationTranslator implements IdentityMatchTranslator { - private MapInterface $translators; + private Map $translators; - public function __construct(MapInterface $translators = null) + public function __construct(Map $translators = null) { $this->translators = $translators ?? Map::of('string', IdentityMatchTranslator::class) (Aggregate::class, new AggregateTranslator) @@ -31,7 +28,7 @@ public function __construct(MapInterface $translators = null) (string) $this->translators->valueType() !== IdentityMatchTranslator::class ) { throw new \TypeError(sprintf( - 'Argument 1 must be of type MapInterface', + 'Argument 1 must be of type Map', IdentityMatchTranslator::class )); } diff --git a/src/Translation/Match/AggregateTranslator.php b/src/Translation/Match/AggregateTranslator.php index 7d3546f..4db3b42 100644 --- a/src/Translation/Match/AggregateTranslator.php +++ b/src/Translation/Match/AggregateTranslator.php @@ -15,6 +15,7 @@ Set, Str, }; +use function Innmind\Immutable\unwrap; final class AggregateTranslator implements MatchTranslator { @@ -26,11 +27,11 @@ public function __invoke(Entity $meta): IdentityMatch $query = (new Query) ->match( 'entity', - $meta->labels()->toPrimitive() + ...unwrap($meta->labels()), ) ->with('entity'); - $variables = new Set('string'); + $variables = Set::strings(); $meta ->children() ->foreach(function( @@ -45,25 +46,25 @@ public function __invoke(Entity $meta): IdentityMatch ->append('_') ->append($child->relationship()->childProperty()); $variables = $variables - ->add((string) $relName) - ->add((string) $childName); + ->add($relName->toString()) + ->add($childName->toString()); $query = $query ->match('entity') ->linkedTo( - (string) $childName, - $child->labels()->toPrimitive() + $childName->toString(), + ...unwrap($child->labels()), ) ->through( (string) $child->relationship()->type(), - (string) $relName, + $relName->toString(), 'left' ); }); return new IdentityMatch( - $query->return('entity', ...$variables->toPrimitive()), + $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) ('entity', $meta) ); diff --git a/src/Translation/Match/DelegationTranslator.php b/src/Translation/Match/DelegationTranslator.php index 0850f68..101951c 100644 --- a/src/Translation/Match/DelegationTranslator.php +++ b/src/Translation/Match/DelegationTranslator.php @@ -10,16 +10,13 @@ Metadata\Entity, IdentityMatch, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class DelegationTranslator implements MatchTranslator { - private MapInterface $translators; + private Map $translators; - public function __construct(MapInterface $translators = null) + public function __construct(Map $translators = null) { $this->translators = $translators ?? Map::of('string', MatchTranslator::class) (Aggregate::class, new AggregateTranslator) @@ -30,7 +27,7 @@ public function __construct(MapInterface $translators = null) (string) $this->translators->valueType() !== MatchTranslator::class ) { throw new \TypeError(sprintf( - 'Argument 1 must be of type MapInterface', + 'Argument 1 must be of type Map', MatchTranslator::class )); } diff --git a/src/Translation/Result/AggregateTranslator.php b/src/Translation/Result/AggregateTranslator.php index 6ebfe83..5e3c7f4 100644 --- a/src/Translation/Result/AggregateTranslator.php +++ b/src/Translation/Result/AggregateTranslator.php @@ -20,9 +20,7 @@ Result\Row, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, Str, }; @@ -36,7 +34,7 @@ public function __invoke( string $variable, Entity $meta, Result $result - ): SetInterface { + ): Set { if (Str::of($variable)->empty()) { throw new DomainException; } @@ -51,8 +49,8 @@ public function __invoke( return $row->column() === $variable; }) ->reduce( - new Set(MapInterface::class), - function(SetInterface $carry, Row $row) use ($meta, $result): SetInterface { + Set::of(Map::class), + function(Set $carry, Row $row) use ($meta, $result): Set { return $carry->add($this->translateNode( $row->value()[$meta->identity()->property()], $meta, @@ -66,7 +64,7 @@ private function translateNode( $identity, Entity $meta, Result $result - ): MapInterface { + ): Map { $node = $result ->nodes() ->filter(static function(int $id, Node $node) use ($identity, $meta) { @@ -76,7 +74,8 @@ private function translateNode( return $properties->contains($id) && $properties->get($id) === $identity; }) - ->current(); + ->values() + ->first(); $data = Map::of('string', 'mixed') ( $meta->identity()->property(), @@ -99,7 +98,7 @@ private function translateNode( }) ->reduce( $data, - static function(MapInterface $carry, string $name) use ($node): MapInterface { + static function(Map $carry, string $name) use ($node): Map { return $carry->put( $name, $node->properties()->get($name) @@ -112,7 +111,7 @@ static function(MapInterface $carry, string $name) use ($node): MapInterface { ->children() ->reduce( $data, - function(MapInterface $carry, string $name, Child $meta) use ($node, $result): MapInterface { + function(Map $carry, string $name, Child $meta) use ($node, $result): Map { return $carry->put( $name, $this->translateChild($meta, $result, $node) @@ -128,7 +127,7 @@ private function translateChild( Child $meta, Result $result, Node $node - ): MapInterface { + ): Map { $relMeta = $meta->relationship(); $relationships = $result ->relationships() @@ -139,7 +138,7 @@ private function translateChild( $node, $relMeta ): bool { - return (string) $relationship->type() === (string) $relMeta->type() && + return $relationship->type()->value() === (string) $relMeta->type() && $relationship->endNode()->value() === $node->id()->value(); }) ->values(); @@ -159,7 +158,7 @@ private function translateRelationship( Child $meta, Result $result, Relationship $relationship - ): MapInterface { + ): Map { return $meta ->relationship() ->properties() @@ -174,8 +173,8 @@ private function translateRelationship( return true; }) ->reduce( - new Map('string', 'mixed'), - static function(MapInterface $carry, string $name) use ($relationship): MapInterface { + Map::of('string', 'mixed'), + static function(Map $carry, string $name) use ($relationship): Map { return $carry->put( $name, $relationship->properties()->get($name) @@ -196,7 +195,7 @@ private function translateValueObject( Child $meta, Result $result, Relationship $relationship - ): MapInterface { + ): Map { $node = $result ->nodes() ->get($relationship->startNode()->value()); @@ -214,8 +213,8 @@ private function translateValueObject( return true; }) ->reduce( - new Map('string', 'mixed'), - static function(MapInterface $carry, string $name) use ($node): MapInterface { + Map::of('string', 'mixed'), + static function(Map $carry, string $name) use ($node): Map { return $carry->put( $name, $node->properties()->get($name) diff --git a/src/Translation/Result/RelationshipTranslator.php b/src/Translation/Result/RelationshipTranslator.php index a999992..8450bab 100644 --- a/src/Translation/Result/RelationshipTranslator.php +++ b/src/Translation/Result/RelationshipTranslator.php @@ -17,9 +17,7 @@ Result\Row, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; @@ -32,7 +30,7 @@ public function __invoke( string $variable, Entity $meta, Result $result - ): SetInterface { + ): Set { if (empty($variable)) { throw new DomainException; } @@ -47,8 +45,8 @@ public function __invoke( return $row->column() === $variable; }) ->reduce( - new Set(MapInterface::class), - function(SetInterface $carry, Row $row) use ($meta, $result): SetInterface { + Set::of(Map::class), + function(Set $carry, Row $row) use ($meta, $result): Set { return $carry->add( $this->translateRelationship( $row->value()[$meta->identity()->property()], @@ -64,7 +62,7 @@ private function translateRelationship( $identity, Entity $meta, Result $result - ): MapInterface { + ): Map { $relationship = $result ->relationships() ->filter(static function(int $id, DBALRelationship $relationship) use ($identity, $meta): bool { @@ -74,7 +72,8 @@ private function translateRelationship( return $properties->contains($id) && $properties->get($id) === $identity; }) - ->current(); + ->values() + ->first(); $data = Map::of('string', 'mixed') ( $meta->identity()->property(), @@ -113,7 +112,7 @@ private function translateRelationship( }) ->reduce( $data, - static function(MapInterface $carry, string $name) use ($relationship): MapInterface { + static function(Map $carry, string $name) use ($relationship): Map { return $carry->put( $name, $relationship->properties()->get($name) diff --git a/src/Translation/ResultTranslator.php b/src/Translation/ResultTranslator.php index 6987814..71e3231 100644 --- a/src/Translation/ResultTranslator.php +++ b/src/Translation/ResultTranslator.php @@ -15,16 +15,15 @@ Result\Row, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, + Set, }; final class ResultTranslator { - private MapInterface $translators; + private Map $translators; - public function __construct(MapInterface $translators = null) + public function __construct(Map $translators = null) { $this->translators = $translators ?? Map::of('string', EntityTranslator::class) (Aggregate::class, new AggregateTranslator) @@ -35,7 +34,7 @@ public function __construct(MapInterface $translators = null) (string) $this->translators->valueType() !== EntityTranslator::class ) { throw new \TypeError(sprintf( - 'Argument 1 must be of type MapInterface', + 'Argument 1 must be of type Map', EntityTranslator::class )); } @@ -44,20 +43,20 @@ public function __construct(MapInterface $translators = null) /** * Translate a raw dbal result into formated data usable for entity factories * - * @param MapInterface $variables Association between query variables and entity definitions + * @param Map $variables Association between query variables and entity definitions * - * @return MapInterface>> + * @return Map>> */ public function __invoke( Result $result, - MapInterface $variables - ): MapInterface { + Map $variables + ): Map { if ( (string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== Entity::class ) { throw new \TypeError(sprintf( - 'Argument 2 must be of type MapInterface', + 'Argument 2 must be of type Map', Entity::class )); } @@ -73,8 +72,8 @@ public function __invoke( return $forVariable->size() > 0; }) ->reduce( - new Map('string', SetInterface::class), - function(MapInterface $carry, string $variable, Entity $meta) use ($result): MapInterface { + Map::of('string', Set::class), + function(Map $carry, string $variable, Entity $meta) use ($result): Map { $translate = $this->translators->get(get_class($meta)); return $carry->put( diff --git a/src/Translation/Specification/AggregateTranslator.php b/src/Translation/Specification/AggregateTranslator.php index 4ca4328..772b493 100644 --- a/src/Translation/Specification/AggregateTranslator.php +++ b/src/Translation/Specification/AggregateTranslator.php @@ -14,11 +14,11 @@ }; use Innmind\Neo4j\DBAL\Query\Query; use Innmind\Immutable\{ - MapInterface, Map, Set, Str, }; +use function Innmind\Immutable\unwrap; use Innmind\Specification\Specification; final class AggregateTranslator implements SpecificationTranslator @@ -30,7 +30,7 @@ public function __invoke( Entity $meta, Specification $specification ): IdentityMatch { - $variables = new Set('string'); + $variables = Set::strings(); try { $mapping = (new AggregatePropertyMatchVisitor($meta))($specification); @@ -39,7 +39,7 @@ public function __invoke( ->addProperties( (new Query)->match( 'entity', - $meta->labels()->toPrimitive() + ...unwrap($meta->labels()), ), 'entity', $mapping @@ -61,8 +61,8 @@ public function __invoke( ->append('_') ->append($child->relationship()->childProperty()); $variables = $variables - ->add((string) $relName) - ->add((string) $childName); + ->add($relName->toString()) + ->add($childName->toString()); $query = $this->addProperties( $this @@ -70,18 +70,18 @@ public function __invoke( $query ->match('entity') ->linkedTo( - (string) $childName, - $child->labels()->toPrimitive() + $childName->toString(), + ...unwrap($child->labels()), ), - (string) $childName, + $childName->toString(), $mapping ) ->through( (string) $child->relationship()->type(), - (string) $relName, + $relName->toString(), 'left' ), - (string) $relName, + $relName->toString(), $mapping ); }); @@ -89,7 +89,7 @@ public function __invoke( $query = (new Query) ->match( 'entity', - $meta->labels()->toPrimitive() + ...unwrap($meta->labels()), ) ->with('entity'); @@ -107,18 +107,18 @@ public function __invoke( ->append('_') ->append($child->relationship()->childProperty()); $variables = $variables - ->add((string) $relName) - ->add((string) $childName); + ->add($relName->toString()) + ->add($childName->toString()); $query = $query ->match('entity') ->linkedTo( - (string) $childName, - $child->labels()->toPrimitive() + $childName->toString(), + ...unwrap($child->labels()), ) ->through( (string) $child->relationship()->type(), - (string) $relName, + $relName->toString(), 'left' ); }); @@ -133,19 +133,19 @@ static function(Query $query, string $key, $value): Query { } return new IdentityMatch( - $query->return('entity', ...$variables->toPrimitive()), + $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) ('entity', $meta) ); } /** - * @param MapInterface $mapping + * @param Map $mapping */ private function addProperties( Query $query, string $name, - MapInterface $mapping + Map $mapping ): Query { if ($mapping->contains($name)) { $match = $mapping->get($name); diff --git a/src/Translation/Specification/DelegationTranslator.php b/src/Translation/Specification/DelegationTranslator.php index edf954b..4f0e695 100644 --- a/src/Translation/Specification/DelegationTranslator.php +++ b/src/Translation/Specification/DelegationTranslator.php @@ -11,19 +11,16 @@ IdentityMatch, Exception\SpecificationNotApplicable, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use Innmind\Specification\Specification; final class DelegationTranslator implements SpecificationTranslator { - private MapInterface $translators; + private Map $translators; private Validator $validate; public function __construct( - MapInterface $translators = null, + Map $translators = null, Validator $validate = null ) { $this->translators = $translators ?? Map::of('string', SpecificationTranslator::class) @@ -36,7 +33,7 @@ public function __construct( (string) $this->translators->valueType() !== SpecificationTranslator::class ) { throw new \TypeError(sprintf( - 'Argument 1 must be of type MapInterface', + 'Argument 1 must be of type Map', SpecificationTranslator::class )); } diff --git a/src/Translation/Specification/RelationshipTranslator.php b/src/Translation/Specification/RelationshipTranslator.php index ed8b166..935cec2 100644 --- a/src/Translation/Specification/RelationshipTranslator.php +++ b/src/Translation/Specification/RelationshipTranslator.php @@ -12,10 +12,7 @@ Exception\SpecificationNotApplicableAsPropertyMatch, }; use Innmind\Neo4j\DBAL\Query\Query; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use Innmind\Specification\Specification; final class RelationshipTranslator implements SpecificationTranslator @@ -78,12 +75,12 @@ static function(Query $query, string $key, $value): Query { } /** - * @param MapInterface $mapping + * @param Map $mapping */ private function addProperties( Query $query, string $name, - MapInterface $mapping + Map $mapping ): Query { if ($mapping->contains($name)) { $match = $mapping->get($name); diff --git a/src/Translation/Specification/Validator/AggregateValidator.php b/src/Translation/Specification/Validator/AggregateValidator.php index 553b732..f4b81f6 100644 --- a/src/Translation/Specification/Validator/AggregateValidator.php +++ b/src/Translation/Specification/Validator/AggregateValidator.php @@ -59,14 +59,14 @@ private function isValidProperty( return true; } - $property = new Str($property); + $property = Str::of($property); if (!$property->matches('/[a-zA-Z]+(\.[a-zA-Z]+)+/')) { return false; } $pieces = $property->split('.'); - $piece = (string) $pieces->get(0); + $piece = $pieces->get(0)->toString(); if (!$meta->children()->contains($piece)) { return false; @@ -77,16 +77,16 @@ private function isValidProperty( switch ($pieces->count()) { case 2: - return $relationship->properties()->contains((string) $pieces->get(1)); + return $relationship->properties()->contains($pieces->get(1)->toString()); case 3: - $subPiece = (string) $pieces->get(1); + $subPiece = $pieces->get(1)->toString(); if (!$relationship->childProperty() === $subPiece) { return false; } - return $child->properties()->contains((string) $pieces->get(2)); + return $child->properties()->contains($pieces->get(2)->toString()); } return false; diff --git a/src/Translation/Specification/Validator/DelegationValidator.php b/src/Translation/Specification/Validator/DelegationValidator.php index 7531dc8..d19fe34 100644 --- a/src/Translation/Specification/Validator/DelegationValidator.php +++ b/src/Translation/Specification/Validator/DelegationValidator.php @@ -10,16 +10,13 @@ Metadata\Relationship, }; use Innmind\Specification\Specification; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; final class DelegationValidator implements Validator { - private MapInterface $validators; + private Map $validators; - public function __construct(MapInterface $validators = null) + public function __construct(Map $validators = null) { $this->validators = $validators ?? Map::of('string', Validator::class) (Aggregate::class, new AggregateValidator) @@ -30,7 +27,7 @@ public function __construct(MapInterface $validators = null) (string) $this->validators->valueType() !== Validator::class ) { throw new \TypeError(sprintf( - 'Argument 1 must be of type MapInterface', + 'Argument 1 must be of type Map', Validator::class )); } diff --git a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php index a53a938..7b915b3 100644 --- a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php @@ -19,6 +19,7 @@ Map, Str, }; +use function Innmind\Immutable\join; final class AggregateVisitor implements CypherVisitor { @@ -46,7 +47,7 @@ public function __invoke(Specification $specification): Where case $specification instanceof Composite: $left = ($this)($specification->left()); $right = ($this)($specification->right()); - $operator = (string) Str::of((string) $specification->operator())->toLower(); + $operator = Str::of((string) $specification->operator())->toLower()->toString(); return $left->{$operator}($right); @@ -57,7 +58,7 @@ public function __invoke(Specification $specification): Where private function buildCondition(Comparator $specification): Where { - $property = new Str($specification->property()); + $property = Str::of($specification->property()); switch (true) { case $this->meta->properties()->contains($specification->property()): @@ -81,24 +82,30 @@ private function buildPropertyCondition( 'entity.%s %s %s', $prop, ($this->convert)($specification->sign()), - $key->prepend('{')->append('}') + $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ); } private function buildSubPropertyCondition( Comparator $specification ): Where { - $prop = new Str($specification->property()); + $prop = Str::of($specification->property()); $pieces = $prop->split('.'); $var = Str::of('entity_')->append( - (string) $pieces->dropEnd(1)->join('_') + join( + '_', + $pieces->dropEnd(1)->mapTo( + 'string', + static fn(Str $piece): string => $piece->toString(), + ), + )->toString(), ); $key = $var ->append('_') - ->append((string) $pieces->last()) + ->append($pieces->last()->toString()) ->append((string) $this->count); return new Where( @@ -106,12 +113,13 @@ private function buildSubPropertyCondition( '%s %s %s', $var ->append('.') - ->append((string) $pieces->last()), + ->append($pieces->last()->toString()) + ->toString(), ($this->convert)($specification->sign()), - $key->prepend('{')->append('}') + $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ); } } diff --git a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php index 91ed46a..b712f0e 100644 --- a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php @@ -18,7 +18,6 @@ Not, }; use Innmind\Immutable\{ - MapInterface, Map, Str, }; @@ -49,7 +48,7 @@ public function __invoke(Specification $specification): Where case $specification instanceof Composite: $left = ($this)($specification->left()); $right = ($this)($specification->right()); - $operator = (string) Str::of((string) $specification->operator())->toLower(); + $operator = Str::of((string) $specification->operator())->toLower()->toString(); return $left->{$operator}($right); @@ -95,10 +94,10 @@ private function buildPropertyCondition( 'entity.%s %s %s', $prop, ($this->convert)($specification->sign()), - $key->prepend('{')->append('}') + $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ); } @@ -123,10 +122,10 @@ private function buildEdgeCondition( $side, $edge->target(), ($this->convert)($specification->sign()), - $key->prepend('{')->append('}') + $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ((string) $key, $value) + ($key->toString(), $value) ); } } diff --git a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php index 715c919..238f2eb 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php @@ -17,10 +17,10 @@ Sign, }; use Innmind\Immutable\{ - MapInterface, Map, Str, }; +use function Innmind\Immutable\join; final class AggregateVisitor implements PropertyMatchVisitor { @@ -34,7 +34,7 @@ public function __construct(Aggregate $meta) /** * {@inheritdo} */ - public function __invoke(Specification $specification): MapInterface + public function __invoke(Specification $specification): Map { switch (true) { case $specification instanceof Comparator: @@ -60,8 +60,8 @@ public function __invoke(Specification $specification): MapInterface private function buildMapping( Comparator $specification - ): MapInterface { - $property = new Str($specification->property()); + ): Map { + $property = Str::of($specification->property()); switch (true) { case $this->meta->properties()->contains($specification->property()): @@ -74,7 +74,7 @@ private function buildMapping( private function buildPropertyMapping( Comparator $specification - ): MapInterface { + ): Map { $prop = $specification->property(); $key = Str::of('entity_')->append($prop); @@ -83,47 +83,54 @@ private function buildPropertyMapping( 'entity', new PropertiesMatch( Map::of('string', 'string') - ($prop, (string) $key->prepend('{')->append('}')), + ($prop, $key->prepend('{')->append('}')->toString()), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ) ); } private function buildSubPropertyMapping( Comparator $specification - ): MapInterface { - $prop = new Str($specification->property()); + ): Map { + $prop = Str::of($specification->property()); $pieces = $prop->split('.'); $var = Str::of('entity_')->append( - (string) $pieces->dropEnd(1)->join('_') + join( + '_', + $pieces->dropEnd(1)->mapTo( + 'string', + static fn(Str $piece): string => $piece->toString(), + ), + )->toString(), ); - $key = $var->append('_')->append((string) $pieces->last()); + $key = $var->append('_')->append($pieces->last()->toString()); return Map::of('string', PropertiesMatch::class) ( - (string) $var, + $var->toString(), new PropertiesMatch( Map::of('string', 'string') ( - (string) $pieces->last(), - (string) $key + $pieces->last()->toString(), + $key ->prepend('{') ->append('}') + ->toString(), ), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ) ); } private function merge( - MapInterface $left, - MapInterface $right - ): MapInterface { + Map $left, + Map $right + ): Map { return $right->reduce( $left, - static function(MapInterface $carry, string $var, PropertiesMatch $data) use ($left): MapInterface { + static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { if (!$carry->contains($var)) { return $carry->put($var, $data); } diff --git a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php index be6c541..a87a79c 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php @@ -19,7 +19,6 @@ Sign, }; use Innmind\Immutable\{ - MapInterface, Map, Str, }; @@ -36,7 +35,7 @@ public function __construct(Relationship $meta) /** * {@inheritdo} */ - public function __invoke(Specification $specification): MapInterface + public function __invoke(Specification $specification): Map { switch (true) { case $specification instanceof Comparator: @@ -62,7 +61,7 @@ public function __invoke(Specification $specification): MapInterface private function buildMapping( Comparator $specification - ): MapInterface { + ): Map { $property = $specification->property(); switch (true) { @@ -87,7 +86,7 @@ private function buildMapping( private function buildPropertyMapping( Comparator $specification - ): MapInterface { + ): Map { $prop = $specification->property(); $key = Str::of('entity_')->append($prop); @@ -96,9 +95,9 @@ private function buildPropertyMapping( 'entity', new PropertiesMatch( Map::of('string', 'string') - ($prop, (string) $key->prepend('{')->append('}')), + ($prop, $key->prepend('{')->append('}')->toString()), Map::of('string', 'mixed') - ((string) $key, $specification->value()) + ($key->toString(), $specification->value()) ) ); } @@ -107,7 +106,7 @@ private function buildEdgeMapping( Comparator $specification, RelationshipEdge $edge, string $side - ): MapInterface { + ): Map { $key = Str::of($side) ->append('_') ->append($edge->target()); @@ -124,23 +123,24 @@ private function buildEdgeMapping( Map::of('string', 'string') ( $edge->target(), - (string) $key + $key ->prepend('{') ->append('}') + ->toString() ), Map::of('string', 'mixed') - ((string) $key, $value) + ($key->toString(), $value) ) ); } private function merge( - MapInterface $left, - MapInterface $right - ): MapInterface { + Map $left, + Map $right + ): Map { return $right->reduce( $left, - static function(MapInterface $carry, string $var, PropertiesMatch $data) use ($left): MapInterface { + static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { if (!$carry->contains($var)) { return $carry->put($var, $data); } diff --git a/src/Translation/Specification/Visitor/PropertyMatchVisitor.php b/src/Translation/Specification/Visitor/PropertyMatchVisitor.php index 8a2dddb..f528dc4 100644 --- a/src/Translation/Specification/Visitor/PropertyMatchVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatchVisitor.php @@ -4,7 +4,7 @@ namespace Innmind\Neo4j\ONM\Translation\Specification\Visitor; use Innmind\Specification\Specification; -use Innmind\Immutable\MapInterface; +use Innmind\Immutable\Map; interface PropertyMatchVisitor { @@ -13,7 +13,7 @@ interface PropertyMatchVisitor * * @throws SpecificationNotApplicableAsPropertyMatchException * - * @return MapInterface + * @return Map */ - public function __invoke(Specification $specification): MapInterface; + public function __invoke(Specification $specification): Map; } diff --git a/src/Type/PointInTimeType.php b/src/Type/PointInTimeType.php index c24b829..ed4155b 100644 --- a/src/Type/PointInTimeType.php +++ b/src/Type/PointInTimeType.php @@ -8,23 +8,23 @@ Exception\InvalidArgumentException, }; use Innmind\TimeContinuum\{ - FormatInterface, - Format\ISO8601, - PointInTimeInterface, - PointInTime\Earth\PointInTime, + Format, + PointInTime as PointInTimeInterface, + Earth\Format\ISO8601, + Earth\PointInTime\PointInTime, }; final class PointInTimeType implements Type { private bool $nullable = false; - private FormatInterface $format; + private Format $format; - public function __construct(FormatInterface $format = null) + public function __construct(Format $format = null) { $this->format = $format ?? new ISO8601; } - public static function nullable(FormatInterface $format = null): self + public static function nullable(Format $format = null): self { $self = new self($format); $self->nullable = true; diff --git a/src/Type/SetType.php b/src/Type/SetType.php index f40a0c9..59a967a 100644 --- a/src/Type/SetType.php +++ b/src/Type/SetType.php @@ -8,10 +8,7 @@ Exception\RecursiveTypeDeclaration, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - SetInterface, - Set, -}; +use Innmind\Immutable\Set; final class SetType implements Type { @@ -47,11 +44,11 @@ public function forDatabase($value) } if ( - !$value instanceof SetInterface || + !$value instanceof Set || (string) $value->type() !== $this->type ) { throw new InvalidArgumentException(sprintf( - 'The set must be an instance of SetInterface<%s>', + 'The set must be an instance of Set<%s>', $this->type )); } @@ -71,7 +68,7 @@ function(array $carry, $value): array { */ public function fromDatabase($value) { - $set = new Set($this->type); + $set = Set::of($this->type); foreach ($value as $sub) { $set = $set->add($this->inner->fromDatabase($sub)); diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 80bd7de..78818f4 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -17,9 +17,10 @@ Query, }; use Innmind\Immutable\{ - MapInterface, - SetInterface, + Map, + Set, }; +use function Innmind\Immutable\first; use Innmind\Reflection\ReflectionObject; final class UnitOfWork @@ -129,7 +130,7 @@ public function get(string $class, Identity $identity): object throw new EntityNotFound; } - return $entities->current(); + return first($entities); } /** @@ -181,14 +182,14 @@ public function detach(object $entity): self /** * Execute the given query * - * @param MapInterface $variables + * @param Map $variables * - * @return SetInterface + * @return Set */ public function execute( Query $query, - MapInterface $variables - ): SetInterface { + Map $variables + ): Set { return ($this->makeEntity)( $this->connection->execute($query), $variables diff --git a/src/bootstrap.php b/src/bootstrap.php index 6736eee..0676492 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -14,36 +14,35 @@ }; use Innmind\CommandBus\CommandBus as CommandBusInterface; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; +use function Innmind\Immutable\unwrap; /** - * @param SetInterface $metas - * @param MapInterface|null $additionalGenerators - * @param MapInterface|null $repositories - * @param SetInterface|null $entityFactories - * @param MapInterface|null $resultTranslators - * @param MapInterface|null $identityMatchTranslators - * @param MapInterface|null $matchTranslators - * @param MapInterface|null $specificationTranslators - * @param MapInterface|null $dataExtractors + * @param Set $metas + * @param Map|null $additionalGenerators + * @param Map|null $repositories + * @param Set|null $entityFactories + * @param Map|null $resultTranslators + * @param Map|null $identityMatchTranslators + * @param Map|null $matchTranslators + * @param Map|null $specificationTranslators + * @param Map|null $dataExtractors */ function bootstrap( Connection $connection, - SetInterface $metas, - MapInterface $additionalGenerators = null, + Set $metas, + Map $additionalGenerators = null, EventBus $eventBus = null, - MapInterface $repositories = null, + Map $repositories = null, Persister $persister = null, - SetInterface $entityFactories = null, - MapInterface $resultTranslators = null, - MapInterface $identityMatchTranslators = null, - MapInterface $matchTranslators = null, - MapInterface $specificationTranslators = null, - MapInterface $dataExtractors = null + Set $entityFactories = null, + Map $resultTranslators = null, + Map $identityMatchTranslators = null, + Map $matchTranslators = null, + Map $specificationTranslators = null, + Map $dataExtractors = null ): array { $eventBus = $eventBus ?? new NullEventBus; @@ -71,7 +70,7 @@ function bootstrap( new EntityFactory\RelationshipFactory($identityGenerators) ); - $metadatas = new Metadatas(...$metas); + $metadatas = new Metadatas(...unwrap($metas)); $entityChangeset = new Entity\ChangesetComputer; $dataExtractor = new Entity\DataExtractor\DataExtractor( @@ -107,7 +106,7 @@ function bootstrap( new EntityFactory\EntityFactory( new Translation\ResultTranslator($resultTranslators), $identityGenerators, - new EntityFactory\Resolver(...$entityFactories), + new EntityFactory\Resolver(...unwrap($entityFactories)), $entityContainer ), new Translation\IdentityMatch\DelegationTranslator($identityMatchTranslators), diff --git a/tests/Entity/ChangesetComputerTest.php b/tests/Entity/ChangesetComputerTest.php index 7bf77a2..e4d9887 100644 --- a/tests/Entity/ChangesetComputerTest.php +++ b/tests/Entity/ChangesetComputerTest.php @@ -7,10 +7,8 @@ Entity\ChangesetComputer, Identity, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class ChangesetComputerTest extends TestCase @@ -87,33 +85,33 @@ public function testComputeWithSource() ) ); - $this->assertInstanceOf(MapInterface::class, $diff); + $this->assertInstanceOf(Map::class, $diff); $this->assertSame('string', (string) $diff->keyType()); $this->assertSame('mixed', (string) $diff->valueType()); $this->assertSame( ['should', 'extra', 'rel', 'another'], - $diff->keys()->toPrimitive() + unwrap($diff->keys()) ); $this->assertSame('to', $diff->get('should')); $this->assertSame('value', $diff->get('extra')); $this->assertNull($diff->get('another')); - $this->assertInstanceOf(MapInterface::class, $diff->get('rel')); + $this->assertInstanceOf(Map::class, $diff->get('rel')); $this->assertSame('string', (string) $diff->get('rel')->keyType()); $this->assertSame('mixed', (string) $diff->get('rel')->valueType()); $this->assertSame( ['child', 'empty'], - $diff->get('rel')->keys()->toPrimitive() + unwrap($diff->get('rel')->keys()) ); $this->assertNull($diff->get('rel')->get('empty')); $this->assertInstanceOf( - MapInterface::class, + Map::class, $diff->get('rel')->get('child') ); $this->assertSame('string', (string) $diff->get('rel')->get('child')->keyType()); $this->assertSame('mixed', (string) $diff->get('rel')->get('child')->valueType()); $this->assertSame( ['content', 'extra'], - $diff->get('rel')->get('child')->keys()->toPrimitive() + unwrap($diff->get('rel')->get('child')->keys()) ); $this->assertSame('bar', $diff->get('rel')->get('child')->get('content')); $this->assertNull($diff->get('rel')->get('child')->get('extra')); @@ -122,22 +120,22 @@ public function testComputeWithSource() public function testThrowWhenUsingInvalidSource() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); $this->computer->use( $this->createMock(Identity::class), - new Map('string', 'variable') + Map::of('string', 'variable') ); } public function testThrowWhenComputingInvalidTarget() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); $this->computer->compute( $this->createMock(Identity::class), - new Map('string', 'variable') + Map::of('string', 'variable') ); } } diff --git a/tests/Entity/DataExtractor/AggregateExtractorTest.php b/tests/Entity/DataExtractor/AggregateExtractorTest.php index 7109259..cb837f9 100644 --- a/tests/Entity/DataExtractor/AggregateExtractorTest.php +++ b/tests/Entity/DataExtractor/AggregateExtractorTest.php @@ -19,10 +19,10 @@ Exception\InvalidArgumentException, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class AggregateExtractorTest extends TestCase @@ -94,12 +94,12 @@ public function testExtract() $extract = new AggregateExtractor; $data = $extract($entity, $this->meta); - $this->assertInstanceOf(MapInterface::class, $data); + $this->assertInstanceOf(Map::class, $data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertSame( ['created', 'empty', 'uuid', 'rel'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', @@ -107,12 +107,12 @@ public function testExtract() ); $this->assertNull($data->get('empty')); $this->assertSame($u, $data->get('uuid')); - $this->assertInstanceOf(MapInterface::class, $data->get('rel')); + $this->assertInstanceOf(Map::class, $data->get('rel')); $this->assertSame('string', (string) $data->get('rel')->keyType()); $this->assertSame('mixed', (string) $data->get('rel')->valueType()); $this->assertSame( ['created', 'empty', 'child'], - $data->get('rel')->keys()->toPrimitive() + unwrap($data->get('rel')->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', @@ -120,14 +120,14 @@ public function testExtract() ); $this->assertNull($data->get('rel')->get('empty')); $this->assertInstanceOf( - MapInterface::class, + Map::class, $data->get('rel')->get('child') ); $this->assertSame('string', (string) $data->get('rel')->get('child')->keyType()); $this->assertSame('mixed', (string) $data->get('rel')->get('child')->valueType()); $this->assertSame( ['content', 'empty'], - $data->get('rel')->get('child')->keys()->toPrimitive() + unwrap($data->get('rel')->get('child')->keys()) ); $this->assertSame('foo', $data->get('rel')->get('child')->get('content')); $this->assertNull($data->get('rel')->get('child')->get('empty')); diff --git a/tests/Entity/DataExtractor/DataExtractorTest.php b/tests/Entity/DataExtractor/DataExtractorTest.php index 2fec8d5..6a81735 100644 --- a/tests/Entity/DataExtractor/DataExtractorTest.php +++ b/tests/Entity/DataExtractor/DataExtractorTest.php @@ -20,10 +20,10 @@ Exception\TypeError, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class DataExtractorTest extends TestCase @@ -114,12 +114,12 @@ public function testExtractAggregateRoot() $data = ($this->extract)($entity); - $this->assertInstanceOf(MapInterface::class, $data); + $this->assertInstanceOf(Map::class, $data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertSame( ['created', 'empty', 'uuid', 'rel'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', @@ -127,12 +127,12 @@ public function testExtractAggregateRoot() ); $this->assertNull($data->get('empty')); $this->assertSame($u, $data->get('uuid')); - $this->assertInstanceOf(MapInterface::class, $data->get('rel')); + $this->assertInstanceOf(Map::class, $data->get('rel')); $this->assertSame('string', (string) $data->get('rel')->keyType()); $this->assertSame('mixed', (string) $data->get('rel')->valueType()); $this->assertSame( ['created', 'empty', 'child'], - $data->get('rel')->keys()->toPrimitive() + unwrap($data->get('rel')->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', @@ -140,14 +140,14 @@ public function testExtractAggregateRoot() ); $this->assertNull($data->get('rel')->get('empty')); $this->assertInstanceOf( - MapInterface::class, + Map::class, $data->get('rel')->get('child') ); $this->assertSame('string', (string) $data->get('rel')->get('child')->keyType()); $this->assertSame('mixed', (string) $data->get('rel')->get('child')->valueType()); $this->assertSame( ['content', 'empty'], - $data->get('rel')->get('child')->keys()->toPrimitive() + unwrap($data->get('rel')->get('child')->keys()) ); $this->assertSame('foo', $data->get('rel')->get('child')->get('content')); $this->assertNull($data->get('rel')->get('child')->get('empty')); @@ -163,12 +163,12 @@ public function testExtractRelationship() $data = ($this->extract)($entity); - $this->assertInstanceOf(MapInterface::class, $data); + $this->assertInstanceOf(Map::class, $data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertSame( ['uuid', 'start', 'end', 'created', 'empty'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', @@ -183,11 +183,11 @@ public function testExtractRelationship() public function testThrowWhenInvalidExtractorMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); new DataExtractor( $this->metadatas, - new Map('string', 'callable') + Map::of('string', 'callable') ); } } diff --git a/tests/Entity/DataExtractor/RelationshipExtractorTest.php b/tests/Entity/DataExtractor/RelationshipExtractorTest.php index 8581df1..d6c461f 100644 --- a/tests/Entity/DataExtractor/RelationshipExtractorTest.php +++ b/tests/Entity/DataExtractor/RelationshipExtractorTest.php @@ -18,10 +18,8 @@ Type, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class RelationshipExtractorTest extends TestCase @@ -66,12 +64,12 @@ public function testExtract() $extract = new RelationshipExtractor; $data = $extract($entity, $this->meta); - $this->assertInstanceOf(MapInterface::class, $data); + $this->assertInstanceOf(Map::class, $data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertSame( ['uuid', 'start', 'end', 'created', 'empty'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); $this->assertRegExp( '/2016-01-01T00:00:00\+\d{4}/', diff --git a/tests/EntityFactory/AggregateFactoryTest.php b/tests/EntityFactory/AggregateFactoryTest.php index 64fccee..2b0d26b 100644 --- a/tests/EntityFactory/AggregateFactoryTest.php +++ b/tests/EntityFactory/AggregateFactoryTest.php @@ -20,11 +20,8 @@ Exception\InvalidArgumentException, }; use Innmind\Immutable\{ - SetInterface, Set, - MapInterface, Map, - Stream, }; use PHPUnit\Framework\TestCase; @@ -134,14 +131,14 @@ public function testThrowWhenTryingToBuildNonAggregate() (new AggregateFactory)( $this->createMock(IdentityInterface::class), $this->createMock(Entity::class), - new Map('string', 'mixed') + Map::of('string', 'mixed') ); } public function testThrowWhenTryingToBuildWithInvalidData() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 3 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 3 must be of type Map'); (new AggregateFactory)( $this->createMock(IdentityInterface::class), @@ -150,7 +147,7 @@ public function testThrowWhenTryingToBuildWithInvalidData() new Identity('uuid', 'foo'), Set::of('string', 'Label') ), - new Map('string', 'variable') + Map::of('string', 'variable') ); } } diff --git a/tests/EntityFactory/EntityFactoryTest.php b/tests/EntityFactory/EntityFactoryTest.php index 5343dd5..a133084 100644 --- a/tests/EntityFactory/EntityFactoryTest.php +++ b/tests/EntityFactory/EntityFactoryTest.php @@ -30,9 +30,9 @@ }; use Innmind\Immutable\{ Map, - SetInterface, Set, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class EntityFactoryTest extends TestCase @@ -216,21 +216,22 @@ public function testMake() ); $this->assertInstanceOf( - SetInterface::class, + Set::class, $entities ); $this->assertCount(2, $entities); + $entities = unwrap($entities); $this->assertInstanceOf( (string) $aggregate->class(), - $entities->current() + \current($entities) ); - $entities->next(); + \next($entities); $this->assertInstanceOf( (string) $relationship->class(), - $entities->current() + \current($entities) ); - $entities->rewind(); - $aggregateRoot = $entities->current(); + \reset($entities); + $aggregateRoot = \current($entities); $this->assertInstanceOf(Uuid::class, $aggregateRoot->uuid); $this->assertSame( '11111111-1111-1111-1111-111111111111', @@ -264,8 +265,8 @@ public function testMake() ); $this->assertSame('foo', $aggregateRoot->rel->child->content); $this->assertNull($aggregateRoot->rel->child->empty); - $entities->next(); - $rel = $entities->current(); + \next($entities); + $rel = \current($entities); $this->assertInstanceOf((string) $relationship->class(), $rel); $this->assertInstanceOf(Uuid::class, $rel->uuid); $this->assertSame( @@ -293,7 +294,9 @@ public function testMake() ); $this->assertTrue( - ($this->make)($result, $variables)->equals($entities) + ($this->make)($result, $variables)->equals( + ($this->make)($result, $variables), + ), ); } @@ -344,11 +347,11 @@ public function testMakeWhenEntityNotFound() public function testThrowWhenInvalidVariableMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); ($this->make)( $this->createMock(ResultInterface::class), - new Map('string', 'object') + Map::of('string', 'object') ); } } diff --git a/tests/EntityFactory/RelationshipFactoryTest.php b/tests/EntityFactory/RelationshipFactoryTest.php index 67f1c95..e3cabcd 100644 --- a/tests/EntityFactory/RelationshipFactoryTest.php +++ b/tests/EntityFactory/RelationshipFactoryTest.php @@ -22,13 +22,7 @@ EntityFactory, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - Map, - MapInterface, - SetInterface, - Set, - Stream, -}; +use Innmind\Immutable\Map; use PHPUnit\Framework\TestCase; class RelationshipFactoryTest extends TestCase @@ -97,14 +91,14 @@ public function testThrowWhenTryingToBuildNonRelationship() (new RelationshipFactory(new Generators))( $this->createMock(IdentityInterface::class), $this->createMock(Entity::class), - new Map('string', 'mixed') + Map::of('string', 'mixed') ); } public function testThrowWhenTryingToBuildWithInvalidData() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 3 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 3 must be of type Map'); (new RelationshipFactory(new Generators))( $this->createMock(IdentityInterface::class), @@ -115,7 +109,7 @@ public function testThrowWhenTryingToBuildWithInvalidData() new RelationshipEdge('start', Uuid::class, 'target'), new RelationshipEdge('end', Uuid::class, 'target') ), - new Map('string', 'variable') + Map::of('string', 'variable') ); } } diff --git a/tests/Identity/GeneratorsTest.php b/tests/Identity/GeneratorsTest.php index 443689a..4489cea 100644 --- a/tests/Identity/GeneratorsTest.php +++ b/tests/Identity/GeneratorsTest.php @@ -9,10 +9,7 @@ Uuid, Generator\UuidGenerator, }; -use Innmind\Immutable\{ - Map, - Exception\InvalidArgumentException, -}; +use Innmind\Immutable\Map; use PHPUnit\Framework\TestCase; class GeneratorsTest extends TestCase @@ -42,8 +39,9 @@ public function testRegisterGenerator() public function testThrowWhenInvalidMap() { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('Argument 1 must be of type Map'); - new Generators(new Map('string', 'object')); + new Generators(Map::of('string', 'object')); } } diff --git a/tests/IdentityMatchTest.php b/tests/IdentityMatchTest.php index 11fdf57..90b3ade 100644 --- a/tests/IdentityMatchTest.php +++ b/tests/IdentityMatchTest.php @@ -17,7 +17,7 @@ public function testInterface() { $identity = new IdentityMatch( $query = new Query, - $variables = new Map('string', Entity::class) + $variables = Map::of('string', Entity::class) ); $this->assertSame($query, $identity->query()); @@ -27,11 +27,11 @@ public function testInterface() public function testThrowWhenInvalidVariableMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); new IdentityMatch( new Query, - new Map('int', 'int') + Map::of('int', 'int') ); } } diff --git a/tests/Metadata/Aggregate/Child/RelationshipTest.php b/tests/Metadata/Aggregate/Child/RelationshipTest.php index 207fa5b..af8f4b9 100644 --- a/tests/Metadata/Aggregate/Child/RelationshipTest.php +++ b/tests/Metadata/Aggregate/Child/RelationshipTest.php @@ -11,10 +11,7 @@ Type, Exception\DomainException, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use PHPUnit\Framework\TestCase; class RelationshipTest extends TestCase @@ -34,7 +31,7 @@ public function testInterface() $this->assertSame($relationshipType, $valueObjectRelationship->type()); $this->assertSame('relationship', $valueObjectRelationship->property()); $this->assertSame('node', $valueObjectRelationship->childProperty()); - $this->assertInstanceOf(MapInterface::class, $valueObjectRelationship->properties()); + $this->assertInstanceOf(Map::class, $valueObjectRelationship->properties()); $this->assertSame('string', (string) $valueObjectRelationship->properties()->keyType()); $this->assertSame(Property::class, (string) $valueObjectRelationship->properties()->valueType()); $this->assertSame(1, $valueObjectRelationship->properties()->count()); diff --git a/tests/Metadata/Aggregate/ChildTest.php b/tests/Metadata/Aggregate/ChildTest.php index 25efb5b..7928a51 100644 --- a/tests/Metadata/Aggregate/ChildTest.php +++ b/tests/Metadata/Aggregate/ChildTest.php @@ -12,11 +12,10 @@ Type, }; use Innmind\Immutable\{ - SetInterface, Set, - MapInterface, Map, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class ChildTest extends TestCase @@ -37,11 +36,11 @@ public function testInterface() ); $this->assertSame($className, $valueObject->class()); - $this->assertInstanceOf(SetInterface::class, $valueObject->labels()); + $this->assertInstanceOf(Set::class, $valueObject->labels()); $this->assertSame('string', (string) $valueObject->labels()->type()); - $this->assertSame(['LabelA', 'LabelB'], $valueObject->labels()->toPrimitive()); + $this->assertSame(['LabelA', 'LabelB'], unwrap($valueObject->labels())); $this->assertSame($valueObjectRelationship, $valueObject->relationship()); - $this->assertInstanceOf(MapInterface::class, $valueObject->properties()); + $this->assertInstanceOf(Map::class, $valueObject->properties()); $this->assertSame('string', (string) $valueObject->properties()->keyType()); $this->assertSame(Property::class, (string) $valueObject->properties()->valueType()); $this->assertSame(1, $valueObject->properties()->count()); diff --git a/tests/Metadata/AggregateTest.php b/tests/Metadata/AggregateTest.php index 8ba3cd0..d5ae2f2 100644 --- a/tests/Metadata/AggregateTest.php +++ b/tests/Metadata/AggregateTest.php @@ -15,11 +15,10 @@ Repository\Repository, }; use Innmind\Immutable\{ - SetInterface, Set, - MapInterface, Map, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class AggregateTest extends TestCase @@ -52,14 +51,14 @@ public function testInterface() $this->assertSame($identity, $aggregateRoot->identity()); $this->assertSame(Repository::class, (string) $aggregateRoot->repository()); $this->assertSame(AggregateFactory::class, (string) $aggregateRoot->factory()); - $this->assertInstanceOf(SetInterface::class, $aggregateRoot->labels()); + $this->assertInstanceOf(Set::class, $aggregateRoot->labels()); $this->assertSame('string', (string) $aggregateRoot->labels()->type()); - $this->assertSame(['LabelA'], $aggregateRoot->labels()->toPrimitive()); - $this->assertInstanceOf(MapInterface::class, $aggregateRoot->children()); + $this->assertSame(['LabelA'], unwrap($aggregateRoot->labels())); + $this->assertInstanceOf(Map::class, $aggregateRoot->children()); $this->assertSame('string', (string) $aggregateRoot->children()->keyType()); $this->assertSame(Child::class, (string) $aggregateRoot->children()->valueType()); $this->assertCount(1, $aggregateRoot->children()); - $this->assertSame($vo, $aggregateRoot->children()->current()); + $this->assertSame($vo, $aggregateRoot->children()->values()->first()); $this->assertCount(1, $aggregateRoot->properties()); $this->assertTrue($aggregateRoot->properties()->contains('foo')); } diff --git a/tests/Query/PropertiesMatchTest.php b/tests/Query/PropertiesMatchTest.php index 3738e3b..db19d21 100644 --- a/tests/Query/PropertiesMatchTest.php +++ b/tests/Query/PropertiesMatchTest.php @@ -12,8 +12,8 @@ class PropertiesMatchTest extends TestCase public function testInterface() { $match = new PropertiesMatch( - $properties = new Map('string', 'string'), - $parameters = new Map('string', 'mixed') + $properties = Map::of('string', 'string'), + $parameters = Map::of('string', 'mixed') ); $this->assertSame($properties, $match->properties()); @@ -23,13 +23,13 @@ public function testInterface() public function testMerge() { $match = new PropertiesMatch( - (new Map('string', 'string'))->put('foo', 'bar'), - (new Map('string', 'mixed'))->put('bar', 'baz') + (Map::of('string', 'string'))->put('foo', 'bar'), + (Map::of('string', 'mixed'))->put('bar', 'baz') ); $match2 = $match->merge( new PropertiesMatch( - (new Map('string', 'string'))->put('bar', 'baz'), - (new Map('string', 'mixed'))->put('baz', 'foobar') + (Map::of('string', 'string'))->put('bar', 'baz'), + (Map::of('string', 'mixed'))->put('baz', 'foobar') ) ); @@ -48,22 +48,22 @@ public function testMerge() public function testThrowWhenInvalidPropertyMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 1 must be of type Map'); new PropertiesMatch( - new Map('int', 'int'), - new Map('string', 'mixed') + Map::of('int', 'int'), + Map::of('string', 'mixed') ); } public function testThrowWhenInvalidParameterMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); new PropertiesMatch( - new Map('string', 'string'), - new Map('string', 'variable') + Map::of('string', 'string'), + Map::of('string', 'variable') ); } } diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index 456ab86..af57f8e 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -16,7 +16,7 @@ public function testInterface() { $where = new Where( 'foo', - $parameters = new Map('string', 'mixed') + $parameters = Map::of('string', 'mixed') ); $this->assertSame('foo', $where->cypher()); @@ -27,29 +27,29 @@ public function testThrowWhenEmptyCypher() { $this->expectException(DomainException::class); - new Where('', new Map('string', 'mixed')); + new Where('', Map::of('string', 'mixed')); } public function testThrowWhenInvalidParameterMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); - new Where('foo', new Map('string', 'variable')); + new Where('foo', Map::of('string', 'variable')); } public function testAnd() { $where = new Where( 'foo', - (new Map('string', 'mixed')) + (Map::of('string', 'mixed')) ->put('foo', 'bar') ); $where2 = $where->and( new Where( 'bar', - (new Map('string', 'mixed')) + (Map::of('string', 'mixed')) ->put('bar', 'baz') ) ); @@ -68,14 +68,14 @@ public function testOr() { $where = new Where( 'foo', - (new Map('string', 'mixed')) + (Map::of('string', 'mixed')) ->put('foo', 'bar') ); $where2 = $where->or( new Where( 'bar', - (new Map('string', 'mixed')) + (Map::of('string', 'mixed')) ->put('bar', 'baz') ) ); @@ -95,7 +95,7 @@ public function testNot() $where = new Where( 'foo', - (new Map('string', 'mixed')) + (Map::of('string', 'mixed')) ->put('foo', 'bar') ); diff --git a/tests/Repository/RepositoryTest.php b/tests/Repository/RepositoryTest.php index 7027eba..30a4bad 100644 --- a/tests/Repository/RepositoryTest.php +++ b/tests/Repository/RepositoryTest.php @@ -39,14 +39,12 @@ use Innmind\EventBus\EventBus; use function Innmind\HttpTransport\bootstrap as http; use Innmind\Url\Url; -use Innmind\TimeContinuum\TimeContinuum\Earth; +use Innmind\TimeContinuum\Earth\Clock as Earth; use Innmind\Specification\Sign; use Innmind\Immutable\{ - SetInterface, Set, Map, }; -use GuzzleHttp\Client; use PHPUnit\Framework\TestCase; class RepositoryTest extends TestCase @@ -66,7 +64,7 @@ public function setUp(): void $conn = dbal( http()['default'](), new Earth, - Url::fromString('http://neo4j:ci@localhost:7474/') + Url::of('http://neo4j:ci@localhost:7474/') ); $container = new Container; $entityFactory = new EntityFactory( @@ -176,7 +174,7 @@ public function testAll() $this->uow->commit(); $all = $this->repository->all(); - $this->assertInstanceOf(SetInterface::class, $all); + $this->assertInstanceOf(Set::class, $all); $this->assertSame('object', (string) $all->type()); $this->assertSame(2, $all->size()); $this->assertTrue($all->contains($entity)); @@ -209,7 +207,7 @@ public function testMatching() $entities = $this->repository->matching(new Property('content', Sign::contains(), 'foo.*')); - $this->assertInstanceOf(SetInterface::class, $entities); + $this->assertInstanceOf(Set::class, $entities); $this->assertSame('object', (string) $entities->type()); $this->assertSame(2, $entities->size()); $this->assertTrue($entities->contains($entity)); diff --git a/tests/RepositoryFactoryTest.php b/tests/RepositoryFactoryTest.php index a6ec17f..8cdc78b 100644 --- a/tests/RepositoryFactoryTest.php +++ b/tests/RepositoryFactoryTest.php @@ -95,7 +95,7 @@ public function testRegisterRepositoryAtConstruct() public function testThrowWhenInvalidRepositoriesMapKey() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 4 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 4 must be of type Map'); new RepositoryFactory( new UnitOfWork( @@ -114,14 +114,14 @@ public function testThrowWhenInvalidRepositoriesMapKey() ), new MatchTranslator, new SpecificationTranslator, - new Map('foo', RepositoryInterface::class) + Map::of('foo', RepositoryInterface::class) ); } public function testThrowWhenInvalidRepositoriesMapValue() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 4 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 4 must be of type Map'); new RepositoryFactory( new UnitOfWork( @@ -140,7 +140,7 @@ public function testThrowWhenInvalidRepositoriesMapValue() ), new MatchTranslator, new SpecificationTranslator, - new Map(Entity::class, 'foo') + Map::of(Entity::class, 'foo') ); } } diff --git a/tests/Translation/IdentityMatch/AggregateTranslatorTest.php b/tests/Translation/IdentityMatch/AggregateTranslatorTest.php index 828f1c2..906f011 100644 --- a/tests/Translation/IdentityMatch/AggregateTranslatorTest.php +++ b/tests/Translation/IdentityMatch/AggregateTranslatorTest.php @@ -19,7 +19,6 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; @@ -82,7 +81,7 @@ public function testTranslate() 'foobar', $identityMatch->query()->parameters()->get('entity_identity')->value() ); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() diff --git a/tests/Translation/IdentityMatch/DelegationTranslatorTest.php b/tests/Translation/IdentityMatch/DelegationTranslatorTest.php index e2f338f..722ac3a 100644 --- a/tests/Translation/IdentityMatch/DelegationTranslatorTest.php +++ b/tests/Translation/IdentityMatch/DelegationTranslatorTest.php @@ -21,7 +21,6 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; @@ -83,7 +82,7 @@ public function testTranslateAggregate() 'foobar', $identityMatch->query()->parameters()->get('entity_identity')->value() ); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() @@ -125,7 +124,7 @@ public function testTranslateRelationship() 'foobar', $identityMatch->query()->parameters()->get('entity_identity')->value() ); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() @@ -141,8 +140,8 @@ public function testTranslateRelationship() public function testThrowWhenGivingInvalidTranslatorsMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 1 must be of type Map'); - new DelegationTranslator(new Map('int', 'int')); + new DelegationTranslator(Map::of('int', 'int')); } } diff --git a/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php b/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php index 3439709..ba634d2 100644 --- a/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php +++ b/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php @@ -18,10 +18,7 @@ IdentityMatch, Type, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use PHPUnit\Framework\TestCase; class RelationshipTranslatorTest extends TestCase @@ -64,7 +61,7 @@ public function testTranslate() 'foobar', $identityMatch->query()->parameters()->get('entity_identity')->value() ); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() diff --git a/tests/Translation/Match/AggregateTranslatorTest.php b/tests/Translation/Match/AggregateTranslatorTest.php index f3a5ecd..3f9830b 100644 --- a/tests/Translation/Match/AggregateTranslatorTest.php +++ b/tests/Translation/Match/AggregateTranslatorTest.php @@ -18,7 +18,6 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; @@ -73,7 +72,7 @@ public function testTranslate() $identityMatch->query()->cypher() ); $this->assertSame(0, $identityMatch->query()->parameters()->count()); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() diff --git a/tests/Translation/Match/DelegationTranslatorTest.php b/tests/Translation/Match/DelegationTranslatorTest.php index 7ba7125..9c98cd9 100644 --- a/tests/Translation/Match/DelegationTranslatorTest.php +++ b/tests/Translation/Match/DelegationTranslatorTest.php @@ -20,7 +20,6 @@ Type, }; use Innmind\Immutable\{ - MapInterface, Map, Set, }; @@ -74,7 +73,7 @@ public function testTranslateAggregate() $identityMatch->query()->cypher() ); $this->assertCount(0, $identityMatch->query()->parameters()); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() @@ -108,7 +107,7 @@ public function testTranslateRelationship() $identityMatch->query()->cypher() ); $this->assertCount(0, $identityMatch->query()->parameters()); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() @@ -124,8 +123,8 @@ public function testTranslateRelationship() public function testThrowWhenGivingInvalidTranslatorsMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 1 must be of type Map'); - new DelegationTranslator(new Map('int', 'int')); + new DelegationTranslator(Map::of('int', 'int')); } } diff --git a/tests/Translation/Match/RelationshipTranslatorTest.php b/tests/Translation/Match/RelationshipTranslatorTest.php index b7d9a25..e6f2465 100644 --- a/tests/Translation/Match/RelationshipTranslatorTest.php +++ b/tests/Translation/Match/RelationshipTranslatorTest.php @@ -17,10 +17,7 @@ IdentityMatch, Type, }; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; use PHPUnit\Framework\TestCase; class RelationshipTranslatorTest extends TestCase @@ -55,7 +52,7 @@ public function testTranslate() $identityMatch->query()->cypher() ); $this->assertSame(0, $identityMatch->query()->parameters()->count()); - $this->assertInstanceOf(MapInterface::class, $identityMatch->variables()); + $this->assertInstanceOf(Map::class, $identityMatch->variables()); $this->assertSame( 'string', (string) $identityMatch->variables()->keyType() diff --git a/tests/Translation/Result/AggregateTranslatorTest.php b/tests/Translation/Result/AggregateTranslatorTest.php index 2975520..180496d 100644 --- a/tests/Translation/Result/AggregateTranslatorTest.php +++ b/tests/Translation/Result/AggregateTranslatorTest.php @@ -24,11 +24,13 @@ Result as ResultInterface, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; +use function Innmind\Immutable\{ + first, + unwrap, +}; use PHPUnit\Framework\TestCase; class AggregateTranslatorTest extends TestCase @@ -161,32 +163,32 @@ public function testTranslate() ]) ); - $this->assertInstanceOf(SetInterface::class, $data); - $this->assertSame(MapInterface::class, (string) $data->type()); + $this->assertInstanceOf(Set::class, $data); + $this->assertSame(Map::class, (string) $data->type()); $this->assertCount(1, $data); - $data = $data->current(); + $data = first($data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertCount(4, $data); $this->assertSame( ['id', 'created', 'rel', 'rel2'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); $this->assertSame(42, $data->get('id')); $this->assertSame('2016-01-01T00:00:00+0200', $data->get('created')); - $this->assertInstanceOf(MapInterface::class, $data->get('rel')); + $this->assertInstanceOf(Map::class, $data->get('rel')); $this->assertSame('string', (string) $data->get('rel')->keyType()); $this->assertSame('mixed', (string) $data->get('rel')->valueType()); $this->assertSame( ['created', 'child'], - $data->get('rel')->keys()->toPrimitive() + unwrap($data->get('rel')->keys()) ); $this->assertSame( '2016-01-01T00:00:00+0200', $data->get('rel')->get('created') ); $this->assertInstanceOf( - MapInterface::class, + Map::class, $data->get('rel')->get('child') ); $this->assertSame( @@ -199,26 +201,26 @@ public function testTranslate() ); $this->assertSame( ['content'], - $data->get('rel')->get('child')->keys()->toPrimitive() + unwrap($data->get('rel')->get('child')->keys()) ); $this->assertSame( 'foo', $data->get('rel')->get('child')->get('content') ); - $this->assertInstanceOf(MapInterface::class, $data->get('rel2')); + $this->assertInstanceOf(Map::class, $data->get('rel2')); $this->assertSame('string', (string) $data->get('rel2')->keyType()); $this->assertSame('mixed', (string) $data->get('rel2')->valueType()); $this->assertCount(2, $data->get('rel2')); $this->assertSame( ['created', 'child'], - $data->get('rel2')->keys()->toPrimitive() + unwrap($data->get('rel2')->keys()) ); $this->assertSame( '2016-01-03T00:00:00+0200', $data->get('rel2')->get('created') ); $this->assertInstanceOf( - MapInterface::class, + Map::class, $data->get('rel2')->get('child') ); $this->assertSame( @@ -231,7 +233,7 @@ public function testTranslate() ); $this->assertSame( ['content'], - $data->get('rel2')->get('child')->keys()->toPrimitive() + unwrap($data->get('rel2')->get('child')->keys()) ); $this->assertSame( 'baz', @@ -314,21 +316,22 @@ public function testTranslateMultipleNodes() ]) ); - $this->assertInstanceOf(SetInterface::class, $data); + $this->assertInstanceOf(Set::class, $data); $this->assertCount(2, $data); + $data = unwrap($data); $this->assertSame( ['id', 'created'], - $data->current()->keys()->toPrimitive() + unwrap(\current($data)->keys()) ); - $this->assertSame(42, $data->current()->get('id')); - $this->assertSame('2016-01-01T00:00:00+0200', $data->current()->get('created')); - $data->next(); + $this->assertSame(42, \current($data)->get('id')); + $this->assertSame('2016-01-01T00:00:00+0200', \current($data)->get('created')); + \next($data); $this->assertSame( ['id', 'created'], - $data->current()->keys()->toPrimitive() + unwrap(\current($data)->keys()) ); - $this->assertSame(43, $data->current()->get('id')); - $this->assertSame('2016-01-02T00:00:00+0200', $data->current()->get('created')); + $this->assertSame(43, \current($data)->get('id')); + $this->assertSame('2016-01-02T00:00:00+0200', \current($data)->get('created')); } public function testThrowWhenMoreThanOneRelationshipFound() diff --git a/tests/Translation/Result/RelationshipTranslatorTest.php b/tests/Translation/Result/RelationshipTranslatorTest.php index 999fde7..063d2a5 100644 --- a/tests/Translation/Result/RelationshipTranslatorTest.php +++ b/tests/Translation/Result/RelationshipTranslatorTest.php @@ -23,9 +23,12 @@ Result as ResultInterface, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, + Set, +}; +use function Innmind\Immutable\{ + unwrap, + first, }; use PHPUnit\Framework\TestCase; @@ -99,15 +102,15 @@ public function testTranslate() ]) ); - $this->assertInstanceOf(SetInterface::class, $data); - $this->assertSame(MapInterface::class, (string) $data->type()); + $this->assertInstanceOf(Set::class, $data); + $this->assertSame(Map::class, (string) $data->type()); $this->assertCount(1, $data); - $data = $data->current(); + $data = first($data); $this->assertSame('string', (string) $data->keyType()); $this->assertSame('mixed', (string) $data->valueType()); $this->assertSame( ['id', 'start', 'end', 'created'], - $data->keys()->toPrimitive() + unwrap($data->keys()), ); $this->assertSame(42, $data->get('id')); $this->assertSame(24, $data->get('start')); @@ -235,25 +238,26 @@ public function testTranslateMultipleRelationships() ]) ); - $this->assertInstanceOf(SetInterface::class, $data); + $this->assertInstanceOf(Set::class, $data); $this->assertCount(2, $data); + $data = unwrap($data); $this->assertSame( ['id', 'start', 'end', 'created'], - $data->current()->keys()->toPrimitive() + unwrap(\current($data)->keys()) ); - $this->assertSame(42, $data->current()->get('id')); - $this->assertSame(24, $data->current()->get('start')); - $this->assertSame(66, $data->current()->get('end')); - $this->assertSame('2016-01-03T00:00:00+0200', $data->current()->get('created')); - $data->next(); + $this->assertSame(42, \current($data)->get('id')); + $this->assertSame(24, \current($data)->get('start')); + $this->assertSame(66, \current($data)->get('end')); + $this->assertSame('2016-01-03T00:00:00+0200', \current($data)->get('created')); + \next($data); $this->assertSame( ['id', 'start', 'end', 'created'], - $data->current()->keys()->toPrimitive() + unwrap(\current($data)->keys()), ); - $this->assertSame(43, $data->current()->get('id')); - $this->assertSame(24, $data->current()->get('start')); - $this->assertSame(66, $data->current()->get('end')); - $this->assertSame('2016-01-04T00:00:00+0200', $data->current()->get('created')); + $this->assertSame(43, \current($data)->get('id')); + $this->assertSame(24, \current($data)->get('start')); + $this->assertSame(66, \current($data)->get('end')); + $this->assertSame('2016-01-04T00:00:00+0200', \current($data)->get('created')); } public function testThrowWhenTranslatingNonSupportedEntity() diff --git a/tests/Translation/ResultTranslatorTest.php b/tests/Translation/ResultTranslatorTest.php index c51ed72..796c047 100644 --- a/tests/Translation/ResultTranslatorTest.php +++ b/tests/Translation/ResultTranslatorTest.php @@ -22,11 +22,13 @@ Result as ResultInterface, }; use Innmind\Immutable\{ - MapInterface, Map, - SetInterface, Set, }; +use function Innmind\Immutable\{ + unwrap, + first, +}; use PHPUnit\Framework\TestCase; class ResultTranslatorTest extends TestCase @@ -183,76 +185,76 @@ public function testTranslate() ], ]], ]), - (new Map('string', Entity::class)) + (Map::of('string', Entity::class)) ->put('n', $aggregate) ->put('r', $relationship) ); - $this->assertInstanceOf(MapInterface::class, $data); + $this->assertInstanceOf(Map::class, $data); $this->assertSame('string', (string) $data->keyType()); - $this->assertSame(SetInterface::class, (string) $data->valueType()); + $this->assertSame(Set::class, (string) $data->valueType()); $this->assertSame( ['n', 'r'], - $data->keys()->toPrimitive() + unwrap($data->keys()) ); - $this->assertCount(4, $data->get('n')->current()); + $this->assertCount(4, first($data->get('n'))); $this->assertSame( ['id', 'created', 'rel', 'rel2'], - $data->get('n')->current()->keys()->toPrimitive() + unwrap(first($data->get('n'))->keys()) ); - $this->assertSame(42, $data->get('n')->current()->get('id')); - $this->assertSame('2016-01-01T00:00:00+0200', $data->get('n')->current()->get('created')); - $this->assertInstanceOf(MapInterface::class, $data->get('n')->current()->get('rel')); + $this->assertSame(42, first($data->get('n'))->get('id')); + $this->assertSame('2016-01-01T00:00:00+0200', first($data->get('n'))->get('created')); + $this->assertInstanceOf(Map::class, first($data->get('n'))->get('rel')); $this->assertSame( ['created', 'child'], - $data->get('n')->current()->get('rel')->keys()->toPrimitive() + unwrap(first($data->get('n'))->get('rel')->keys()) ); $this->assertSame( '2016-01-01T00:00:00+0200', - $data->get('n')->current()->get('rel')->get('created') + first($data->get('n'))->get('rel')->get('created') ); $this->assertInstanceOf( - MapInterface::class, - $data->get('n')->current()->get('rel')->get('child') + Map::class, + first($data->get('n'))->get('rel')->get('child') ); $this->assertSame( ['content'], - $data->get('n')->current()->get('rel')->get('child')->keys()->toPrimitive() + unwrap(first($data->get('n'))->get('rel')->get('child')->keys()) ); $this->assertSame( 'foo', - $data->get('n')->current()->get('rel')->get('child')->get('content') + first($data->get('n'))->get('rel')->get('child')->get('content') ); - $this->assertInstanceOf(MapInterface::class, $data->get('n')->current()->get('rel2')); - $this->assertSame(2, $data->get('n')->current()->get('rel2')->count()); + $this->assertInstanceOf(Map::class, first($data->get('n'))->get('rel2')); + $this->assertSame(2, first($data->get('n'))->get('rel2')->count()); $this->assertSame( ['created', 'child'], - $data->get('n')->current()->get('rel2')->keys()->toPrimitive() + unwrap(first($data->get('n'))->get('rel2')->keys()) ); $this->assertSame( '2016-01-03T00:00:00+0200', - $data->get('n')->current()->get('rel2')->get('created') + first($data->get('n'))->get('rel2')->get('created') ); $this->assertInstanceOf( - MapInterface::class, - $data->get('n')->current()->get('rel2')->get('child') + Map::class, + first($data->get('n'))->get('rel2')->get('child') ); $this->assertSame( ['content'], - $data->get('n')->current()->get('rel2')->get('child')->keys()->toPrimitive() + unwrap(first($data->get('n'))->get('rel2')->get('child')->keys()) ); $this->assertSame( 'baz', - $data->get('n')->current()->get('rel2')->get('child')->get('content') + first($data->get('n'))->get('rel2')->get('child')->get('content') ); $this->assertSame( ['id', 'start', 'end', 'created'], - $data->get('r')->current()->keys()->toPrimitive() + unwrap(first($data->get('r'))->keys()) ); - $this->assertSame(42, $data->get('r')->current()->get('id')); - $this->assertSame(24, $data->get('r')->current()->get('start')); - $this->assertSame(66, $data->get('r')->current()->get('end')); - $this->assertSame('2016-01-03T00:00:00+0200', $data->get('r')->current()->get('created')); + $this->assertSame(42, first($data->get('r'))->get('id')); + $this->assertSame(24, first($data->get('r'))->get('start')); + $this->assertSame(66, first($data->get('r'))->get('end')); + $this->assertSame('2016-01-03T00:00:00+0200', first($data->get('r'))->get('created')); } public function testTranslateWithoutExpectedVariable() @@ -281,7 +283,7 @@ public function testTranslateWithoutExpectedVariable() ], ]], ]), - (new Map('string', Entity::class)) + (Map::of('string', Entity::class)) ->put('n', $aggregate) ->put('r', $relationship) ); @@ -292,17 +294,17 @@ public function testTranslateWithoutExpectedVariable() public function testThrowWhenEmptyInvalidMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); - new ResultTranslator(new Map('string', 'callable')); + $this->expectExceptionMessage('Argument 1 must be of type Map'); + new ResultTranslator(Map::of('string', 'callable')); } public function testThrowWhenEmptyInvalidVariableMap() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 2 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 2 must be of type Map'); (new ResultTranslator)( $this->createMock(ResultInterface::class), - new Map('string', 'object') + Map::of('string', 'object') ); } } diff --git a/tests/Translation/Specification/DelegationTranslatorTest.php b/tests/Translation/Specification/DelegationTranslatorTest.php index 3c0801c..37e600f 100644 --- a/tests/Translation/Specification/DelegationTranslatorTest.php +++ b/tests/Translation/Specification/DelegationTranslatorTest.php @@ -53,7 +53,7 @@ public function testTranslate() return new IdentityMatch( $this->createMock(Query::class), - new Map('string', Entity::class) + Map::of('string', Entity::class) ); })); $mock2 = $this->createMock(SpecificationTranslator::class); @@ -66,7 +66,7 @@ public function testTranslate() return new IdentityMatch( $this->createMock(Query::class), - new Map('string', Entity::class) + Map::of('string', Entity::class) ); })); @@ -110,9 +110,9 @@ public function testTranslate() public function testThrowWhenInjectingInvalidTranslators() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 1 must be of type Map'); - new DelegationTranslator(new Map('int', 'int')); + new DelegationTranslator(Map::of('int', 'int')); } public function testThrowWhenSpecificationNotApplicableToAggregate() diff --git a/tests/Translation/Specification/Validator/DelegationValidatorTest.php b/tests/Translation/Specification/Validator/DelegationValidatorTest.php index 5e33faf..4035422 100644 --- a/tests/Translation/Specification/Validator/DelegationValidatorTest.php +++ b/tests/Translation/Specification/Validator/DelegationValidatorTest.php @@ -221,8 +221,8 @@ public function testDoesntValidateRelationship() public function testThrowWhenInjectingInvalidValidator() { $this->expectException(\TypeError::class); - $this->expectExceptionMessage('Argument 1 must be of type MapInterface'); + $this->expectExceptionMessage('Argument 1 must be of type Map'); - new DelegationValidator(new Map('int', 'int')); + new DelegationValidator(Map::of('int', 'int')); } } diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php index e00d6cd..13afc1f 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php @@ -20,10 +20,10 @@ use Fixtures\Innmind\Neo4j\ONM\Specification\Property; use Innmind\Specification\Sign; use Innmind\Immutable\{ - MapInterface, Map, Set, }; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class AggregateVisitorTest extends TestCase @@ -79,7 +79,7 @@ public function testVisit() ->and(new Property('rel.child.empty', Sign::equality(), null)) ); - $this->assertInstanceOf(MapInterface::class, $mapping); + $this->assertInstanceOf(Map::class, $mapping); $this->assertSame('string', (string) $mapping->keyType()); $this->assertSame( PropertiesMatch::class, @@ -87,7 +87,7 @@ public function testVisit() ); $this->assertSame( ['entity', 'entity_rel', 'entity_rel_child'], - $mapping->keys()->toPrimitive() + unwrap($mapping->keys()), ); $this->assertCount(2, $mapping->get('entity')->properties()); $this->assertSame('{entity_empty}', $mapping->get('entity')->properties()->get('empty')); diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php index 7a3210e..d77d58c 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php @@ -22,10 +22,8 @@ }; use Fixtures\Innmind\Neo4j\ONM\Specification\Property; use Innmind\Specification\Sign; -use Innmind\Immutable\{ - MapInterface, - Map, -}; +use Innmind\Immutable\Map; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class RelationshipVisitorTest extends TestCase @@ -62,7 +60,7 @@ public function testVisit() ->and(new Property('end', Sign::equality(), 'bar')) ); - $this->assertInstanceOf(MapInterface::class, $mapping); + $this->assertInstanceOf(Map::class, $mapping); $this->assertSame('string', (string) $mapping->keyType()); $this->assertSame( PropertiesMatch::class, @@ -70,7 +68,7 @@ public function testVisit() ); $this->assertSame( ['entity', 'start', 'end'], - $mapping->keys()->toPrimitive() + unwrap($mapping->keys()), ); $this->assertSame('{entity_empty}', $mapping->get('entity')->properties()->get('empty')); $this->assertSame('{entity_created}', $mapping->get('entity')->properties()->get('created')); diff --git a/tests/Type/PointInTimeTypeTest.php b/tests/Type/PointInTimeTypeTest.php index 0df833a..e486691 100644 --- a/tests/Type/PointInTimeTypeTest.php +++ b/tests/Type/PointInTimeTypeTest.php @@ -9,10 +9,10 @@ Exception\InvalidArgumentException, }; use Innmind\TimeContinuum\{ - PointInTimeInterface, - PointInTime\Earth\PointInTime, - PointInTime\Earth\Now, - Format\RSS, + PointInTime as PointInTimeInterface, + Earth\PointInTime\PointInTime, + Earth\PointInTime\Now, + Earth\Format\RSS, }; use PHPUnit\Framework\TestCase; diff --git a/tests/Type/SetTypeTest.php b/tests/Type/SetTypeTest.php index 2c5f91f..93a0c54 100644 --- a/tests/Type/SetTypeTest.php +++ b/tests/Type/SetTypeTest.php @@ -10,10 +10,8 @@ Exception\RecursiveTypeDeclaration, Exception\InvalidArgumentException, }; -use Innmind\Immutable\{ - SetInterface, - Set, -}; +use Innmind\Immutable\Set; +use function Innmind\Immutable\unwrap; use PHPUnit\Framework\TestCase; class SetTypeTest extends TestCase @@ -49,7 +47,7 @@ public function testForDatabase() $this->assertSame( ['foo'], - $type->forDatabase((new Set('string'))->add('foo')) + $type->forDatabase((Set::of('string'))->add('foo')) ); $this->assertSame( @@ -58,7 +56,7 @@ public function testForDatabase() ); $this->assertSame( [''], - SetType::nullable(new StringType, 'string')->forDatabase((new Set('string'))->add('')) + SetType::nullable(new StringType, 'string')->forDatabase((Set::of('string'))->add('')) ); } @@ -98,7 +96,7 @@ public function isNullable(): bool public function testThrowWhenInvalidType() { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The set must be an instance of SetInterface'); + $this->expectExceptionMessage('The set must be an instance of Set'); SetType::nullable(new StringType, 'string')->forDatabase(['']); } @@ -106,27 +104,27 @@ public function testThrowWhenInvalidType() public function testThrowWhenInvalidSetType() { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The set must be an instance of SetInterface'); + $this->expectExceptionMessage('The set must be an instance of Set'); - SetType::nullable(new StringType, 'string')->forDatabase(new Set('int')); + SetType::nullable(new StringType, 'string')->forDatabase(Set::of('int')); } public function testFromDatabase() { $type = new SetType(new StringType, 'string'); - $this->assertInstanceOf(SetInterface::class, $type->fromDatabase(['foo'])); + $this->assertInstanceOf(Set::class, $type->fromDatabase(['foo'])); $this->assertSame('string', (string) $type->fromDatabase(['foo'])->type()); - $this->assertSame(['foo'], $type->fromDatabase(['foo'])->toPrimitive()); - $this->assertInstanceOf(SetInterface::class, $type->fromDatabase([null])); + $this->assertSame(['foo'], unwrap($type->fromDatabase(['foo']))); + $this->assertInstanceOf(Set::class, $type->fromDatabase([null])); $this->assertSame('string', (string) $type->fromDatabase([null])->type()); - $this->assertSame([''], $type->fromDatabase([null])->toPrimitive()); + $this->assertSame([''], unwrap($type->fromDatabase([null]))); $t = SetType::nullable(new StringType, 'string'); - $this->assertInstanceOf(SetInterface::class, $type->fromDatabase([null])); + $this->assertInstanceOf(Set::class, $type->fromDatabase([null])); $this->assertSame('string', (string) $type->fromDatabase([null])->type()); - $this->assertSame([''], $type->fromDatabase([null])->toPrimitive()); + $this->assertSame([''], unwrap($type->fromDatabase([null]))); } public function testUseSpecificSetTypeInsteadOfInnerTypeName() @@ -135,7 +133,7 @@ public function testUseSpecificSetTypeInsteadOfInnerTypeName() $set = $type->fromDatabase([]); - $this->assertInstanceOf(SetInterface::class, $set); + $this->assertInstanceOf(Set::class, $set); $this->assertSame('stdClass', (string) $set->type()); } } diff --git a/tests/UnitOfWorkTest.php b/tests/UnitOfWorkTest.php index 8b51d4f..2d195b1 100644 --- a/tests/UnitOfWorkTest.php +++ b/tests/UnitOfWorkTest.php @@ -36,12 +36,12 @@ use Innmind\EventBus\EventBus; use function Innmind\HttpTransport\bootstrap as http; use Innmind\Url\Url; -use Innmind\TimeContinuum\TimeContinuum\Earth; +use Innmind\TimeContinuum\Earth\Clock as Earth; use Innmind\Immutable\{ - SetInterface, Set, Map, }; +use function Innmind\Immutable\first; use GuzzleHttp\Client; use PHPUnit\Framework\TestCase; @@ -65,7 +65,7 @@ public function setUp(): void $this->conn = dbal( http()['default'](), new Earth, - Url::fromString('http://neo4j:ci@localhost:7474/') + Url::of('http://neo4j:ci@localhost:7474/') ); $this->container = new Container; $this->entityFactory = new EntityFactory( @@ -185,7 +185,7 @@ public function testLoadEntityFromDatabase() { $this->conn->execute( (new Query) - ->create('n', ['Label']) + ->create('n', 'Label') ->withProperty('uuid', '{uuid}') ->withParameter('uuid', $uuid = '11111111-1111-1111-1111-111111111112') ); @@ -223,16 +223,16 @@ public function testExecute(array $args) $data = $uow->execute( (new Query) - ->match('entity', ['Label']) + ->match('entity', 'Label') ->withProperty('uuid', '"11111111-1111-1111-1111-111111111111"') ->return('entity'), - (new Map('string', Entity::class)) - ->put('entity', ($this->metadata)($this->aggregateClass)) + Map::of('string', Entity::class) + ('entity', ($this->metadata)($this->aggregateClass)) ); - $this->assertInstanceOf(SetInterface::class, $data); + $this->assertInstanceOf(Set::class, $data); $this->assertSame(1, $data->size()); - $this->assertSame($expectedEntity, $data->current()); + $this->assertSame($expectedEntity, first($data)); } public function testRemoveNewEntity() From d8e922341e1d6d92679aeb277173d6e38c76e562 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 17:00:24 +0100 Subject: [PATCH 07/17] add psalm --- composer.json | 3 +- psalm.xml | 16 ++++++ src/CommandBus/ClearDomainEvents.php | 10 ++-- src/CommandBus/DispatchDomainEvents.php | 11 +++- src/Entity/ChangesetComputer.php | 19 +++++-- src/Entity/Container.php | 5 ++ .../DataExtractor/AggregateExtractor.php | 6 ++ src/Entity/DataExtractor/DataExtractor.php | 8 +++ .../DataExtractor/RelationshipExtractor.php | 3 + src/EntityFactory/AggregateFactory.php | 19 +++++-- src/EntityFactory/EntityFactory.php | 3 +- src/EntityFactory/Resolver.php | 3 + src/Event/EntityAboutToBeUpdated.php | 4 ++ src/Event/EntityUpdated.php | 4 ++ src/Exception/LogicException.php | 8 +++ .../MoreThanOneRelationshipFound.php | 26 +++++---- src/Identity/Generator/UuidGenerator.php | 14 ++++- src/Identity/Generators.php | 8 ++- src/IdentityMatch.php | 10 ++-- src/Metadata/Aggregate.php | 29 +++++++--- src/Metadata/Aggregate/Child.php | 26 +++++++-- src/Metadata/Aggregate/Child/Relationship.php | 23 ++++++-- src/Metadata/ClassName.php | 7 +++ src/Metadata/Factory.php | 12 +++- src/Metadata/Relationship.php | 23 ++++++-- src/Metadata/Repository.php | 12 +++- src/Metadatas.php | 2 + src/Persister/DelegationPersister.php | 1 + src/Persister/InsertPersister.php | 38 ++++++++++--- src/Persister/RemovePersister.php | 18 +++--- src/Persister/UpdatePersister.php | 27 ++++++--- src/Query/PropertiesMatch.php | 6 ++ src/Query/Where.php | 4 ++ src/Repository.php | 3 +- src/RepositoryFactory.php | 9 ++- src/Translation/EntityTranslator.php | 7 ++- .../IdentityMatch/AggregateTranslator.php | 34 +++++++---- .../IdentityMatch/DelegationTranslator.php | 8 +++ .../IdentityMatch/RelationshipTranslator.php | 6 ++ src/Translation/Match/AggregateTranslator.php | 34 +++++++---- .../Match/DelegationTranslator.php | 8 +++ .../Match/RelationshipTranslator.php | 6 ++ .../Result/AggregateTranslator.php | 18 +++++- .../Result/RelationshipTranslator.php | 14 ++++- src/Translation/ResultTranslator.php | 9 +++ .../Specification/AggregateTranslator.php | 56 ++++++++++++------- .../Specification/DelegationTranslator.php | 8 +++ .../Specification/RelationshipTranslator.php | 7 +++ .../Validator/AggregateValidator.php | 4 +- .../Validator/DelegationValidator.php | 8 +++ .../Validator/RelationshipValidator.php | 6 +- .../Visitor/Cypher/AggregateVisitor.php | 17 ++++++ .../Visitor/Cypher/RelationshipVisitor.php | 19 +++++++ .../PropertyMatch/AggregateVisitor.php | 49 +++++++++++----- .../PropertyMatch/RelationshipVisitor.php | 46 +++++++++++---- .../Visitor/PropertyMatchVisitor.php | 6 +- src/Type/ArrayType.php | 4 ++ src/Type/DateType.php | 3 + src/Type/PointInTimeType.php | 2 + src/Type/SetType.php | 3 + src/UnitOfWork.php | 3 +- src/bootstrap.php | 46 +++++++++++---- 62 files changed, 674 insertions(+), 177 deletions(-) create mode 100644 psalm.xml create mode 100644 src/Exception/LogicException.php diff --git a/composer.json b/composer.json index dd21ab9..5493123 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "innmind/command-bus": "~4.0", "innmind/cli": "~2.0", "innmind/object-graph": "~2.0", - "innmind/server-control": "~3.0" + "innmind/server-control": "~3.0", + "vimeo/psalm": "^3.10" }, "suggest": { "innmind/time-continuum": "To be able to use point_in_time type", diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..617f63d --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/CommandBus/ClearDomainEvents.php b/src/CommandBus/ClearDomainEvents.php index f68b0a2..8e3cb95 100644 --- a/src/CommandBus/ClearDomainEvents.php +++ b/src/CommandBus/ClearDomainEvents.php @@ -10,6 +10,7 @@ }; use Innmind\CommandBus\CommandBus; use Innmind\EventBus\ContainsRecordedEvents; +use Innmind\Immutable\Map; final class ClearDomainEvents implements CommandBus { @@ -25,7 +26,8 @@ public function __construct(CommandBus $handle, Container $entities) public function __invoke(object $command): void { ($this->handle)($command); - $this + /** @var Map */ + $entitiesWithRecordedEvents = $this ->entities ->state(State::new()) ->merge($this->entities->state(State::managed())) @@ -33,9 +35,9 @@ public function __invoke(object $command): void ->merge($this->entities->state(State::removed())) ->filter(static function(Identity $identity, $entity): bool { return $entity instanceof ContainsRecordedEvents; - }) - ->foreach(static function(Identity $identity, ContainsRecordedEvents $entity): void { - $entity->clearEvents(); }); + $entitiesWithRecordedEvents->foreach(static function(Identity $identity, ContainsRecordedEvents $entity): void { + $entity->clearEvents(); + }); } } diff --git a/src/CommandBus/DispatchDomainEvents.php b/src/CommandBus/DispatchDomainEvents.php index c8ffe28..689fe64 100644 --- a/src/CommandBus/DispatchDomainEvents.php +++ b/src/CommandBus/DispatchDomainEvents.php @@ -13,7 +13,10 @@ EventBus, ContainsRecordedEvents, }; -use Innmind\Immutable\Sequence; +use Innmind\Immutable\{ + Sequence, + Map, +}; final class DispatchDomainEvents implements CommandBus { @@ -34,7 +37,8 @@ public function __construct( public function __invoke(object $command): void { ($this->handle)($command); - $this + /** @var Map */ + $entitiesWithRecordedEvents = $this ->entities ->state(State::new()) ->merge($this->entities->state(State::managed())) @@ -42,7 +46,8 @@ public function __invoke(object $command): void ->merge($this->entities->state(State::removed())) ->filter(static function(Identity $identity, $entity): bool { return $entity instanceof ContainsRecordedEvents; - }) + }); + $entitiesWithRecordedEvents ->reduce( Sequence::objects(), static function( diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index 3958ff1..981e4ce 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -11,10 +11,12 @@ final class ChangesetComputer { + /** @var Map> */ private Map $sources; public function __construct() { + /** @var Map> */ $this->sources = Map::of(Identity::class, Map::class); } @@ -62,10 +64,14 @@ public function compute(Identity $identity, Map $target): Map return $this->diff($source, $target); } - private function diff( - Map $source, - Map $target - ): Map { + /** + * @param Map $source + * @param Map $target + * + * @return Map + */ + private function diff(Map $source, Map $target): Map + { $changeset = $target->filter(static function(string $property, $value) use ($source): bool { if ( !$source->contains($property) || @@ -77,6 +83,10 @@ private function diff( return false; }); + /** + * @psalm-suppress MissingClosureReturnType + * @var Map + */ return $source ->filter(static function(string $property) use ($target): bool { return !$target->contains($property); @@ -92,6 +102,7 @@ static function(Map $carry, string $property) use ($target): Map { return $value; } + /** @psalm-suppress MixedArgument */ return $this->diff( $source->get($property), $target->get($property) diff --git a/src/Entity/Container.php b/src/Entity/Container.php index 96fb0c2..b9350c8 100644 --- a/src/Entity/Container.php +++ b/src/Entity/Container.php @@ -13,10 +13,15 @@ final class Container { + /** @var Map> */ private Map $states; public function __construct() { + /** + * @psalm-suppress InvalidArgument + * @var Map> + */ $this->states = Map::of(State::class, Map::class) (State::managed(), Map::of(Identity::class, 'object')) (State::new(), Map::of(Identity::class, 'object')) diff --git a/src/Entity/DataExtractor/AggregateExtractor.php b/src/Entity/DataExtractor/AggregateExtractor.php index 6b0db06..69f2c77 100644 --- a/src/Entity/DataExtractor/AggregateExtractor.php +++ b/src/Entity/DataExtractor/AggregateExtractor.php @@ -35,6 +35,7 @@ public function __invoke(object $entity, Entity $meta): Map throw new InvalidArgumentException; } + /** @psalm-suppress MixedMethodCall */ $data = $this ->extractProperties($entity, $meta->properties()) ->put( @@ -46,6 +47,7 @@ public function __invoke(object $entity, Entity $meta): Map ->value() ); + /** @var Map */ return $meta ->children() ->reduce( @@ -69,10 +71,13 @@ private function extractRelationship( Child $child, object $entity ): Map { + /** @var object */ $rel = $this ->reflection($entity) ->extract($property = $child->relationship()->property()) ->get($property); + + /** @psalm-suppress MixedArgument */ $data = $this ->extractProperties( $rel, @@ -103,6 +108,7 @@ private function extractProperties( ): Map { $refl = $this->reflection($object); + /** @var Map */ return $properties->reduce( Map::of('string', 'mixed'), static function(Map $carry, string $name, Property $property) use ($refl): Map { diff --git a/src/Entity/DataExtractor/DataExtractor.php b/src/Entity/DataExtractor/DataExtractor.php index 582b57d..56eade4 100644 --- a/src/Entity/DataExtractor/DataExtractor.php +++ b/src/Entity/DataExtractor/DataExtractor.php @@ -14,13 +14,21 @@ final class DataExtractor { private Metadatas $metadata; + /** @var Map */ private Map $extractors; + /** + * @param Map|null $extractors + */ public function __construct( Metadatas $metadata, Map $extractors = null ) { $this->metadata = $metadata; + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->extractors = $extractors ?? Map::of('string', DataExtractorInterface::class) (Aggregate::class, new AggregateExtractor) (Relationship::class, new RelationshipExtractor); diff --git a/src/Entity/DataExtractor/RelationshipExtractor.php b/src/Entity/DataExtractor/RelationshipExtractor.php index 1314d60..2650ac9 100644 --- a/src/Entity/DataExtractor/RelationshipExtractor.php +++ b/src/Entity/DataExtractor/RelationshipExtractor.php @@ -40,11 +40,13 @@ public function __invoke(object $entity, Entity $meta): Map null, $this->extractionStrategy ); + /** @var Map */ $data = $refl->extract( $id = $meta->identity()->property(), $start = $meta->startNode()->property(), $end = $meta->endNode()->property() ); + /** @psalm-suppress MixedMethodCall */ $data = $data ->put( $id, @@ -59,6 +61,7 @@ public function __invoke(object $entity, Entity $meta): Map $data->get($end)->value() ); + /** @var Map */ return $meta ->properties() ->reduce( diff --git a/src/EntityFactory/AggregateFactory.php b/src/EntityFactory/AggregateFactory.php index bafe68e..a844428 100644 --- a/src/EntityFactory/AggregateFactory.php +++ b/src/EntityFactory/AggregateFactory.php @@ -97,20 +97,26 @@ function(ReflectionClass $carry, string $property, Child $meta) use ($data): Ref ->build(); } - private function buildChild(Child $meta, Map $data) + /** + * @param Map $data + */ + private function buildChild(Child $meta, Map $data): object { $relationship = $meta->relationship(); + /** @var Map */ $data = $data->get($relationship->property()); return $this->buildRelationship($meta, $data); } - private function buildRelationship( - Child $meta, - Map $data - ) { + /** + * @param Map $data + */ + private function buildRelationship(Child $meta, Map $data): object + { $relationship = $meta->relationship(); + /** @psalm-suppress MixedArgument */ return $relationship ->properties() ->filter(static function(string $name, Property $property) use ($data): bool { @@ -176,6 +182,9 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ ->build(); } + /** + * @param class-string $class + */ private function reflection(string $class): ReflectionClass { return new ReflectionClass( diff --git a/src/EntityFactory/EntityFactory.php b/src/EntityFactory/EntityFactory.php index 75903a5..ec2e923 100644 --- a/src/EntityFactory/EntityFactory.php +++ b/src/EntityFactory/EntityFactory.php @@ -59,6 +59,7 @@ public function __invoke( $structuredData = ($this->translate)($result, $variables); $entities = Set::objects(); + /** @var Set */ return $variables ->filter(static function(string $variable) use ($structuredData): bool { return $structuredData->contains($variable); @@ -83,7 +84,7 @@ function(Set $carry, Map $data) use ($meta): Set { /** * @param Map $data */ - private function makeEntity(Entity $meta, Map $data) + private function makeEntity(Entity $meta, Map $data): object { $identity = $this ->generators diff --git a/src/EntityFactory/Resolver.php b/src/EntityFactory/Resolver.php index b918147..e013799 100644 --- a/src/EntityFactory/Resolver.php +++ b/src/EntityFactory/Resolver.php @@ -11,10 +11,12 @@ final class Resolver { + /** @var Map */ private Map $mapping; public function __construct(EntityFactoryInterface ...$factories) { + /** @var Map */ $this->mapping = Map::of('string', EntityFactoryInterface::class); foreach ($factories as $factory) { @@ -27,6 +29,7 @@ public function __construct(EntityFactoryInterface ...$factories) */ public function __invoke(Entity $meta): EntityFactoryInterface { + /** @var class-string */ $class = (string) $meta->factory(); if ($this->mapping->contains($class)) { diff --git a/src/Event/EntityAboutToBeUpdated.php b/src/Event/EntityAboutToBeUpdated.php index 5a45882..ce91d92 100644 --- a/src/Event/EntityAboutToBeUpdated.php +++ b/src/Event/EntityAboutToBeUpdated.php @@ -10,8 +10,12 @@ final class EntityAboutToBeUpdated { private Identity $identity; private object $entity; + /** @var Map */ private Map $changeset; + /** + * @param Map $changeset + */ public function __construct( Identity $identity, object $entity, diff --git a/src/Event/EntityUpdated.php b/src/Event/EntityUpdated.php index e358f1c..fce8d4d 100644 --- a/src/Event/EntityUpdated.php +++ b/src/Event/EntityUpdated.php @@ -10,8 +10,12 @@ final class EntityUpdated { private Identity $identity; private object $entity; + /** @var Map */ private Map $changeset; + /** + * @param Map $changeset + */ public function __construct( Identity $identity, object $entity, diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php new file mode 100644 index 0000000..a169004 --- /dev/null +++ b/src/Exception/LogicException.php @@ -0,0 +1,8 @@ +child = $child; + parent::__construct($message); + $this->child = $child; + } - return $exception; + public static function for(Child $child): self + { + return new self('', $child); } public function on(Entity $entity): self { - $exception = new self(sprintf( - 'More than one relationship found on "%s::%s"', - $entity->class(), - $this->child->relationship()->property() - )); - $exception->child = $this->child; + $exception = new self( + \sprintf( + 'More than one relationship found on "%s::%s"', + (string) $entity->class(), + $this->child->relationship()->property(), + ), + $this->child, + ); $exception->entity = $entity; return $exception; diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 705bc7c..8dede7f 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -17,14 +17,19 @@ final class UuidGenerator implements Generator { + /** @var Map */ private Map $identities; + /** + * @param class-string $type + */ public function __construct(string $type = Uuid::class) { if (Str::of($type)->empty()) { throw new DomainException; } + /** @var Map */ $this->identities = Map::of('string', $type); } @@ -33,10 +38,11 @@ public function __construct(string $type = Uuid::class) */ public function new(): Identity { + /** @var class-string */ $class = (string) $this->identities->valueType(); $uuid = new $class((string) Factory::uuid4()); $this->identities = $this->identities->put( - $uuid->value(), + (string) $uuid, $uuid ); @@ -48,6 +54,7 @@ public function new(): Identity */ public function knows($value): bool { + /** @psalm-suppress MixedArgument */ return $this->identities->contains($value); } @@ -56,6 +63,7 @@ public function knows($value): bool */ public function get($value): Identity { + /** @psalm-suppress MixedArgument */ return $this->identities->get($value); } @@ -64,8 +72,9 @@ public function get($value): Identity */ public function add(Identity $identity): Generator { + /** @psalm-suppress ArgumentTypeCoercion */ $this->identities = $this->identities->put( - $identity->value(), + (string) $identity, $identity ); @@ -81,6 +90,7 @@ public function for($value): Identity return $this->get($value); } + /** @var class-string */ $class = (string) $this->identities->valueType(); $uuid = new $class($value); $this->add($uuid); diff --git a/src/Identity/Generators.php b/src/Identity/Generators.php index 629b6fc..432653d 100644 --- a/src/Identity/Generators.php +++ b/src/Identity/Generators.php @@ -8,11 +8,17 @@ final class Generators { + /** @var Map */ private Map $mapping; + /** + * @param Map|null $mapping + */ public function __construct(Map $mapping = null) { - $mapping = $mapping ?? Map::of('string', Generator::class); + /** @var Map */ + $mapping ??= Map::of('string', Generator::class); + /** @psalm-suppress InvalidArgument */ $this->mapping = Map::of('string', Generator::class) (Uuid::class, new Generator\UuidGenerator) ->merge($mapping); diff --git a/src/IdentityMatch.php b/src/IdentityMatch.php index 0128d49..a5ba321 100644 --- a/src/IdentityMatch.php +++ b/src/IdentityMatch.php @@ -10,12 +10,14 @@ final class IdentityMatch { private Query $query; + /** @var Map */ private Map $variables; - public function __construct( - Query $query, - Map $variables - ) { + /** + * @param Map $variables + */ + public function __construct(Query $query, Map $variables) + { if ( (string) $variables->keyType() !== 'string' || (string) $variables->valueType() !== Entity::class diff --git a/src/Metadata/Aggregate.php b/src/Metadata/Aggregate.php index f581860..7d39e7f 100644 --- a/src/Metadata/Aggregate.php +++ b/src/Metadata/Aggregate.php @@ -20,10 +20,18 @@ final class Aggregate implements Entity private Identity $identity; private Repository $repository; private Factory $factory; + /** @var Map */ private Map $properties; + /** @var Set */ private Set $labels; + /** @var Map */ private Map $children; + /** + * @param Set $labels + * @param Set $properties + * @param Set $children + */ public function __construct( ClassName $class, Identity $identity, @@ -53,6 +61,7 @@ public function __construct( $this->identity = $identity; $this->repository = new Repository(ConcreteRepository::class); $this->factory = new Factory(AggregateFactory::class); + /** @var Map */ $this->properties = $properties->reduce( Map::of('string', Property::class), static function(Map $properties, Property $property): Map { @@ -60,6 +69,7 @@ static function(Map $properties, Property $property): Map { } ); $this->labels = $labels; + /** @var Map */ $this->children = $children->reduce( Map::of('string', Child::class), static function(Map $children, Child $child): Map { @@ -73,8 +83,8 @@ static function(Map $children, Child $child): Map { /** * @param Set $labels - * @param Map $properties - * @param Set $children + * @param Map|null $properties + * @param Set|null $children */ public static function of( ClassName $class, @@ -83,16 +93,19 @@ public static function of( Map $properties = null, Set $children = null ): self { + /** @var Map */ + $properties ??= Map::of('string', Type::class); + /** @var Set */ + $properties = $properties->toSetOf( + Property::class, + static fn(string $property, Type $type): \Generator => yield new Property($property, $type), + ); + return new self( $class, $identity, $labels, - ($properties ?? Map::of('string', Type::class))->reduce( - Set::of(Property::class), - static function(Set $properties, string $name, Type $type): Set { - return $properties->add(new Property($name, $type)); - } - ), + $properties, $children ?? Set::of(Child::class) ); } diff --git a/src/Metadata/Aggregate/Child.php b/src/Metadata/Aggregate/Child.php index 7a37f4a..73fff94 100644 --- a/src/Metadata/Aggregate/Child.php +++ b/src/Metadata/Aggregate/Child.php @@ -16,10 +16,16 @@ final class Child { private ClassName $class; + /** @var Set */ private Set $labels; private Child\Relationship $relationship; + /** @var Map */ private Map $properties; + /** + * @param Set $labels + * @param Set $properties + */ public function __construct( ClassName $class, Set $labels, @@ -40,6 +46,7 @@ public function __construct( $this->class = $class; $this->labels = $labels; $this->relationship = $relationship; + /** @var Map */ $this->properties = $properties->reduce( Map::of('string', Property::class), static function(Map $properties, Property $property): Map { @@ -48,22 +55,29 @@ static function(Map $properties, Property $property): Map { ); } + /** + * @param Set $labels + * @param Map|null $properties + */ public static function of( ClassName $class, Set $labels, Child\Relationship $relationship, Map $properties = null ): self { + /** @var Map */ + $properties ??= Map::of('string', Type::class); + /** @var Set */ + $properties = $properties->toSetOf( + Property::class, + static fn(string $property, Type $type): \Generator => yield new Property($property, $type), + ); + return new self( $class, $labels, $relationship, - ($properties ?? Map::of('string', Type::class))->reduce( - Set::of(Property::class), - static function(Set $properties, string $property, Type $type): Set { - return $properties->add(new Property($property, $type)); - } - ) + $properties, ); } diff --git a/src/Metadata/Aggregate/Child/Relationship.php b/src/Metadata/Aggregate/Child/Relationship.php index 2e4e326..732d05e 100644 --- a/src/Metadata/Aggregate/Child/Relationship.php +++ b/src/Metadata/Aggregate/Child/Relationship.php @@ -22,8 +22,12 @@ final class Relationship private RelationshipType $type; private string $property; private string $childProperty; + /** @var Map */ private Map $properties; + /** + * @param Set $properties + */ public function __construct( ClassName $class, RelationshipType $type, @@ -46,6 +50,7 @@ public function __construct( $this->type = $type; $this->property = $property; $this->childProperty = $childProperty; + /** @var Map */ $this->properties = $properties->reduce( Map::of('string', Property::class), static function(Map $properties, Property $property): Map { @@ -54,6 +59,9 @@ static function(Map $properties, Property $property): Map { ); } + /** + * @param Map|null $properties + */ public static function of( ClassName $class, RelationshipType $type, @@ -61,17 +69,20 @@ public static function of( string $childProperty, Map $properties = null ): self { + /** @var Map */ + $properties ??= Map::of('string', Type::class); + /** @var Set */ + $properties = $properties->toSetOf( + Property::class, + static fn(string $property, Type $type): \Generator => yield new Property($property, $type), + ); + return new self( $class, $type, $property, $childProperty, - ($properties ?? Map::of('string', Type::class))->reduce( - Set::of(Property::class), - static function(Set $properties, string $property, Type $type): Set { - return $properties->add(new Property($property, $type)); - } - ) + $properties, ); } diff --git a/src/Metadata/ClassName.php b/src/Metadata/ClassName.php index 804b65e..ba9ea60 100644 --- a/src/Metadata/ClassName.php +++ b/src/Metadata/ClassName.php @@ -8,8 +8,12 @@ final class ClassName { + /** @var class-string */ private string $class; + /** + * @param class-string $class + */ public function __construct(string $class) { if (Str::of($class)->empty()) { @@ -19,6 +23,9 @@ public function __construct(string $class) $this->class = $class; } + /** + * @return class-string + */ public function __toString(): string { return $this->class; diff --git a/src/Metadata/Factory.php b/src/Metadata/Factory.php index 74151b8..348c262 100644 --- a/src/Metadata/Factory.php +++ b/src/Metadata/Factory.php @@ -3,7 +3,10 @@ namespace Innmind\Neo4j\ONM\Metadata; -use Innmind\Neo4j\ONM\Exception\DomainException; +use Innmind\Neo4j\ONM\{ + EntityFactory, + Exception\DomainException, +}; use Innmind\Immutable\Str; /** @@ -11,8 +14,12 @@ */ final class Factory { + /** @var class-string */ private string $class; + /** + * @param class-string $class + */ public function __construct(string $class) { if (Str::of($class)->empty()) { @@ -22,6 +29,9 @@ public function __construct(string $class) $this->class = $class; } + /** + * @return class-string + */ public function __toString(): string { return $this->class; diff --git a/src/Metadata/Relationship.php b/src/Metadata/Relationship.php index a4175f7..26d006c 100644 --- a/src/Metadata/Relationship.php +++ b/src/Metadata/Relationship.php @@ -22,8 +22,12 @@ final class Relationship implements Entity private RelationshipType $type; private RelationshipEdge $startNode; private RelationshipEdge $endNode; + /** @var Map */ private Map $properties; + /** + * @param Set $properties + */ public function __construct( ClassName $class, Identity $identity, @@ -46,6 +50,7 @@ public function __construct( $this->type = $type; $this->startNode = $startNode; $this->endNode = $endNode; + /** @var Map */ $this->properties = $properties->reduce( Map::of('string', Property::class), static function(Map $properties, Property $property): Map { @@ -54,6 +59,9 @@ static function(Map $properties, Property $property): Map { ); } + /** + * @param Map|null $properties + */ public static function of( ClassName $class, Identity $identity, @@ -62,18 +70,21 @@ public static function of( RelationshipEdge $endNode, Map $properties = null ): self { + /** @var Map */ + $properties ??= Map::of('string', Type::class); + /** @var Set */ + $properties = $properties->toSetOf( + Property::class, + static fn(string $property, Type $type): \Generator => yield new Property($property, $type), + ); + return new self( $class, $identity, $type, $startNode, $endNode, - ($properties ?? Map::of('string', Type::class))->reduce( - Set::of(Property::class), - static function(Set $properties, string $property, Type $type): Set { - return $properties->add(new Property($property, $type)); - } - ) + $properties, ); } diff --git a/src/Metadata/Repository.php b/src/Metadata/Repository.php index e3e9918..ab40876 100644 --- a/src/Metadata/Repository.php +++ b/src/Metadata/Repository.php @@ -3,7 +3,10 @@ namespace Innmind\Neo4j\ONM\Metadata; -use Innmind\Neo4j\ONM\Exception\DomainException; +use Innmind\Neo4j\ONM\{ + Repository as RepositoryInterface, + Exception\DomainException, +}; use Innmind\Immutable\Str; /** @@ -11,8 +14,12 @@ */ final class Repository { + /** @var class-string */ private string $class; + /** + * @param class-string $class + */ public function __construct(string $class) { if (Str::of($class)->empty()) { @@ -22,6 +29,9 @@ public function __construct(string $class) $this->class = $class; } + /** + * @return class-string + */ public function __toString(): string { return $this->class; diff --git a/src/Metadatas.php b/src/Metadatas.php index 4fe780f..9a410f3 100644 --- a/src/Metadatas.php +++ b/src/Metadatas.php @@ -8,10 +8,12 @@ final class Metadatas { + /** @var Map */ private Map $mapping; public function __construct(Entity ...$metas) { + /** @var Map */ $this->mapping = Map::of('string', Entity::class); foreach ($metas as $meta) { diff --git a/src/Persister/DelegationPersister.php b/src/Persister/DelegationPersister.php index 6509def..43d42f1 100644 --- a/src/Persister/DelegationPersister.php +++ b/src/Persister/DelegationPersister.php @@ -11,6 +11,7 @@ final class DelegationPersister implements Persister { + /** @var list */ private array $persisters; public function __construct(Persister ...$persisters) diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index f84a30b..b3ddc53 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -16,11 +16,12 @@ Metadata\Property, Metadata\Aggregate\Child, Metadata\RelationshipEdge, + Metadata\Relationship, Metadatas, }; use Innmind\Neo4j\DBAL\{ Connection, - Query, + Query\Query, }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ @@ -37,7 +38,8 @@ final class InsertPersister implements Persister private DataExtractor $extract; private Metadatas $metadata; private Str $name; - private ?Sequence $variables = null; + /** @var Sequence */ + private Sequence $variables; public function __construct( ChangesetComputer $changeset, @@ -50,6 +52,7 @@ public function __construct( $this->extract = $extract; $this->metadata = $metadata; $this->name = Str::of('e%s'); + $this->variables = Sequence::strings(); } /** @@ -86,8 +89,8 @@ public function __invoke(Connection $connection, Container $container): void */ private function queryFor(Map $entities): Query { - $query = new Query\Query; - $this->variables = Sequence::strings(); + $query = new Query; + $this->variables = $this->variables->clear(); $partitions = $entities->partition(function(Identity $identity, object $entity): bool { $meta = ($this->metadata)(\get_class($entity)); @@ -110,7 +113,7 @@ function(Query $carry, Identity $identity, object $entity): Query { return $this->createRelationship($identity, $entity, $carry); } ); - $this->variables = null; + $this->variables = $this->variables->clear(); return $query; } @@ -123,9 +126,10 @@ private function createAggregate( object $entity, Query $query ): Query { + /** @var Aggregate */ $meta = ($this->metadata)(\get_class($entity)); $data = ($this->extract)($entity); - $varName = $this->name->sprintf(\md5($identity->value())); + $varName = $this->name->sprintf(\md5((string) $identity->value())); $query = $query->create( $varName->toString(), @@ -138,6 +142,7 @@ private function createAggregate( ); $keysToKeep = $data->keys()->intersect($properties->keys()); + /** @psalm-suppress MixedArgumentTypeCoercion */ $query = $query ->withProperty( $meta->identity()->property(), @@ -168,6 +173,7 @@ static function(array $carry, string $property, string $cypher): array { ->reduce( [], static function(array $carry, string $key, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[$key] = $value; return $carry; @@ -180,6 +186,7 @@ static function(array $carry, string $key, $value): array { ->reduce( $query, function(Query $carry, string $property, Child $child) use ($varName, $data): Query { + /** @psalm-suppress MixedArgument */ return $this->createAggregateChild( $child, $varName, @@ -220,6 +227,11 @@ private function createAggregateChild( $relationshipParamKey = $relationshipName->append('_props') ); + /** + * @psalm-suppress MixedArgumentTypeCoercion + * @psalm-suppress MissingClosureParamType + * @psalm-suppress MixedMethodCall + */ return $query ->create($nodeName->toString()) ->linkedTo( @@ -241,6 +253,7 @@ static function(array $carry, string $property, string $cypher): array { ->reduce( [], static function(array $carry, string $key, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[$key] = $value; return $carry; @@ -267,6 +280,7 @@ static function(array $carry, string $property, string $cypher): array { ->reduce( [], static function(array $carry, string $key, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[$key] = $value; return $carry; @@ -288,6 +302,7 @@ private function buildProperties( ): Map { $name = $name->prepend('{')->append('}.'); + /** @var Map */ return $properties->reduce( Map::of('string', 'string'), static function(Map $carry, string $property) use ($name): Map { @@ -307,18 +322,22 @@ private function createRelationship( object $entity, Query $query ): Query { + /** @var Relationship */ $meta = ($this->metadata)(\get_class($entity)); $data = ($this->extract)($entity); + /** @var mixed */ $start = $data->get($meta->startNode()->property()); + /** @var mixed */ $end = $data->get($meta->endNode()->property()); - $varName = $this->name->sprintf(\md5($identity->value())); - $startName = $this->name->sprintf(\md5($start)); - $endName = $this->name->sprintf(\md5($end)); + $varName = $this->name->sprintf(\md5((string) $identity->value())); + $startName = $this->name->sprintf(\md5((string) $start)); + $endName = $this->name->sprintf(\md5((string) $end)); $paramKey = $varName->append('_props'); $properties = $this->buildProperties($meta->properties(), $paramKey); $keysToKeep = $data->keys()->intersect($properties->keys()); + /** @psalm-suppress MixedArgumentTypeCoercion */ return $this ->matchEdge( $endName, @@ -364,6 +383,7 @@ static function(array $carry, string $property, string $cypher): array { ->reduce( [], static function(array $carry, string $key, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[$key] = $value; return $carry; diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 7369697..857690e 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -18,7 +18,7 @@ }; use Innmind\Neo4j\DBAL\{ Connection, - Query, + Query\Query, }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ @@ -34,7 +34,8 @@ final class RemovePersister implements Persister private EventBus $dispatch; private Metadatas $metadata; private Str $name; - private ?Sequence $variables = null; + /** @var Sequence */ + private Sequence $variables; public function __construct( ChangesetComputer $changeset, @@ -45,6 +46,7 @@ public function __construct( $this->dispatch = $dispatch; $this->metadata = $metadata; $this->name = Str::of('e%s'); + $this->variables = Sequence::strings(); } /** @@ -77,8 +79,8 @@ public function __invoke(Connection $connection, Container $container): void */ private function queryFor(Map $entities): Query { - $query = new Query\Query; - $this->variables = Sequence::strings(); + $query = new Query; + $this->variables = $this->variables->clear(); $partitions = $entities->partition(function(Identity $identity, object $entity): bool { $meta = ($this->metadata)(\get_class($entity)); @@ -109,7 +111,7 @@ static function(Query $carry, string $variable): Query { return $carry->delete($variable); } ); - $this->variables = null; + $this->variables = $this->variables->clear(); return $query; } @@ -122,8 +124,9 @@ private function matchRelationship( object $entity, Query $query ): Query { + /** @var Relationship */ $meta = ($this->metadata)(\get_class($entity)); - $name = $this->name->sprintf(\md5($identity->value())); + $name = $this->name->sprintf(\md5((string) $identity->value())); $this->variables = $this->variables->add($name->toString()); return $query @@ -154,8 +157,9 @@ private function matchAggregate( object $entity, Query $query ): Query { + /** @var Aggregate */ $meta = ($this->metadata)(\get_class($entity)); - $name = $this->name->sprintf(\md5($identity->value())); + $name = $this->name->sprintf(\md5((string) $identity->value())); $this->variables = $this->variables->add($name->toString()); $query = $query diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index 00a157b..965496f 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -15,11 +15,13 @@ Metadata\Aggregate, Metadata\Aggregate\Child, Metadata\Relationship, + Metadata\Property, Metadatas, + Exception\LogicException, }; use Innmind\Neo4j\DBAL\{ Connection, - Query, + Query\Query, }; use Innmind\EventBus\EventBus; use Innmind\Immutable\{ @@ -35,7 +37,8 @@ final class UpdatePersister implements Persister private DataExtractor $extract; private Metadatas $metadata; private Str $name; - private ?Map $variables = null; + /** @var Map> */ + private Map $variables; public function __construct( ChangesetComputer $changeset, @@ -48,6 +51,7 @@ public function __construct( $this->extract = $extract; $this->metadata = $metadata; $this->name = Str::of('e%s'); + $this->variables = Map::of(Str::class, Map::class); } /** @@ -56,6 +60,7 @@ public function __construct( public function __invoke(Connection $connection, Container $container): void { $entities = $container->state(State::managed()); + /** @var Map> */ $changesets = $entities->reduce( Map::of(Identity::class, Map::class), function(Map $carry, Identity $identity, object $entity): Map { @@ -112,10 +117,10 @@ private function queryFor( Map $changesets, Map $entities ): Query { - $this->variables = Map::of(Str::class, Map::class); + $this->variables = $this->variables->clear(); $query = $changesets->reduce( - new Query\Query, + new Query, function(Query $carry, Identity $identity, Map $changeset) use ($entities): Query { $entity = $entities->get($identity); $meta = ($this->metadata)(\get_class($entity)); @@ -137,6 +142,9 @@ function(Query $carry, Identity $identity, Map $changeset) use ($entities): Quer $carry ); } + + $class = \get_class($meta); + throw new LogicException("Unknown metadata '$class'"); } ); $query = $this @@ -147,7 +155,7 @@ function(Query $carry, Str $variable, Map $changeset): Query { return $this->update($variable, $changeset, $carry); } ); - $this->variables = null; + $this->variables = $this->variables->clear(); return $query; } @@ -164,7 +172,7 @@ private function matchAggregate( Map $changeset, Query $query ): Query { - $name = $this->name->sprintf(\md5($identity->value())); + $name = $this->name->sprintf(\md5((string) $identity->value())); $query = $query ->match( $name->toString(), @@ -197,6 +205,7 @@ private function matchAggregate( ->reduce( $query, function(Query $carry, string $property, Child $child) use ($changeset, $name): Query { + /** @var Map */ $changeset = $changeset->get($property); $childName = null; $relName = $name @@ -216,6 +225,7 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): ->append( $child->relationship()->childProperty() ); + /** @psalm-suppress MixedArgument */ $this->variables = $this->variables->put( $childName, $changeset->get( @@ -241,7 +251,7 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): /** * Add the match clause for a relationship * - * @param Map $changeset + * @param Map> $changeset */ private function matchRelationship( Identity $identity, @@ -250,7 +260,7 @@ private function matchRelationship( Map $changeset, Query $query ): Query { - $name = $this->name->sprintf(\md5($identity->value())); + $name = $this->name->sprintf(\md5((string) $identity->value())); $this->variables = $this->variables->put( $name, $this->buildProperties( @@ -321,6 +331,7 @@ private function update( $changeset->reduce( [], static function(array $carry, string $key, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[$key] = $value; return $carry; diff --git a/src/Query/PropertiesMatch.php b/src/Query/PropertiesMatch.php index 57f8245..73a5b1c 100644 --- a/src/Query/PropertiesMatch.php +++ b/src/Query/PropertiesMatch.php @@ -7,9 +7,15 @@ final class PropertiesMatch { + /** @var Map */ private Map $properties; + /** @var Map */ private Map $parameters; + /** + * @param Map $properties + * @param Map $parameters + */ public function __construct(Map $properties, Map $parameters) { if ( diff --git a/src/Query/Where.php b/src/Query/Where.php index 5f6bd76..c978532 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -12,8 +12,12 @@ final class Where { private string $cypher; + /** @var Map */ private Map $parameters; + /** + * @param Map $parameters + */ public function __construct(string $cypher, Map $parameters) { if (Str::of($cypher)->empty()) { diff --git a/src/Repository.php b/src/Repository.php index a27beea..c2d58c2 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -3,6 +3,7 @@ namespace Innmind\Neo4j\ONM; +use Innmind\Neo4j\ONM\Exception\EntityNotFound; use Innmind\Specification\Specification; use Innmind\Immutable\Set; @@ -21,7 +22,7 @@ public function has(Identity $identity): bool; /** * Return the entity with the given id * - * @throws EntityNotFoundException + * @throws EntityNotFound */ public function get(Identity $identity): object; diff --git a/src/RepositoryFactory.php b/src/RepositoryFactory.php index 17a6064..4cff11f 100644 --- a/src/RepositoryFactory.php +++ b/src/RepositoryFactory.php @@ -15,15 +15,20 @@ final class RepositoryFactory private UnitOfWork $unitOfWork; private MatchTranslator $matchTranslator; private SpecificationTranslator $specificationTranslator; + /** @var Map */ private Map $repositories; + /** + * @param Map|null $repositories + */ public function __construct( UnitOfWork $unitOfWork, MatchTranslator $matchTranslator, SpecificationTranslator $specificationTranslator, Map $repositories = null ) { - $repositories = $repositories ?? Map::of(Entity::class, Repository::class); + /** @var Map */ + $repositories ??= Map::of(Entity::class, Repository::class); if ( (string) $repositories->keyType() !== Entity::class || @@ -51,7 +56,9 @@ public function __invoke(Entity $meta): Repository return $this->repositories->get($meta); } + /** @var class-string */ $class = (string) $meta->repository(); + /** @var Repository */ $repository = new $class( $this->unitOfWork, $this->matchTranslator, diff --git a/src/Translation/EntityTranslator.php b/src/Translation/EntityTranslator.php index 396c11a..3e388bb 100644 --- a/src/Translation/EntityTranslator.php +++ b/src/Translation/EntityTranslator.php @@ -5,14 +5,17 @@ use Innmind\Neo4j\ONM\Metadata\Entity; use Innmind\Neo4j\DBAL\Result; -use Innmind\Immutable\Set; +use Innmind\Immutable\{ + Set, + Map, +}; interface EntityTranslator { /** * Translate the wished variable from the result * - * @return Set> + * @return Set> */ public function __invoke( string $variable, diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index 19658a7..9fa11cf 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -7,6 +7,7 @@ Translation\IdentityMatchTranslator, Identity, Metadata\Entity, + Metadata\Aggregate, Metadata\Aggregate\Child, IdentityMatch, }; @@ -20,6 +21,14 @@ final class AggregateTranslator implements IdentityMatchTranslator { + /** @var Set */ + private Set $variables; + + public function __construct() + { + $this->variables = Set::strings(); + } + /** * {@inheritdoc} */ @@ -27,6 +36,10 @@ public function __invoke( Entity $meta, Identity $identity ): IdentityMatch { + if (!$meta instanceof Aggregate) { + throw new \TypeError('Argument 1 must be of type '.Aggregate::class); + } + $query = (new Query) ->match( 'entity', @@ -39,25 +52,23 @@ public function __invoke( ->withParameter('entity_identity', $identity->value()) ->with('entity'); - $variables = Set::strings(); - $meta - ->children() - ->foreach(function( + $this->variables = $this->variables->clear(); + $query = $meta->children()->reduce( + $query, + function( + Query $query, string $property, Child $child - ) use ( - &$query, - &$variables - ): void { + ): Query { $relName = Str::of('entity_')->append($property); $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $variables = $variables + $this->variables = $this->variables ->add($relName->toString()) ->add($childName->toString()); - $query = $query + return $query ->match('entity') ->linkedTo( $childName->toString(), @@ -70,7 +81,10 @@ public function __invoke( ); }); + $variables = $this->variables; + $this->variables = $this->variables->clear(); + /** @psalm-suppress InvalidArgument */ return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) diff --git a/src/Translation/IdentityMatch/DelegationTranslator.php b/src/Translation/IdentityMatch/DelegationTranslator.php index fe08de5..c67411b 100644 --- a/src/Translation/IdentityMatch/DelegationTranslator.php +++ b/src/Translation/IdentityMatch/DelegationTranslator.php @@ -15,10 +15,18 @@ final class DelegationTranslator implements IdentityMatchTranslator { + /** @var Map */ private Map $translators; + /** + * @param Map|null $translators + */ public function __construct(Map $translators = null) { + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->translators = $translators ?? Map::of('string', IdentityMatchTranslator::class) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); diff --git a/src/Translation/IdentityMatch/RelationshipTranslator.php b/src/Translation/IdentityMatch/RelationshipTranslator.php index a77bded..73c72d2 100644 --- a/src/Translation/IdentityMatch/RelationshipTranslator.php +++ b/src/Translation/IdentityMatch/RelationshipTranslator.php @@ -7,6 +7,7 @@ Translation\IdentityMatchTranslator, Identity, Metadata\Entity, + Metadata\Relationship, IdentityMatch, }; use Innmind\Neo4j\DBAL\Query\Query; @@ -21,6 +22,10 @@ public function __invoke( Entity $meta, Identity $identity ): IdentityMatch { + if (!$meta instanceof Relationship) { + throw new \TypeError('Argument 1 must be of type '.Relationship::class); + } + $query = (new Query) ->match('start') ->linkedTo('end') @@ -37,6 +42,7 @@ public function __invoke( ->return('start', 'end', 'entity'); + /** @psalm-suppress InvalidArgument */ return new IdentityMatch( $query, Map::of('string', Entity::class) diff --git a/src/Translation/Match/AggregateTranslator.php b/src/Translation/Match/AggregateTranslator.php index 4db3b42..a5dc222 100644 --- a/src/Translation/Match/AggregateTranslator.php +++ b/src/Translation/Match/AggregateTranslator.php @@ -6,6 +6,7 @@ use Innmind\Neo4j\ONM\{ Translation\MatchTranslator, Metadata\Entity, + Metadata\Aggregate, Metadata\Aggregate\Child, IdentityMatch, }; @@ -19,11 +20,23 @@ final class AggregateTranslator implements MatchTranslator { + /** @var Set */ + private Set $variables; + + public function __construct() + { + $this->variables = Set::strings(); + } + /** * {@inheritdoc} */ public function __invoke(Entity $meta): IdentityMatch { + if (!$meta instanceof Aggregate) { + throw new \TypeError('Argument 1 must be of type '.Aggregate::class); + } + $query = (new Query) ->match( 'entity', @@ -31,25 +44,23 @@ public function __invoke(Entity $meta): IdentityMatch ) ->with('entity'); - $variables = Set::strings(); - $meta - ->children() - ->foreach(function( + $this->variables = $this->variables->clear(); + $query = $meta->children()->reduce( + $query, + function( + Query $query, string $property, Child $child - ) use ( - &$query, - &$variables - ) { + ): Query { $relName = Str::of('entity_')->append($property); $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $variables = $variables + $this->variables = $this->variables ->add($relName->toString()) ->add($childName->toString()); - $query = $query + return $query ->match('entity') ->linkedTo( $childName->toString(), @@ -62,7 +73,10 @@ public function __invoke(Entity $meta): IdentityMatch ); }); + $variables = $this->variables; + $this->variables = $this->variables->clear(); + /** @psalm-suppress InvalidArgument */ return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) diff --git a/src/Translation/Match/DelegationTranslator.php b/src/Translation/Match/DelegationTranslator.php index 101951c..c39f6fb 100644 --- a/src/Translation/Match/DelegationTranslator.php +++ b/src/Translation/Match/DelegationTranslator.php @@ -14,10 +14,18 @@ final class DelegationTranslator implements MatchTranslator { + /** @var Map */ private Map $translators; + /** + * @param Map|null $translators + */ public function __construct(Map $translators = null) { + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->translators = $translators ?? Map::of('string', MatchTranslator::class) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); diff --git a/src/Translation/Match/RelationshipTranslator.php b/src/Translation/Match/RelationshipTranslator.php index b8cb339..b6052ac 100644 --- a/src/Translation/Match/RelationshipTranslator.php +++ b/src/Translation/Match/RelationshipTranslator.php @@ -6,6 +6,7 @@ use Innmind\Neo4j\ONM\{ Translation\MatchTranslator, Metadata\Entity, + Metadata\Relationship, IdentityMatch, }; use Innmind\Neo4j\DBAL\Query\Query; @@ -18,6 +19,10 @@ final class RelationshipTranslator implements MatchTranslator */ public function __invoke(Entity $meta): IdentityMatch { + if (!$meta instanceof Relationship) { + throw new \TypeError('Argument 1 must be of type '.Relationship::class); + } + $query = (new Query) ->match('start') ->linkedTo('end') @@ -29,6 +34,7 @@ public function __invoke(Entity $meta): IdentityMatch ->return('start', 'end', 'entity'); + /** @psalm-suppress InvalidArgument */ return new IdentityMatch( $query, Map::of('string', Entity::class) diff --git a/src/Translation/Result/AggregateTranslator.php b/src/Translation/Result/AggregateTranslator.php index 5e3c7f4..5adb613 100644 --- a/src/Translation/Result/AggregateTranslator.php +++ b/src/Translation/Result/AggregateTranslator.php @@ -43,6 +43,7 @@ public function __invoke( throw new InvalidArgumentException; } + /** @var Set> */ return $result ->rows() ->filter(static function(Row $row) use ($variable) { @@ -51,6 +52,7 @@ public function __invoke( ->reduce( Set::of(Map::class), function(Set $carry, Row $row) use ($meta, $result): Set { + /** @psalm-suppress PossiblyInvalidArrayAccess */ return $carry->add($this->translateNode( $row->value()[$meta->identity()->property()], $meta, @@ -60,9 +62,14 @@ function(Set $carry, Row $row) use ($meta, $result): Set { ); } + /** + * @param mixed $identity + * + * @return Map + */ private function translateNode( $identity, - Entity $meta, + Aggregate $meta, Result $result ): Map { $node = $result @@ -76,7 +83,9 @@ private function translateNode( }) ->values() ->first(); - $data = Map::of('string', 'mixed') + /** @var Map */ + $data = Map::of('string', 'mixed'); + $data = ($data) ( $meta->identity()->property(), $node->properties()->get( @@ -107,6 +116,7 @@ static function(Map $carry, string $name) use ($node): Map { ); try { + /** @var Map */ return $meta ->children() ->reduce( @@ -159,6 +169,10 @@ private function translateRelationship( Result $result, Relationship $relationship ): Map { + /** + * @psalm-suppress InvalidArgument + * @psalm-suppress InvalidScalarArgument + */ return $meta ->relationship() ->properties() diff --git a/src/Translation/Result/RelationshipTranslator.php b/src/Translation/Result/RelationshipTranslator.php index 8450bab..c8fbb3b 100644 --- a/src/Translation/Result/RelationshipTranslator.php +++ b/src/Translation/Result/RelationshipTranslator.php @@ -39,6 +39,7 @@ public function __invoke( throw new InvalidArgumentException; } + /** @var Set> */ return $result ->rows() ->filter(static function(Row $row) use ($variable) { @@ -47,6 +48,7 @@ public function __invoke( ->reduce( Set::of(Map::class), function(Set $carry, Row $row) use ($meta, $result): Set { + /** @psalm-suppress PossiblyInvalidArrayAccess */ return $carry->add( $this->translateRelationship( $row->value()[$meta->identity()->property()], @@ -58,9 +60,14 @@ function(Set $carry, Row $row) use ($meta, $result): Set { ); } + /** + * @param mixed $identity + * + * @return Map + */ private function translateRelationship( $identity, - Entity $meta, + Relationship $meta, Result $result ): Map { $relationship = $result @@ -74,7 +81,9 @@ private function translateRelationship( }) ->values() ->first(); - $data = Map::of('string', 'mixed') + /** @var Map */ + $data = Map::of('string', 'mixed'); + $data = ($data) ( $meta->identity()->property(), $relationship->properties()->get( @@ -98,6 +107,7 @@ private function translateRelationship( ->get($meta->endNode()->target()) ); + /** @var Map */ return $meta ->properties() ->filter(static function(string $name, Property $property) use ($relationship): bool { diff --git a/src/Translation/ResultTranslator.php b/src/Translation/ResultTranslator.php index 71e3231..49024b3 100644 --- a/src/Translation/ResultTranslator.php +++ b/src/Translation/ResultTranslator.php @@ -21,10 +21,18 @@ final class ResultTranslator { + /** @var Map */ private Map $translators; + /** + * @param Map|null $translators + */ public function __construct(Map $translators = null) { + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->translators = $translators ?? Map::of('string', EntityTranslator::class) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); @@ -61,6 +69,7 @@ public function __invoke( )); } + /** @var Map>> */ return $variables ->filter(static function(string $variable) use ($result): bool { $forVariable = $result diff --git a/src/Translation/Specification/AggregateTranslator.php b/src/Translation/Specification/AggregateTranslator.php index 772b493..76f5586 100644 --- a/src/Translation/Specification/AggregateTranslator.php +++ b/src/Translation/Specification/AggregateTranslator.php @@ -9,7 +9,9 @@ Translation\Specification\Visitor\Cypher\AggregateVisitor as AggregateCypherVisitor, Metadata\Aggregate\Child, Metadata\Entity, + Metadata\Aggregate, IdentityMatch, + Query\PropertiesMatch, Exception\SpecificationNotApplicableAsPropertyMatch, }; use Innmind\Neo4j\DBAL\Query\Query; @@ -23,6 +25,14 @@ final class AggregateTranslator implements SpecificationTranslator { + /** @var Set */ + private Set $variables; + + public function __construct() + { + $this->variables = Set::strings(); + } + /** * {@inheritdoc} */ @@ -30,7 +40,11 @@ public function __invoke( Entity $meta, Specification $specification ): IdentityMatch { - $variables = Set::strings(); + if (!$meta instanceof Aggregate) { + throw new \TypeError('Argument 1 must be of type '.Aggregate::class); + } + + $this->variables = $this->variables->clear(); try { $mapping = (new AggregatePropertyMatchVisitor($meta))($specification); @@ -46,25 +60,24 @@ public function __invoke( ) ->with('entity'); - $meta - ->children() - ->foreach(function( + $query = $meta->children()->reduce( + $query, + function( + Query $query, string $property, Child $child ) use ( - &$query, - $mapping, - &$variables - ): void { + $mapping + ): Query { $relName = Str::of('entity_')->append($property); $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $variables = $variables + $this->variables = $this->variables ->add($relName->toString()) ->add($childName->toString()); - $query = $this->addProperties( + return $this->addProperties( $this ->addProperties( $query @@ -93,24 +106,22 @@ public function __invoke( ) ->with('entity'); - $meta - ->children() - ->foreach(function( + $query = $meta->children()->reduce( + $query, + function( + Query $query, string $property, Child $child - ) use ( - &$query, - &$variables - ): void { + ): Query { $relName = Str::of('entity_')->append($property); $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $variables = $variables + $this->variables = $this->variables ->add($relName->toString()) ->add($childName->toString()); - $query = $query + return $query ->match('entity') ->linkedTo( $childName->toString(), @@ -132,6 +143,13 @@ static function(Query $query, string $key, $value): Query { ); } + $variables = $this->variables; + $this->variables = $this->variables->clear(); + + /** + * @psalm-suppress InvalidArgument + * @psalm-suppress MixedArgument + */ return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) diff --git a/src/Translation/Specification/DelegationTranslator.php b/src/Translation/Specification/DelegationTranslator.php index 4f0e695..73d5d6d 100644 --- a/src/Translation/Specification/DelegationTranslator.php +++ b/src/Translation/Specification/DelegationTranslator.php @@ -16,13 +16,21 @@ final class DelegationTranslator implements SpecificationTranslator { + /** @var Map */ private Map $translators; private Validator $validate; + /** + * @param Map|null $translators + */ public function __construct( Map $translators = null, Validator $validate = null ) { + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->translators = $translators ?? Map::of('string', SpecificationTranslator::class) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); diff --git a/src/Translation/Specification/RelationshipTranslator.php b/src/Translation/Specification/RelationshipTranslator.php index 935cec2..bed6a06 100644 --- a/src/Translation/Specification/RelationshipTranslator.php +++ b/src/Translation/Specification/RelationshipTranslator.php @@ -8,7 +8,9 @@ Translation\Specification\Visitor\PropertyMatch\RelationshipVisitor as RelationshipPropertyMatchVisitor, Translation\Specification\Visitor\Cypher\RelationshipVisitor as RelationshipCypherVisitor, Metadata\Entity, + Metadata\Relationship, IdentityMatch, + Query\PropertiesMatch, Exception\SpecificationNotApplicableAsPropertyMatch, }; use Innmind\Neo4j\DBAL\Query\Query; @@ -24,6 +26,10 @@ public function __invoke( Entity $meta, Specification $specification ): IdentityMatch { + if (!$meta instanceof Relationship) { + throw new \TypeError('Argument 1 must be of type '.Relationship::class); + } + try { $mapping = (new RelationshipPropertyMatchVisitor($meta))($specification); @@ -67,6 +73,7 @@ static function(Query $query, string $key, $value): Query { ); } + /** @psalm-suppress InvalidArgument */ return new IdentityMatch( $query->return('start', 'end', 'entity'), Map::of('string', Entity::class) diff --git a/src/Translation/Specification/Validator/AggregateValidator.php b/src/Translation/Specification/Validator/AggregateValidator.php index f4b81f6..85f2097 100644 --- a/src/Translation/Specification/Validator/AggregateValidator.php +++ b/src/Translation/Specification/Validator/AggregateValidator.php @@ -53,7 +53,7 @@ public function __invoke( private function isValidProperty( string $property, - Entity $meta + Aggregate $meta ): bool { if ($meta->properties()->contains($property)) { return true; @@ -82,7 +82,7 @@ private function isValidProperty( case 3: $subPiece = $pieces->get(1)->toString(); - if (!$relationship->childProperty() === $subPiece) { + if ($relationship->childProperty() !== $subPiece) { return false; } diff --git a/src/Translation/Specification/Validator/DelegationValidator.php b/src/Translation/Specification/Validator/DelegationValidator.php index d19fe34..c71b9a6 100644 --- a/src/Translation/Specification/Validator/DelegationValidator.php +++ b/src/Translation/Specification/Validator/DelegationValidator.php @@ -14,10 +14,18 @@ final class DelegationValidator implements Validator { + /** @var Map */ private Map $validators; + /** + * @param Map|null $validators + */ public function __construct(Map $validators = null) { + /** + * @psalm-suppress InvalidArgument + * @var Map + */ $this->validators = $validators ?? Map::of('string', Validator::class) (Aggregate::class, new AggregateValidator) (Relationship::class, new RelationshipValidator); diff --git a/src/Translation/Specification/Validator/RelationshipValidator.php b/src/Translation/Specification/Validator/RelationshipValidator.php index ec8933c..74d7fdf 100644 --- a/src/Translation/Specification/Validator/RelationshipValidator.php +++ b/src/Translation/Specification/Validator/RelationshipValidator.php @@ -50,10 +50,8 @@ public function __invoke( return false; } - private function isValidProperty( - string $property, - Entity $meta - ): bool { + private function isValidProperty(string $property, Relationship $meta): bool + { if ($meta->properties()->contains($property)) { return true; } diff --git a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php index 7b915b3..b172d7b 100644 --- a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php @@ -8,6 +8,7 @@ Metadata\Aggregate, Query\Where, Specification\ConvertSign, + Exception\LogicException, }; use Innmind\Specification\{ Specification, @@ -49,10 +50,15 @@ public function __invoke(Specification $specification): Where $right = ($this)($specification->right()); $operator = Str::of((string) $specification->operator())->toLower()->toString(); + /** @var Where */ return $left->{$operator}($right); case $specification instanceof Not: return ($this)($specification->specification())->not(); + + default: + $class = \get_class($specification); + throw new LogicException("Unknown specification '$class'"); } } @@ -66,6 +72,9 @@ private function buildCondition(Comparator $specification): Where case $property->matches('/[a-zA-Z]+(\.[a-zA-Z]+)+/'): return $this->buildSubPropertyCondition($specification); + + default: + throw new LogicException("Unknown property '{$property->toString()}'"); } } @@ -77,6 +86,10 @@ private function buildPropertyCondition( ->append($prop) ->append((string) $this->count); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return new Where( \sprintf( 'entity.%s %s %s', @@ -108,6 +121,10 @@ private function buildSubPropertyCondition( ->append($pieces->last()->toString()) ->append((string) $this->count); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return new Where( \sprintf( '%s %s %s', diff --git a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php index b712f0e..d707cc2 100644 --- a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php @@ -10,6 +10,7 @@ Identity, Query\Where, Specification\ConvertSign, + Exception\LogicException, }; use Innmind\Specification\{ Specification, @@ -50,10 +51,15 @@ public function __invoke(Specification $specification): Where $right = ($this)($specification->right()); $operator = Str::of((string) $specification->operator())->toLower()->toString(); + /** @var Where */ return $left->{$operator}($right); case $specification instanceof Not: return ($this)($specification->specification())->not(); + + default: + $class = \get_class($specification); + throw new LogicException("Unknown specification '$class'"); } } @@ -78,6 +84,9 @@ private function buildCondition(Comparator $specification): Where $this->meta->endNode(), 'end' ); + + default: + throw new LogicException("Unknown property '$property'"); } } @@ -89,6 +98,10 @@ private function buildPropertyCondition( ->append($prop) ->append((string) $this->count); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return new Where( \sprintf( 'entity.%s %s %s', @@ -110,12 +123,18 @@ private function buildEdgeCondition( ->append('_') ->append($edge->target()) ->append((string) $this->count); + /** @var mixed */ $value = $specification->value(); if ($value instanceof Identity) { + /** @var mixed */ $value = $value->value(); } + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return new Where( \sprintf( '%s.%s %s %s', diff --git a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php index 238f2eb..ca93657 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php @@ -7,6 +7,7 @@ Translation\Specification\Visitor\PropertyMatchVisitor, Metadata\Aggregate, Exception\SpecificationNotApplicableAsPropertyMatch, + Exception\LogicException, Query\PropertiesMatch, }; use Innmind\Specification\{ @@ -58,9 +59,11 @@ public function __invoke(Specification $specification): Map throw new SpecificationNotApplicableAsPropertyMatch; } - private function buildMapping( - Comparator $specification - ): Map { + /** + * @return Map + */ + private function buildMapping(Comparator $specification): Map + { $property = Str::of($specification->property()); switch (true) { @@ -69,15 +72,24 @@ private function buildMapping( case $property->matches('/[a-zA-Z]+(\.[a-zA-Z]+)+/'): return $this->buildSubPropertyMapping($specification); + + default: + throw new LogicException("Unknown property '{$property->toString()}'"); } } - private function buildPropertyMapping( - Comparator $specification - ): Map { + /** + * @return Map + */ + private function buildPropertyMapping(Comparator $specification): Map + { $prop = $specification->property(); $key = Str::of('entity_')->append($prop); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return Map::of('string', PropertiesMatch::class) ( 'entity', @@ -90,9 +102,11 @@ private function buildPropertyMapping( ); } - private function buildSubPropertyMapping( - Comparator $specification - ): Map { + /** + * @return Map + */ + private function buildSubPropertyMapping(Comparator $specification): Map + { $prop = Str::of($specification->property()); $pieces = $prop->split('.'); $var = Str::of('entity_')->append( @@ -106,6 +120,10 @@ private function buildSubPropertyMapping( ); $key = $var->append('_')->append($pieces->last()->toString()); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return Map::of('string', PropertiesMatch::class) ( $var->toString(), @@ -124,10 +142,15 @@ private function buildSubPropertyMapping( ); } - private function merge( - Map $left, - Map $right - ): Map { + /** + * @param Map $left + * @param Map $right + * + * @return Map + */ + private function merge(Map $left, Map $right): Map + { + /** @var Map */ return $right->reduce( $left, static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { diff --git a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php index a87a79c..5ef3327 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php @@ -9,6 +9,7 @@ Metadata\RelationshipEdge, Identity, Exception\SpecificationNotApplicableAsPropertyMatch, + Exception\LogicException, Query\PropertiesMatch, }; use Innmind\Specification\{ @@ -59,9 +60,11 @@ public function __invoke(Specification $specification): Map throw new SpecificationNotApplicableAsPropertyMatch; } - private function buildMapping( - Comparator $specification - ): Map { + /** + * @return Map + */ + private function buildMapping(Comparator $specification): Map + { $property = $specification->property(); switch (true) { @@ -81,15 +84,24 @@ private function buildMapping( $this->meta->endNode(), 'end' ); + + default: + throw new LogicException("Unknown property '$property'"); } } - private function buildPropertyMapping( - Comparator $specification - ): Map { + /** + * @return Map + */ + private function buildPropertyMapping(Comparator $specification): Map + { $prop = $specification->property(); $key = Str::of('entity_')->append($prop); + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return Map::of('string', PropertiesMatch::class) ( 'entity', @@ -102,6 +114,9 @@ private function buildPropertyMapping( ); } + /** + * @return Map + */ private function buildEdgeMapping( Comparator $specification, RelationshipEdge $edge, @@ -110,12 +125,18 @@ private function buildEdgeMapping( $key = Str::of($side) ->append('_') ->append($edge->target()); + /** @var mixed */ $value = $specification->value(); if ($value instanceof Identity) { + /** @var mixed */ $value = $value->value(); } + /** + * @psalm-suppress MixedArgument + * @psalm-suppress InvalidArgument + */ return Map::of('string', PropertiesMatch::class) ( $side, @@ -134,10 +155,15 @@ private function buildEdgeMapping( ); } - private function merge( - Map $left, - Map $right - ): Map { + /** + * @param Map $left + * @param Map $right + * + * @return Map + */ + private function merge(Map $left, Map $right): Map + { + /** @var Map */ return $right->reduce( $left, static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { diff --git a/src/Translation/Specification/Visitor/PropertyMatchVisitor.php b/src/Translation/Specification/Visitor/PropertyMatchVisitor.php index f528dc4..bc536a3 100644 --- a/src/Translation/Specification/Visitor/PropertyMatchVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatchVisitor.php @@ -3,6 +3,10 @@ namespace Innmind\Neo4j\ONM\Translation\Specification\Visitor; +use Innmind\Neo4j\ONM\{ + Query\PropertiesMatch, + Exception\SpecificationNotApplicableAsPropertyMatch, +}; use Innmind\Specification\Specification; use Innmind\Immutable\Map; @@ -11,7 +15,7 @@ interface PropertyMatchVisitor /** * Return a map composed of the property map and the associated parameters * - * @throws SpecificationNotApplicableAsPropertyMatchException + * @throws SpecificationNotApplicableAsPropertyMatch * * @return Map */ diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index e50a293..5760ac8 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -41,7 +41,9 @@ public function forDatabase($value) $array = []; + /** @var mixed $sub */ foreach ($value as $sub) { + /** @psalm-suppress MixedAssignment */ $array[] = $this->inner->forDatabase($sub); } @@ -55,7 +57,9 @@ public function fromDatabase($value) { $array = []; + /** @var mixed $sub */ foreach ($value as $sub) { + /** @psalm-suppress MixedAssignment */ $array[] = $this->inner->fromDatabase($sub); } diff --git a/src/Type/DateType.php b/src/Type/DateType.php index 49d54ac..76de3f2 100644 --- a/src/Type/DateType.php +++ b/src/Type/DateType.php @@ -58,6 +58,7 @@ public function forDatabase($value) } if (!$value instanceof \DateTimeInterface) { + /** @psalm-suppress MixedArgument */ throw new InvalidArgumentException(sprintf( 'The value "%s" must be an instance of DateTimeInterface', $value @@ -73,9 +74,11 @@ public function forDatabase($value) public function fromDatabase($value) { if ($this->immutable) { + /** @psalm-suppress MixedArgument */ return \DateTimeImmutable::createFromFormat($this->format, $value); } + /** @psalm-suppress MixedArgument */ return \DateTime::createFromFormat($this->format, $value); } diff --git a/src/Type/PointInTimeType.php b/src/Type/PointInTimeType.php index ed4155b..aac3ab7 100644 --- a/src/Type/PointInTimeType.php +++ b/src/Type/PointInTimeType.php @@ -42,6 +42,7 @@ public function forDatabase($value) } if (!$value instanceof PointInTimeInterface) { + /** @psalm-suppress MixedArgument */ throw new InvalidArgumentException(sprintf( 'The value "%s" must be an instance of PointInTimeInterface', $value @@ -56,6 +57,7 @@ public function forDatabase($value) */ public function fromDatabase($value) { + /** @psalm-suppress MixedArgument */ return new PointInTime($value); } diff --git a/src/Type/SetType.php b/src/Type/SetType.php index 59a967a..d3f6869 100644 --- a/src/Type/SetType.php +++ b/src/Type/SetType.php @@ -56,6 +56,7 @@ public function forDatabase($value) return $value->reduce( [], function(array $carry, $value): array { + /** @psalm-suppress MixedAssignment */ $carry[] = $this->inner->forDatabase($value); return $carry; @@ -70,7 +71,9 @@ public function fromDatabase($value) { $set = Set::of($this->type); + /** @var mixed $sub */ foreach ($value as $sub) { + /** @psalm-suppress MixedArgument */ $set = $set->add($this->inner->fromDatabase($sub)); } diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 78818f4..c1394cc 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -182,7 +182,7 @@ public function detach(object $entity): self /** * Execute the given query * - * @param Map $variables + * @param Map $variables * * @return Set */ @@ -213,6 +213,7 @@ private function extractIdentity(object $entity): Identity { $identity = ($this->metadata)(get_class($entity))->identity()->property(); + /** @var Identity */ return ReflectionObject::of($entity) ->extract($identity) ->get($identity); diff --git a/src/bootstrap.php b/src/bootstrap.php index 0676492..4310d7d 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -21,14 +21,16 @@ /** * @param Set $metas - * @param Map|null $additionalGenerators - * @param Map|null $repositories + * @param Map|null $additionalGenerators + * @param Map|null $repositories * @param Set|null $entityFactories - * @param Map|null $resultTranslators - * @param Map|null $identityMatchTranslators - * @param Map|null $matchTranslators - * @param Map|null $specificationTranslators - * @param Map|null $dataExtractors + * @param Map|null $resultTranslators + * @param Map|null $identityMatchTranslators + * @param Map|null $matchTranslators + * @param Map|null $specificationTranslators + * @param Map|null $dataExtractors + * + * @return array{manager: Manager, command_bus: array{clear_domain_events: callable(CommandBusInterface): CommandBusInterface, dispatch_domain_events: callable(CommandBusInterface): CommandBusInterface, flush: callable(CommandBusInterface): CommandBusInterface, transaction: callable(CommandBusInterface): CommandBusInterface}} */ function bootstrap( Connection $connection, @@ -46,19 +48,39 @@ function bootstrap( ): array { $eventBus = $eventBus ?? new NullEventBus; - $resultTranslators = $resultTranslators ?? Map::of('string', Translation\EntityTranslator::class) + /** + * @psalm-suppress InvalidScalarArgument + * @psalm-suppress InvalidArgument + */ + $resultTranslators ??= Map::of('string', Translation\EntityTranslator::class) (Aggregate::class, new Translation\Result\AggregateTranslator) (Relationship::class, new Translation\Result\RelationshipTranslator); - $identityMatchTranslators = $identityMatchTranslators ?? Map::of('string', Translation\IdentityMatchTranslator::class) + /** + * @psalm-suppress InvalidScalarArgument + * @psalm-suppress InvalidArgument + */ + $identityMatchTranslators ??= Map::of('string', Translation\IdentityMatchTranslator::class) (Aggregate::class, new Translation\IdentityMatch\AggregateTranslator) (Relationship::class, new Translation\IdentityMatch\RelationshipTranslator); - $matchTranslators = $matchTranslators ?? Map::of('string', Translation\MatchTranslator::class) + /** + * @psalm-suppress InvalidScalarArgument + * @psalm-suppress InvalidArgument + */ + $matchTranslators ??= Map::of('string', Translation\MatchTranslator::class) (Aggregate::class, new Translation\Match\AggregateTranslator) (Relationship::class, new Translation\Match\RelationshipTranslator); - $specificationTranslators = $specificationTranslators ?? Map::of('string', Translation\SpecificationTranslator::class) + /** + * @psalm-suppress InvalidScalarArgument + * @psalm-suppress InvalidArgument + */ + $specificationTranslators ??= Map::of('string', Translation\SpecificationTranslator::class) (Aggregate::class, new Translation\Specification\AggregateTranslator) (Relationship::class, new Translation\Specification\RelationshipTranslator); - $dataExtractors = $dataExtractors ?? Map::of('string', Entity\DataExtractor::class) + /** + * @psalm-suppress InvalidScalarArgument + * @psalm-suppress InvalidArgument + */ + $dataExtractors ??= Map::of('string', Entity\DataExtractor::class) (Aggregate::class, new Entity\DataExtractor\AggregateExtractor) (Relationship::class, new Entity\DataExtractor\RelationshipExtractor); From 1187d9e69cfabcc478e2e2982c80e8a9e9af77ea Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 17:03:23 +0100 Subject: [PATCH 08/17] make constant private --- src/Identity/Uuid.php | 2 +- tests/Identity/Generator/UuidGeneratorTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Identity/Uuid.php b/src/Identity/Uuid.php index 2d6242a..cd04b6a 100644 --- a/src/Identity/Uuid.php +++ b/src/Identity/Uuid.php @@ -11,7 +11,7 @@ class Uuid implements Identity { - const PATTERN = '/^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/'; + private const PATTERN = '/^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/'; private string $value; diff --git a/tests/Identity/Generator/UuidGeneratorTest.php b/tests/Identity/Generator/UuidGeneratorTest.php index ed4fe30..9165971 100644 --- a/tests/Identity/Generator/UuidGeneratorTest.php +++ b/tests/Identity/Generator/UuidGeneratorTest.php @@ -73,7 +73,10 @@ public function __toString(): string $uuid2 = $generator->new(); $this->assertInstanceOf(get_class($uuid), $uuid2); - $this->assertRegExp(Uuid::PATTERN, $uuid2->value()); + $this->assertRegExp( + '/^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/', + $uuid2->value(), + ); } public function testThrowWhenEmptyType() From ae3a58d1d6e182c9ef8271b32c536384c1f63b9d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 17:20:07 +0100 Subject: [PATCH 09/17] rename __toString to toString --- src/EntityFactory/AggregateFactory.php | 6 +++--- src/EntityFactory/RelationshipFactory.php | 2 +- src/EntityFactory/Resolver.php | 3 +-- src/Exception/MoreThanOneRelationshipFound.php | 2 +- src/Identity.php | 2 +- src/Identity/Generator/UuidGenerator.php | 4 ++-- src/Identity/Uuid.php | 2 +- src/Metadata/ClassName.php | 2 +- src/Metadata/Factory.php | 2 +- src/Metadata/Identity.php | 5 ----- src/Metadata/Property.php | 5 ----- src/Metadata/RelationshipType.php | 2 +- src/Metadata/Repository.php | 2 +- src/Metadatas.php | 2 +- src/Persister/InsertPersister.php | 8 ++++---- src/Persister/RemovePersister.php | 8 ++++---- src/Persister/UpdatePersister.php | 8 ++++---- src/Repository/Repository.php | 2 +- src/RepositoryFactory.php | 3 +-- src/Translation/IdentityMatch/AggregateTranslator.php | 2 +- .../IdentityMatch/RelationshipTranslator.php | 2 +- src/Translation/Match/AggregateTranslator.php | 2 +- src/Translation/Match/RelationshipTranslator.php | 2 +- src/Translation/Result/AggregateTranslator.php | 2 +- src/Translation/Specification/AggregateTranslator.php | 4 ++-- .../Specification/RelationshipTranslator.php | 4 ++-- tests/EntityFactory/EntityFactoryTest.php | 10 +++++----- tests/Identity/Generator/UuidGeneratorTest.php | 2 +- tests/Identity/UuidTest.php | 2 +- tests/Metadata/AggregateTest.php | 4 ++-- tests/Metadata/ClassNameTest.php | 2 +- tests/Metadata/FactoryTest.php | 2 +- tests/Metadata/IdentityTest.php | 1 - tests/Metadata/RelationshipEdgeTest.php | 1 - tests/Metadata/RelationshipTest.php | 4 ++-- tests/Metadata/RelationshipTypeTest.php | 2 +- tests/Metadata/RepositoryTest.php | 2 +- 37 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/EntityFactory/AggregateFactory.php b/src/EntityFactory/AggregateFactory.php index a844428..1e297bd 100644 --- a/src/EntityFactory/AggregateFactory.php +++ b/src/EntityFactory/AggregateFactory.php @@ -53,7 +53,7 @@ public function __invoke( } $reflection = $this - ->reflection((string) $meta->class()) + ->reflection($meta->class()->toString()) ->withProperty( $meta->identity()->property(), $identity @@ -130,7 +130,7 @@ private function buildRelationship(Child $meta, Map $data): object return true; }) ->reduce( - $this->reflection((string) $relationship->class()), + $this->reflection($relationship->class()->toString()), static function(ReflectionClass $carry, string $name, Property $property) use ($data): ReflectionClass { return $carry->withProperty( $name, @@ -169,7 +169,7 @@ private function buildValueObject( return true; }) ->reduce( - $this->reflection((string) $meta->class()), + $this->reflection($meta->class()->toString()), static function(ReflectionClass $carry, string $name, Property $property) use ($data): ReflectionClass { return $carry->withProperty( $name, diff --git a/src/EntityFactory/RelationshipFactory.php b/src/EntityFactory/RelationshipFactory.php index 5def4c8..c612815 100644 --- a/src/EntityFactory/RelationshipFactory.php +++ b/src/EntityFactory/RelationshipFactory.php @@ -52,7 +52,7 @@ public function __invoke( } $reflection = ReflectionClass::of( - (string) $meta->class(), + $meta->class()->toString(), null, $this->injectionStrategy, $this->instanciator diff --git a/src/EntityFactory/Resolver.php b/src/EntityFactory/Resolver.php index e013799..dfe503d 100644 --- a/src/EntityFactory/Resolver.php +++ b/src/EntityFactory/Resolver.php @@ -29,8 +29,7 @@ public function __construct(EntityFactoryInterface ...$factories) */ public function __invoke(Entity $meta): EntityFactoryInterface { - /** @var class-string */ - $class = (string) $meta->factory(); + $class = $meta->factory()->toString(); if ($this->mapping->contains($class)) { return $this->mapping->get($class); diff --git a/src/Exception/MoreThanOneRelationshipFound.php b/src/Exception/MoreThanOneRelationshipFound.php index 928b7e7..e89dd3c 100644 --- a/src/Exception/MoreThanOneRelationshipFound.php +++ b/src/Exception/MoreThanOneRelationshipFound.php @@ -30,7 +30,7 @@ public function on(Entity $entity): self $exception = new self( \sprintf( 'More than one relationship found on "%s::%s"', - (string) $entity->class(), + $entity->class()->toString(), $this->child->relationship()->property(), ), $this->child, diff --git a/src/Identity.php b/src/Identity.php index e6d9232..0f3529e 100644 --- a/src/Identity.php +++ b/src/Identity.php @@ -15,5 +15,5 @@ public function value(); /** * Return the string representation of the identifier */ - public function __toString(): string; + public function toString(): string; } diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 8dede7f..8988962 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -42,7 +42,7 @@ public function new(): Identity $class = (string) $this->identities->valueType(); $uuid = new $class((string) Factory::uuid4()); $this->identities = $this->identities->put( - (string) $uuid, + $uuid->toString(), $uuid ); @@ -74,7 +74,7 @@ public function add(Identity $identity): Generator { /** @psalm-suppress ArgumentTypeCoercion */ $this->identities = $this->identities->put( - (string) $identity, + $identity->toString(), $identity ); diff --git a/src/Identity/Uuid.php b/src/Identity/Uuid.php index cd04b6a..287e8de 100644 --- a/src/Identity/Uuid.php +++ b/src/Identity/Uuid.php @@ -35,7 +35,7 @@ public function value() /** * {@inheritdoc} */ - public function __toString(): string + public function toString(): string { return $this->value; } diff --git a/src/Metadata/ClassName.php b/src/Metadata/ClassName.php index ba9ea60..3e659cc 100644 --- a/src/Metadata/ClassName.php +++ b/src/Metadata/ClassName.php @@ -26,7 +26,7 @@ public function __construct(string $class) /** * @return class-string */ - public function __toString(): string + public function toString(): string { return $this->class; } diff --git a/src/Metadata/Factory.php b/src/Metadata/Factory.php index 348c262..5708e85 100644 --- a/src/Metadata/Factory.php +++ b/src/Metadata/Factory.php @@ -32,7 +32,7 @@ public function __construct(string $class) /** * @return class-string */ - public function __toString(): string + public function toString(): string { return $this->class; } diff --git a/src/Metadata/Identity.php b/src/Metadata/Identity.php index e97b54d..6dbe08a 100644 --- a/src/Metadata/Identity.php +++ b/src/Metadata/Identity.php @@ -33,9 +33,4 @@ public function property(): string { return $this->property; } - - public function __toString(): string - { - return $this->property; - } } diff --git a/src/Metadata/Property.php b/src/Metadata/Property.php index 647cf6c..ddb6c5e 100644 --- a/src/Metadata/Property.php +++ b/src/Metadata/Property.php @@ -29,11 +29,6 @@ public function name(): string return $this->name; } - public function __toString(): string - { - return $this->name(); - } - public function type(): Type { return $this->type; diff --git a/src/Metadata/RelationshipType.php b/src/Metadata/RelationshipType.php index 3042083..c153475 100644 --- a/src/Metadata/RelationshipType.php +++ b/src/Metadata/RelationshipType.php @@ -19,7 +19,7 @@ public function __construct(string $type) $this->type = $type; } - public function __toString(): string + public function toString(): string { return $this->type; } diff --git a/src/Metadata/Repository.php b/src/Metadata/Repository.php index ab40876..6a3adba 100644 --- a/src/Metadata/Repository.php +++ b/src/Metadata/Repository.php @@ -32,7 +32,7 @@ public function __construct(string $class) /** * @return class-string */ - public function __toString(): string + public function toString(): string { return $this->class; } diff --git a/src/Metadatas.php b/src/Metadatas.php index 9a410f3..28545b3 100644 --- a/src/Metadatas.php +++ b/src/Metadatas.php @@ -34,7 +34,7 @@ public function __invoke(string $class): Entity */ private function register(Entity $meta): self { - $this->mapping = $this->mapping->put((string) $meta->class(), $meta); + $this->mapping = $this->mapping->put($meta->class()->toString(), $meta); return $this; } diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index b3ddc53..a8b54ac 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -129,7 +129,7 @@ private function createAggregate( /** @var Aggregate */ $meta = ($this->metadata)(\get_class($entity)); $data = ($this->extract)($entity); - $varName = $this->name->sprintf(\md5((string) $identity->value())); + $varName = $this->name->sprintf(\md5($identity->toString())); $query = $query->create( $varName->toString(), @@ -261,7 +261,7 @@ static function(array $carry, string $key, $value): array { ) ) ->through( - (string) $meta->relationship()->type(), + $meta->relationship()->type()->toString(), $relationshipName->toString(), 'left' ) @@ -329,7 +329,7 @@ private function createRelationship( $start = $data->get($meta->startNode()->property()); /** @var mixed */ $end = $data->get($meta->endNode()->property()); - $varName = $this->name->sprintf(\md5((string) $identity->value())); + $varName = $this->name->sprintf(\md5($identity->toString())); $startName = $this->name->sprintf(\md5((string) $start)); $endName = $this->name->sprintf(\md5((string) $end)); @@ -353,7 +353,7 @@ private function createRelationship( ->create($startName->toString()) ->linkedTo($endName->toString()) ->through( - (string) $meta->type(), + $meta->type()->toString(), $varName->toString(), 'right' ) diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 857690e..9becfae 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -126,14 +126,14 @@ private function matchRelationship( ): Query { /** @var Relationship */ $meta = ($this->metadata)(\get_class($entity)); - $name = $this->name->sprintf(\md5((string) $identity->value())); + $name = $this->name->sprintf(\md5($identity->toString())); $this->variables = $this->variables->add($name->toString()); return $query ->match() ->linkedTo() ->through( - (string) $meta->type(), + $meta->type()->toString(), $name->toString(), ) ->withProperty( @@ -159,7 +159,7 @@ private function matchAggregate( ): Query { /** @var Aggregate */ $meta = ($this->metadata)(\get_class($entity)); - $name = $this->name->sprintf(\md5((string) $identity->value())); + $name = $this->name->sprintf(\md5($identity->toString())); $this->variables = $this->variables->add($name->toString()); $query = $query @@ -196,7 +196,7 @@ function(Query $carry, string $property, Child $child) use ($name): Query { ...unwrap($child->labels()), ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName = $name ->append('_') ->append($child->relationship()->property()) diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index 965496f..5a2af72 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -172,7 +172,7 @@ private function matchAggregate( Map $changeset, Query $query ): Query { - $name = $this->name->sprintf(\md5((string) $identity->value())); + $name = $this->name->sprintf(\md5($identity->toString())); $query = $query ->match( $name->toString(), @@ -241,7 +241,7 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): ...unwrap($child->labels()), ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName->toString(), ); } @@ -260,7 +260,7 @@ private function matchRelationship( Map $changeset, Query $query ): Query { - $name = $this->name->sprintf(\md5((string) $identity->value())); + $name = $this->name->sprintf(\md5($identity->toString())); $this->variables = $this->variables->put( $name, $this->buildProperties( @@ -273,7 +273,7 @@ private function matchRelationship( ->match() ->linkedTo() ->through( - (string) $meta->type(), + $meta->type()->toString(), $name->toString(), ) ->withProperty( diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 584214c..7ceda31 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -75,7 +75,7 @@ public function has(Identity $identity): bool public function get(Identity $identity): object { $entity = $this->unitOfWork()->get( - (string) $this->metadata()->class(), + $this->metadata()->class()->toString(), $identity ); $state = $this->unitOfWork()->stateFor($identity); diff --git a/src/RepositoryFactory.php b/src/RepositoryFactory.php index 4cff11f..971d5a2 100644 --- a/src/RepositoryFactory.php +++ b/src/RepositoryFactory.php @@ -56,8 +56,7 @@ public function __invoke(Entity $meta): Repository return $this->repositories->get($meta); } - /** @var class-string */ - $class = (string) $meta->repository(); + $class = $meta->repository()->toString(); /** @var Repository */ $repository = new $class( $this->unitOfWork, diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index 9fa11cf..f7abe0c 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -75,7 +75,7 @@ function( ...unwrap($child->labels()) ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName->toString(), 'left' ); diff --git a/src/Translation/IdentityMatch/RelationshipTranslator.php b/src/Translation/IdentityMatch/RelationshipTranslator.php index 73c72d2..8e4f21e 100644 --- a/src/Translation/IdentityMatch/RelationshipTranslator.php +++ b/src/Translation/IdentityMatch/RelationshipTranslator.php @@ -30,7 +30,7 @@ public function __invoke( ->match('start') ->linkedTo('end') ->through( - (string) $meta->type(), + $meta->type()->toString(), 'entity', 'right' ) diff --git a/src/Translation/Match/AggregateTranslator.php b/src/Translation/Match/AggregateTranslator.php index a5dc222..5bfe53d 100644 --- a/src/Translation/Match/AggregateTranslator.php +++ b/src/Translation/Match/AggregateTranslator.php @@ -67,7 +67,7 @@ function( ...unwrap($child->labels()), ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName->toString(), 'left' ); diff --git a/src/Translation/Match/RelationshipTranslator.php b/src/Translation/Match/RelationshipTranslator.php index b6052ac..e731ede 100644 --- a/src/Translation/Match/RelationshipTranslator.php +++ b/src/Translation/Match/RelationshipTranslator.php @@ -27,7 +27,7 @@ public function __invoke(Entity $meta): IdentityMatch ->match('start') ->linkedTo('end') ->through( - (string) $meta->type(), + $meta->type()->toString(), 'entity', 'right' ) diff --git a/src/Translation/Result/AggregateTranslator.php b/src/Translation/Result/AggregateTranslator.php index 5adb613..b6fb38c 100644 --- a/src/Translation/Result/AggregateTranslator.php +++ b/src/Translation/Result/AggregateTranslator.php @@ -148,7 +148,7 @@ private function translateChild( $node, $relMeta ): bool { - return $relationship->type()->value() === (string) $relMeta->type() && + return $relationship->type()->value() === $relMeta->type()->toString() && $relationship->endNode()->value() === $node->id()->value(); }) ->values(); diff --git a/src/Translation/Specification/AggregateTranslator.php b/src/Translation/Specification/AggregateTranslator.php index 76f5586..b6fccb0 100644 --- a/src/Translation/Specification/AggregateTranslator.php +++ b/src/Translation/Specification/AggregateTranslator.php @@ -90,7 +90,7 @@ function( $mapping ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName->toString(), 'left' ), @@ -128,7 +128,7 @@ function( ...unwrap($child->labels()), ) ->through( - (string) $child->relationship()->type(), + $child->relationship()->type()->toString(), $relName->toString(), 'left' ); diff --git a/src/Translation/Specification/RelationshipTranslator.php b/src/Translation/Specification/RelationshipTranslator.php index bed6a06..1b4ab86 100644 --- a/src/Translation/Specification/RelationshipTranslator.php +++ b/src/Translation/Specification/RelationshipTranslator.php @@ -47,7 +47,7 @@ public function __invoke( $mapping ) ->through( - (string) $meta->type(), + $meta->type()->toString(), 'entity', 'right' ), @@ -60,7 +60,7 @@ public function __invoke( ->match('start') ->linkedTo('end') ->through( - (string) $meta->type(), + $meta->type()->toString(), 'entity', 'right' ) diff --git a/tests/EntityFactory/EntityFactoryTest.php b/tests/EntityFactory/EntityFactoryTest.php index a133084..6380782 100644 --- a/tests/EntityFactory/EntityFactoryTest.php +++ b/tests/EntityFactory/EntityFactoryTest.php @@ -222,12 +222,12 @@ public function testMake() $this->assertCount(2, $entities); $entities = unwrap($entities); $this->assertInstanceOf( - (string) $aggregate->class(), + $aggregate->class()->toString(), \current($entities) ); \next($entities); $this->assertInstanceOf( - (string) $relationship->class(), + $relationship->class()->toString(), \current($entities) ); \reset($entities); @@ -247,7 +247,7 @@ public function testMake() ); $this->assertNull($aggregateRoot->empty); $this->assertInstanceOf( - (string) $aggregate->children()->get('rel')->relationship()->class(), + $aggregate->children()->get('rel')->relationship()->class()->toString(), $aggregateRoot->rel ); $this->assertInstanceOf( @@ -260,14 +260,14 @@ public function testMake() ); $this->assertNull($aggregateRoot->rel->empty); $this->assertInstanceOf( - (string) $aggregate->children()->get('rel')->class(), + $aggregate->children()->get('rel')->class()->toString(), $aggregateRoot->rel->child ); $this->assertSame('foo', $aggregateRoot->rel->child->content); $this->assertNull($aggregateRoot->rel->child->empty); \next($entities); $rel = \current($entities); - $this->assertInstanceOf((string) $relationship->class(), $rel); + $this->assertInstanceOf($relationship->class()->toString(), $rel); $this->assertInstanceOf(Uuid::class, $rel->uuid); $this->assertSame( '11111111-1111-1111-1111-111111111112', diff --git a/tests/Identity/Generator/UuidGeneratorTest.php b/tests/Identity/Generator/UuidGeneratorTest.php index 9165971..2deaa83 100644 --- a/tests/Identity/Generator/UuidGeneratorTest.php +++ b/tests/Identity/Generator/UuidGeneratorTest.php @@ -64,7 +64,7 @@ public function value() return $this->value; } - public function __toString(): string + public function toString(): string { return $this->value; } diff --git a/tests/Identity/UuidTest.php b/tests/Identity/UuidTest.php index 53a360a..0969466 100644 --- a/tests/Identity/UuidTest.php +++ b/tests/Identity/UuidTest.php @@ -18,7 +18,7 @@ public function testInterface() $this->assertInstanceOf(Identity::class, $uuid); $this->assertSame($string, $uuid->value()); - $this->assertSame($string, (string) $uuid); + $this->assertSame($string, $uuid->toString()); } public function testThrowWhenGlobalFormatNotRespected() diff --git a/tests/Metadata/AggregateTest.php b/tests/Metadata/AggregateTest.php index d5ae2f2..4c7157e 100644 --- a/tests/Metadata/AggregateTest.php +++ b/tests/Metadata/AggregateTest.php @@ -49,8 +49,8 @@ public function testInterface() $this->assertInstanceOf(Entity::class, $aggregateRoot); $this->assertSame($className, $aggregateRoot->class()); $this->assertSame($identity, $aggregateRoot->identity()); - $this->assertSame(Repository::class, (string) $aggregateRoot->repository()); - $this->assertSame(AggregateFactory::class, (string) $aggregateRoot->factory()); + $this->assertSame(Repository::class, $aggregateRoot->repository()->toString()); + $this->assertSame(AggregateFactory::class, $aggregateRoot->factory()->toString()); $this->assertInstanceOf(Set::class, $aggregateRoot->labels()); $this->assertSame('string', (string) $aggregateRoot->labels()->type()); $this->assertSame(['LabelA'], unwrap($aggregateRoot->labels())); diff --git a/tests/Metadata/ClassNameTest.php b/tests/Metadata/ClassNameTest.php index afe4b65..1ba47a8 100644 --- a/tests/Metadata/ClassNameTest.php +++ b/tests/Metadata/ClassNameTest.php @@ -15,7 +15,7 @@ public function testInterface() { $className = new ClassName('Class\Name\Space'); - $this->assertSame('Class\Name\Space', (string) $className); + $this->assertSame('Class\Name\Space', $className->toString()); } public function testThrowWhenEmptyClass() diff --git a/tests/Metadata/FactoryTest.php b/tests/Metadata/FactoryTest.php index 0630034..df4f28c 100644 --- a/tests/Metadata/FactoryTest.php +++ b/tests/Metadata/FactoryTest.php @@ -15,7 +15,7 @@ public function testInterface() { $factory = new Factory('Class\Name\SpaceFactory'); - $this->assertSame('Class\Name\SpaceFactory', (string) $factory); + $this->assertSame('Class\Name\SpaceFactory', $factory->toString()); } public function testThrowWhenEmptyClass() diff --git a/tests/Metadata/IdentityTest.php b/tests/Metadata/IdentityTest.php index 4deccaa..4361c9f 100644 --- a/tests/Metadata/IdentityTest.php +++ b/tests/Metadata/IdentityTest.php @@ -15,7 +15,6 @@ public function testInterface() { $identity = new Identity('uuid', 'UUID'); - $this->assertSame('uuid', (string) $identity); $this->assertSame('uuid', $identity->property()); $this->assertSame('UUID', $identity->type()); } diff --git a/tests/Metadata/RelationshipEdgeTest.php b/tests/Metadata/RelationshipEdgeTest.php index f8e0ba5..ca5d3bf 100644 --- a/tests/Metadata/RelationshipEdgeTest.php +++ b/tests/Metadata/RelationshipEdgeTest.php @@ -15,7 +15,6 @@ public function testInterface() { $edge = new RelationshipEdge('uuid', 'UUID', 'target'); - $this->assertSame('uuid', (string) $edge); $this->assertSame('uuid', $edge->property()); $this->assertSame('UUID', $edge->type()); $this->assertSame('target', $edge->target()); diff --git a/tests/Metadata/RelationshipTest.php b/tests/Metadata/RelationshipTest.php index 364af8c..4db4738 100644 --- a/tests/Metadata/RelationshipTest.php +++ b/tests/Metadata/RelationshipTest.php @@ -35,8 +35,8 @@ public function testInterface() $this->assertInstanceOf(Entity::class, $relationship); $this->assertSame($className, $relationship->class()); $this->assertSame($identity, $relationship->identity()); - $this->assertSame(Repository::class, (string) $relationship->repository()); - $this->assertSame(RelationshipFactory::class, (string) $relationship->factory()); + $this->assertSame(Repository::class, $relationship->repository()->toString()); + $this->assertSame(RelationshipFactory::class, $relationship->factory()->toString()); $this->assertSame($type, $relationship->type()); $this->assertSame($start, $relationship->startNode()); $this->assertSame($end, $relationship->endNode()); diff --git a/tests/Metadata/RelationshipTypeTest.php b/tests/Metadata/RelationshipTypeTest.php index 517f603..5f4c0fd 100644 --- a/tests/Metadata/RelationshipTypeTest.php +++ b/tests/Metadata/RelationshipTypeTest.php @@ -15,7 +15,7 @@ public function testInterface() { $type = new RelationshipType('FOO'); - $this->assertSame('FOO', (string) $type); + $this->assertSame('FOO', $type->toString()); } public function testThrowWhenEmptyType() diff --git a/tests/Metadata/RepositoryTest.php b/tests/Metadata/RepositoryTest.php index 5e00e44..4e5abf9 100644 --- a/tests/Metadata/RepositoryTest.php +++ b/tests/Metadata/RepositoryTest.php @@ -15,7 +15,7 @@ public function testInterface() { $repository = new Repository('Class\Name\SpaceRepository'); - $this->assertSame('Class\Name\SpaceRepository', (string) $repository); + $this->assertSame('Class\Name\SpaceRepository', $repository->toString()); } public function testThrowWhenEmptyClass() From 0bc50f57f116496bb198eaf94a9fa009afd0c6ba Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 18:13:47 +0100 Subject: [PATCH 10/17] CS --- src/Entity/ChangesetComputer.php | 21 ++--- src/Entity/Container.php | 2 +- .../DataExtractor/AggregateExtractor.php | 60 +++++-------- src/Entity/DataExtractor/DataExtractor.php | 21 ++--- .../DataExtractor/RelationshipExtractor.php | 30 ++----- src/EntityFactory/AggregateFactory.php | 56 +++++-------- src/EntityFactory/EntityFactory.php | 37 ++++---- src/EntityFactory/RelationshipFactory.php | 34 +++----- src/EntityFactory/Resolver.php | 10 +-- src/Identity/Generator/UuidGenerator.php | 29 ++----- src/Identity/Uuid.php | 6 -- src/IdentityMatch.php | 11 +-- src/Manager/Manager.php | 5 +- src/Metadata/Aggregate.php | 63 ++++---------- src/Metadata/Aggregate/Child.php | 24 ++---- src/Metadata/Aggregate/Child/Relationship.php | 19 ++--- src/Metadata/Relationship.php | 34 ++------ src/Metadatas.php | 6 +- src/Persister/DelegationPersister.php | 3 - src/Persister/InsertPersister.php | 81 ++++++++---------- src/Persister/RemovePersister.php | 27 +++--- src/Persister/UpdatePersister.php | 84 ++++++++----------- src/Query/PropertiesMatch.php | 18 +--- src/Query/Where.php | 14 ++-- src/Repository/Repository.php | 31 ++----- src/RepositoryFactory.php | 26 ++---- src/Translation/EntityTranslator.php | 6 +- .../IdentityMatch/AggregateTranslator.php | 13 ++- .../IdentityMatch/DelegationTranslator.php | 13 +-- .../IdentityMatch/RelationshipTranslator.php | 9 +- src/Translation/IdentityMatchTranslator.php | 5 +- src/Translation/Match/AggregateTranslator.php | 13 ++- .../Match/DelegationTranslator.php | 13 +-- .../Match/RelationshipTranslator.php | 7 +- .../Result/AggregateTranslator.php | 59 ++++++------- .../Result/RelationshipTranslator.php | 25 +++--- src/Translation/ResultTranslator.php | 35 ++------ .../Specification/AggregateTranslator.php | 27 +++--- .../Specification/DelegationTranslator.php | 13 +-- .../Specification/RelationshipTranslator.php | 21 ++--- src/Translation/Specification/Validator.php | 5 +- .../Validator/AggregateValidator.php | 11 +-- .../Validator/DelegationValidator.php | 22 ++--- .../Validator/RelationshipValidator.php | 9 +- .../Visitor/Cypher/AggregateVisitor.php | 17 ++-- .../Visitor/Cypher/RelationshipVisitor.php | 16 ++-- .../PropertyMatch/AggregateVisitor.php | 21 ++--- .../PropertyMatch/RelationshipVisitor.php | 25 +++--- src/Type/ArrayType.php | 9 -- src/Type/BooleanType.php | 9 -- src/Type/DateType.php | 15 +--- src/Type/FloatType.php | 9 -- src/Type/IntType.php | 9 -- src/Type/PointInTimeType.php | 13 +-- src/Type/SetType.php | 19 ++--- src/Type/StringType.php | 9 -- src/UnitOfWork.php | 22 +++-- src/bootstrap.php | 38 ++++----- 58 files changed, 432 insertions(+), 857 deletions(-) diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index 981e4ce..9fbba2a 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -8,6 +8,7 @@ Exception\InvalidArgumentException, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class ChangesetComputer { @@ -27,12 +28,7 @@ public function __construct() */ public function use(Identity $identity, Map $source): self { - if ( - (string) $source->keyType() !== 'string' || - (string) $source->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 2 must be of type Map'); - } + assertMap('string', 'mixed', $source, 2); $this->sources = $this->sources->put($identity, $source); @@ -48,12 +44,7 @@ public function use(Identity $identity, Map $source): self */ public function compute(Identity $identity, Map $target): Map { - if ( - (string) $target->keyType() !== 'string' || - (string) $target->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 2 must be of type Map'); - } + assertMap('string', 'mixed', $target, 2); if (!$this->sources->contains($identity)) { return $target; @@ -95,7 +86,7 @@ private function diff(Map $source, Map $target): Map $changeset, static function(Map $carry, string $property) use ($target): Map { return $carry->put($property, null); - } + }, ) ->map(function(string $property, $value) use ($source, $target) { if (!$value instanceof Map) { @@ -105,7 +96,7 @@ static function(Map $carry, string $property) use ($target): Map { /** @psalm-suppress MixedArgument */ return $this->diff( $source->get($property), - $target->get($property) + $target->get($property), ); }) ->filter(static function(string $property, $value) { @@ -113,7 +104,7 @@ static function(Map $carry, string $property) use ($target): Map { return true; } - return $value->size() !== 0; + return !$value->empty(); }); } } diff --git a/src/Entity/Container.php b/src/Entity/Container.php index b9350c8..7b5ce43 100644 --- a/src/Entity/Container.php +++ b/src/Entity/Container.php @@ -47,7 +47,7 @@ public function push(Identity $identity, object $entity, State $wished): self $wished ) { if ($wished === $state) { - return $entities->put($identity, $entity); + return ($entities)($identity, $entity); } return $entities->remove($identity); diff --git a/src/Entity/DataExtractor/AggregateExtractor.php b/src/Entity/DataExtractor/AggregateExtractor.php index 69f2c77..f4c3dbc 100644 --- a/src/Entity/DataExtractor/AggregateExtractor.php +++ b/src/Entity/DataExtractor/AggregateExtractor.php @@ -26,9 +26,6 @@ public function __construct() $this->extractionStrategy = new ReflectionStrategy; } - /** - * {@inheritdoc} - */ public function __invoke(object $entity, Entity $meta): Map { if (!$meta instanceof Aggregate) { @@ -44,7 +41,7 @@ public function __invoke(object $entity, Entity $meta): Map ->reflection($entity) ->extract($id) ->get($id) - ->value() + ->value(), ); /** @var Map */ @@ -53,24 +50,19 @@ public function __invoke(object $entity, Entity $meta): Map ->reduce( $data, function(Map $carry, string $property, Child $child) use ($entity): Map { - return $carry->put( + return ($carry)( $property, - $this->extractRelationship( - $child, - $entity - ) + $this->extractRelationship($child, $entity), ); - } + }, ); } /** * @return Map */ - private function extractRelationship( - Child $child, - object $entity - ): Map { + private function extractRelationship(Child $child, object $entity): Map + { /** @var object */ $rel = $this ->reflection($entity) @@ -78,10 +70,10 @@ private function extractRelationship( ->get($property); /** @psalm-suppress MixedArgument */ - $data = $this + return $this ->extractProperties( $rel, - $child->relationship()->properties() + $child->relationship()->properties(), ) ->put( $property = $child->relationship()->childProperty(), @@ -90,11 +82,9 @@ private function extractRelationship( ->reflection($rel) ->extract($property) ->get($property), - $child->properties() - ) + $child->properties(), + ), ); - - return $data; } /** @@ -102,25 +92,21 @@ private function extractRelationship( * * @return Map */ - private function extractProperties( - object $object, - Map $properties - ): Map { + private function extractProperties(object $object, Map $properties): Map + { $refl = $this->reflection($object); /** @var Map */ - return $properties->reduce( - Map::of('string', 'mixed'), - static function(Map $carry, string $name, Property $property) use ($refl): Map { - return $carry->put( - $name, - $property - ->type() - ->forDatabase( - $refl->extract($name)->get($name) - ) - ); - } + return $properties->toMapOf( + 'string', + 'mixed', + static function(string $name, Property $property) use ($refl): \Generator { + yield $name => $property + ->type() + ->forDatabase( + $refl->extract($name)->get($name) + ); + }, ); } @@ -130,7 +116,7 @@ private function reflection(object $object): ReflectionObject $object, null, null, - $this->extractionStrategy + $this->extractionStrategy, ); } } diff --git a/src/Entity/DataExtractor/DataExtractor.php b/src/Entity/DataExtractor/DataExtractor.php index 56eade4..5972880 100644 --- a/src/Entity/DataExtractor/DataExtractor.php +++ b/src/Entity/DataExtractor/DataExtractor.php @@ -10,6 +10,7 @@ Metadata\Relationship, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class DataExtractor { @@ -20,10 +21,8 @@ final class DataExtractor /** * @param Map|null $extractors */ - public function __construct( - Metadatas $metadata, - Map $extractors = null - ) { + public function __construct(Metadatas $metadata, Map $extractors = null) + { $this->metadata = $metadata; /** * @psalm-suppress InvalidArgument @@ -33,15 +32,7 @@ public function __construct( (Aggregate::class, new AggregateExtractor) (Relationship::class, new RelationshipExtractor); - if ( - (string) $this->extractors->keyType() !== 'string' || - (string) $this->extractors->valueType() !== DataExtractorInterface::class - ) { - throw new \TypeError(sprintf( - 'Argument 2 must be of type Map', - DataExtractorInterface::class - )); - } + assertMap('string', DataExtractorInterface::class, $this->extractors, 2); } /** @@ -51,8 +42,8 @@ public function __construct( */ public function __invoke(object $entity): Map { - $meta = ($this->metadata)(get_class($entity)); - $extract = $this->extractors->get(get_class($meta)); + $meta = ($this->metadata)(\get_class($entity)); + $extract = $this->extractors->get(\get_class($meta)); return $extract($entity, $meta); } diff --git a/src/Entity/DataExtractor/RelationshipExtractor.php b/src/Entity/DataExtractor/RelationshipExtractor.php index 2650ac9..eab9b09 100644 --- a/src/Entity/DataExtractor/RelationshipExtractor.php +++ b/src/Entity/DataExtractor/RelationshipExtractor.php @@ -25,9 +25,6 @@ public function __construct() $this->extractionStrategy = new ReflectionStrategy; } - /** - * {@inheritdoc} - */ public function __invoke(object $entity, Entity $meta): Map { if (!$meta instanceof Relationship) { @@ -38,28 +35,19 @@ public function __invoke(object $entity, Entity $meta): Map $entity, null, null, - $this->extractionStrategy + $this->extractionStrategy, ); /** @var Map */ $data = $refl->extract( $id = $meta->identity()->property(), $start = $meta->startNode()->property(), - $end = $meta->endNode()->property() + $end = $meta->endNode()->property(), ); /** @psalm-suppress MixedMethodCall */ $data = $data - ->put( - $id, - $data->get($id)->value() - ) - ->put( - $start, - $data->get($start)->value() - ) - ->put( - $end, - $data->get($end)->value() - ); + ($id, $data->get($id)->value()) + ($start, $data->get($start)->value()) + ($end, $data->get($end)->value()); /** @var Map */ return $meta @@ -67,15 +55,15 @@ public function __invoke(object $entity, Entity $meta): Map ->reduce( $data, static function(Map $carry, string $name, Property $property) use ($refl): Map { - return $carry->put( + return ($carry)( $name, $property ->type() ->forDatabase( - $refl->extract($name)->get($name) - ) + $refl->extract($name)->get($name), + ), ); - } + }, ); } } diff --git a/src/EntityFactory/AggregateFactory.php b/src/EntityFactory/AggregateFactory.php index 1e297bd..36f1894 100644 --- a/src/EntityFactory/AggregateFactory.php +++ b/src/EntityFactory/AggregateFactory.php @@ -16,6 +16,7 @@ Map, Set, }; +use function Innmind\Immutable\assertMap; use Innmind\Reflection\{ ReflectionClass, Instanciator\ConstructorLessInstanciator, @@ -33,30 +34,19 @@ public function __construct() $this->injectionStrategy = new ReflectionStrategy; } - /** - * {@inheritdoc} - */ - public function __invoke( - Identity $identity, - Entity $meta, - Map $data - ): object { + public function __invoke(Identity $identity, Entity $meta, Map $data): object + { if (!$meta instanceof Aggregate) { throw new InvalidArgumentException; } - if ( - (string) $data->keyType() !== 'string' || - (string) $data->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 3 must be of type Map'); - } + assertMap('string', 'mixed', $data, 3); $reflection = $this ->reflection($meta->class()->toString()) ->withProperty( $meta->identity()->property(), - $identity + $identity, ); $reflection = $meta @@ -77,10 +67,10 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ return $carry->withProperty( $name, $property->type()->fromDatabase( - $data->get($name) - ) + $data->get($name), + ), ); - } + }, ); return $meta @@ -90,9 +80,9 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ function(ReflectionClass $carry, string $property, Child $meta) use ($data): ReflectionClass { return $carry->withProperty( $property, - $this->buildChild($meta, $data) + $this->buildChild($meta, $data), ); - } + }, ) ->build(); } @@ -135,27 +125,25 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ return $carry->withProperty( $name, $property->type()->fromDatabase( - $data->get($name) - ) + $data->get($name), + ), ); - } + }, ) ->withProperty( $relationship->childProperty(), $this->buildValueObject( $meta, $data->get( - $relationship->childProperty() - ) - ) + $relationship->childProperty(), + ), + ), ) ->build(); } - private function buildValueObject( - Child $meta, - Map $data - ): object { + private function buildValueObject(Child $meta, Map $data): object + { return $meta ->properties() ->filter(static function(string $name, Property $property) use ($data): bool { @@ -174,10 +162,10 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ return $carry->withProperty( $name, $property->type()->fromDatabase( - $data->get($name) - ) + $data->get($name), + ), ); - } + }, ) ->build(); } @@ -191,7 +179,7 @@ private function reflection(string $class): ReflectionClass $class, null, $this->injectionStrategy, - $this->instanciator + $this->instanciator, ); } } diff --git a/src/EntityFactory/EntityFactory.php b/src/EntityFactory/EntityFactory.php index ec2e923..43132a5 100644 --- a/src/EntityFactory/EntityFactory.php +++ b/src/EntityFactory/EntityFactory.php @@ -15,6 +15,7 @@ Map, Set, }; +use function Innmind\Immutable\assertMap; final class EntityFactory { @@ -42,19 +43,9 @@ public function __construct( * * @return Set */ - public function __invoke( - Result $result, - Map $variables - ): Set { - if ( - (string) $variables->keyType() !== 'string' || - (string) $variables->valueType() !== Entity::class - ) { - throw new \TypeError(sprintf( - 'Argument 2 must be of type Map', - Entity::class - )); - } + public function __invoke(Result $result, Map $variables): Set + { + assertMap('string', Entity::class, $variables, 2); $structuredData = ($this->translate)($result, $variables); $entities = Set::objects(); @@ -65,19 +56,19 @@ public function __invoke( return $structuredData->contains($variable); }) ->reduce( - Set::objects(), - function(Set $carry, string $variable, Entity $meta) use ($structuredData): Set { + $entities, + function(Set $entities, string $variable, Entity $meta) use ($structuredData): Set { return $structuredData ->get($variable) ->reduce( - $carry, - function(Set $carry, Map $data) use ($meta): Set { - return $carry->add( - $this->makeEntity($meta, $data) + $entities, + function(Set $entities, Map $data) use ($meta): Set { + return ($entities)( + $this->makeEntity($meta, $data), ); - } + }, ); - } + }, ); } @@ -90,7 +81,7 @@ private function makeEntity(Entity $meta, Map $data): object ->generators ->get($meta->identity()->type()) ->for( - $data->get($meta->identity()->property()) + $data->get($meta->identity()->property()), ); if ($this->entities->contains($identity)) { @@ -102,7 +93,7 @@ private function makeEntity(Entity $meta, Map $data): object $this->entities = $this->entities->push( $identity, $entity, - State::managed() + State::managed(), ); return $entity; diff --git a/src/EntityFactory/RelationshipFactory.php b/src/EntityFactory/RelationshipFactory.php index c612815..dc745bf 100644 --- a/src/EntityFactory/RelationshipFactory.php +++ b/src/EntityFactory/RelationshipFactory.php @@ -13,6 +13,7 @@ Exception\InvalidArgumentException, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; use Innmind\Reflection\{ ReflectionClass, Instanciator\ConstructorLessInstanciator, @@ -32,24 +33,13 @@ public function __construct(Generators $generators) $this->injectionStrategy = new ReflectionStrategy; } - /** - * {@inheritdoc} - */ - public function __invoke( - Identity $identity, - Entity $meta, - Map $data - ): object { + public function __invoke(Identity $identity, Entity $meta, Map $data): object + { if (!$meta instanceof Relationship) { throw new InvalidArgumentException; } - if ( - (string) $data->keyType() !== 'string' || - (string) $data->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 3 must be of type Map'); - } + assertMap('string', 'mixed', $data, 3); $reflection = ReflectionClass::of( $meta->class()->toString(), @@ -59,7 +49,7 @@ public function __invoke( ) ->withProperty( $meta->identity()->property(), - $identity + $identity, ) ->withProperty( $meta->startNode()->property(), @@ -67,8 +57,8 @@ public function __invoke( ->generators ->get($meta->startNode()->type()) ->for( - $data->get($meta->startNode()->property()) - ) + $data->get($meta->startNode()->property()), + ), ) ->withProperty( $meta->endNode()->property(), @@ -76,8 +66,8 @@ public function __invoke( ->generators ->get($meta->endNode()->type()) ->for( - $data->get($meta->endNode()->property()) - ) + $data->get($meta->endNode()->property()), + ), ); return $meta @@ -98,10 +88,10 @@ static function(ReflectionClass $carry, string $name, Property $property) use ($ return $carry->withProperty( $name, $property->type()->fromDatabase( - $data->get($name) - ) + $data->get($name), + ), ); - } + }, ) ->build(); } diff --git a/src/EntityFactory/Resolver.php b/src/EntityFactory/Resolver.php index dfe503d..bd6bfd8 100644 --- a/src/EntityFactory/Resolver.php +++ b/src/EntityFactory/Resolver.php @@ -44,13 +44,11 @@ public function __invoke(Entity $meta): EntityFactoryInterface /** * Register the given entity factory instance */ - private function register(EntityFactoryInterface $factory): self + private function register(EntityFactoryInterface $factory): void { - $this->mapping = $this->mapping->put( - get_class($factory), - $factory + $this->mapping = ($this->mapping)( + \get_class($factory), + $factory, ); - - return $this; } } diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 8988962..1d4e0e5 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -33,57 +33,42 @@ public function __construct(string $type = Uuid::class) $this->identities = Map::of('string', $type); } - /** - * {@inheritdoc} - */ public function new(): Identity { /** @var class-string */ - $class = (string) $this->identities->valueType(); - $uuid = new $class((string) Factory::uuid4()); - $this->identities = $this->identities->put( + $class = $this->identities->valueType(); + $uuid = new $class(Factory::uuid4()->toString()); + $this->identities = ($this->identities)( $uuid->toString(), - $uuid + $uuid, ); return $uuid; } - /** - * {@inheritdoc} - */ public function knows($value): bool { /** @psalm-suppress MixedArgument */ return $this->identities->contains($value); } - /** - * {@inheritdoc} - */ public function get($value): Identity { /** @psalm-suppress MixedArgument */ return $this->identities->get($value); } - /** - * {@inheritdoc} - */ public function add(Identity $identity): Generator { /** @psalm-suppress ArgumentTypeCoercion */ - $this->identities = $this->identities->put( + $this->identities = ($this->identities)( $identity->toString(), - $identity + $identity, ); return $this; } - /** - * {@inheritdoc} - */ public function for($value): Identity { if ($this->knows($value)) { @@ -91,7 +76,7 @@ public function for($value): Identity } /** @var class-string */ - $class = (string) $this->identities->valueType(); + $class = $this->identities->valueType(); $uuid = new $class($value); $this->add($uuid); diff --git a/src/Identity/Uuid.php b/src/Identity/Uuid.php index 287e8de..3616cc6 100644 --- a/src/Identity/Uuid.php +++ b/src/Identity/Uuid.php @@ -24,17 +24,11 @@ public function __construct(string $uuid) $this->value = $uuid; } - /** - * {@inheritdoc} - */ public function value() { return $this->value; } - /** - * {@inheritdoc} - */ public function toString(): string { return $this->value; diff --git a/src/IdentityMatch.php b/src/IdentityMatch.php index a5ba321..5c1280f 100644 --- a/src/IdentityMatch.php +++ b/src/IdentityMatch.php @@ -6,6 +6,7 @@ use Innmind\Neo4j\ONM\Metadata\Entity; use Innmind\Neo4j\DBAL\Query; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class IdentityMatch { @@ -18,15 +19,7 @@ final class IdentityMatch */ public function __construct(Query $query, Map $variables) { - if ( - (string) $variables->keyType() !== 'string' || - (string) $variables->valueType() !== Entity::class - ) { - throw new \TypeError(sprintf( - 'Argument 2 must be of type Map', - Entity::class - )); - } + assertMap('string', Entity::class, $variables, 2); $this->query = $query; $this->variables = $variables; diff --git a/src/Manager/Manager.php b/src/Manager/Manager.php index bd1e5f4..aa9d9a6 100644 --- a/src/Manager/Manager.php +++ b/src/Manager/Manager.php @@ -41,13 +41,10 @@ public function connection(): Connection public function repository(string $class): Repository { return ($this->make)( - ($this->metadata)($class) + ($this->metadata)($class), ); } - /** - * {@inheritdoc} - */ public function flush(): ManagerInterface { $this->unitOfWork->commit(); diff --git a/src/Metadata/Aggregate.php b/src/Metadata/Aggregate.php index 7d39e7f..8af1bd7 100644 --- a/src/Metadata/Aggregate.php +++ b/src/Metadata/Aggregate.php @@ -13,6 +13,7 @@ Map, Set, }; +use function Innmind\Immutable\assertSet; final class Aggregate implements Entity { @@ -39,45 +40,30 @@ public function __construct( Set $properties, Set $children ) { - if ((string) $labels->type() !== 'string') { - throw new \TypeError('Argument 3 must be of type Set'); - } - - if ((string) $properties->type() !== Property::class) { - throw new \TypeError(\sprintf( - 'Argument 4 must be of type Set<%s>', - Type::class - )); - } - - if ((string) $children->type() !== Child::class) { - throw new \TypeError(\sprintf( - 'Argument 5 must be of type Set<%s>', - Child::class - )); - } + assertSet('string', $labels, 3); + assertSet(Property::class, $properties, 4); + assertSet(Child::class, $children, 5); $this->class = $class; $this->identity = $identity; $this->repository = new Repository(ConcreteRepository::class); $this->factory = new Factory(AggregateFactory::class); /** @var Map */ - $this->properties = $properties->reduce( - Map::of('string', Property::class), - static function(Map $properties, Property $property): Map { - return $properties->put($property->name(), $property); - } + $this->properties = $properties->toMapOf( + 'string', + Property::class, + static function(Property $property): \Generator { + yield $property->name() => $property; + }, ); $this->labels = $labels; /** @var Map */ - $this->children = $children->reduce( - Map::of('string', Child::class), - static function(Map $children, Child $child): Map { - return $children->put( - $child->relationship()->property(), - $child - ); - } + $this->children = $children->toMapOf( + 'string', + Child::class, + static function(Child $child): \Generator { + yield $child->relationship()->property() => $child; + }, ); } @@ -106,45 +92,30 @@ public static function of( $identity, $labels, $properties, - $children ?? Set::of(Child::class) + $children ?? Set::of(Child::class), ); } - /** - * {@inheritdoc} - */ public function identity(): Identity { return $this->identity; } - /** - * {@inheritdoc} - */ public function repository(): Repository { return $this->repository; } - /** - * {@inheritdoc} - */ public function factory(): Factory { return $this->factory; } - /** - * {@inheritdoc} - */ public function properties(): Map { return $this->properties; } - /** - * {@inheritdoc} - */ public function class(): ClassName { return $this->class; diff --git a/src/Metadata/Aggregate/Child.php b/src/Metadata/Aggregate/Child.php index 73fff94..a5c44ff 100644 --- a/src/Metadata/Aggregate/Child.php +++ b/src/Metadata/Aggregate/Child.php @@ -12,6 +12,7 @@ Map, Set, }; +use function Innmind\Immutable\assertSet; final class Child { @@ -32,26 +33,19 @@ public function __construct( Child\Relationship $relationship, Set $properties ) { - if ((string) $labels->type() !== 'string') { - throw new \TypeError('Argument 2 must be of type Set'); - } - - if ((string) $properties->type() !== Property::class) { - throw new \TypeError(\sprintf( - 'Argument 4 must be of type Set<%s>', - Property::class - )); - } + assertSet('string', $labels, 2); + assertSet(Property::class, $properties, 4); $this->class = $class; $this->labels = $labels; $this->relationship = $relationship; /** @var Map */ - $this->properties = $properties->reduce( - Map::of('string', Property::class), - static function(Map $properties, Property $property): Map { - return $properties->put($property->name(), $property); - } + $this->properties = $properties->toMapOf( + 'string', + Property::class, + static function(Property $property): \Generator { + yield $property->name() => $property; + }, ); } diff --git a/src/Metadata/Aggregate/Child/Relationship.php b/src/Metadata/Aggregate/Child/Relationship.php index 732d05e..55961f9 100644 --- a/src/Metadata/Aggregate/Child/Relationship.php +++ b/src/Metadata/Aggregate/Child/Relationship.php @@ -15,6 +15,7 @@ Set, Str, }; +use function Innmind\Immutable\assertSet; final class Relationship { @@ -39,23 +40,19 @@ public function __construct( throw new DomainException; } - if ((string) $properties->type() !== Property::class) { - throw new \TypeError(\sprintf( - 'Argument 5 must be of type Set<%s>', - Property::class - )); - } + assertSet(Property::class, $properties, 5); $this->class = $class; $this->type = $type; $this->property = $property; $this->childProperty = $childProperty; /** @var Map */ - $this->properties = $properties->reduce( - Map::of('string', Property::class), - static function(Map $properties, Property $property): Map { - return $properties->put($property->name(), $property); - } + $this->properties = $properties->toMapOf( + 'string', + Property::class, + static function(Property $property): \Generator { + yield $property->name() => $property; + }, ); } diff --git a/src/Metadata/Relationship.php b/src/Metadata/Relationship.php index 26d006c..85ed1ff 100644 --- a/src/Metadata/Relationship.php +++ b/src/Metadata/Relationship.php @@ -12,6 +12,7 @@ Map, Set, }; +use function Innmind\Immutable\assertSet; final class Relationship implements Entity { @@ -36,12 +37,7 @@ public function __construct( RelationshipEdge $endNode, Set $properties ) { - if ((string) $properties->type() !== Property::class) { - throw new \TypeError(\sprintf( - 'Argument 6 must be of type Set<%s>', - Property::class - )); - } + assertSet(Property::class, $properties, 6); $this->class = $class; $this->identity = $identity; @@ -51,11 +47,12 @@ public function __construct( $this->startNode = $startNode; $this->endNode = $endNode; /** @var Map */ - $this->properties = $properties->reduce( - Map::of('string', Property::class), - static function(Map $properties, Property $property): Map { - return $properties->put($property->name(), $property); - } + $this->properties = $properties->toMapOf( + 'string', + Property::class, + static function(Property $property): \Generator { + yield $property->name() => $property; + }, ); } @@ -88,41 +85,26 @@ public static function of( ); } - /** - * {@inheritdoc} - */ public function identity(): Identity { return $this->identity; } - /** - * {@inheritdoc} - */ public function repository(): Repository { return $this->repository; } - /** - * {@inheritdoc} - */ public function factory(): Factory { return $this->factory; } - /** - * {@inheritdoc} - */ public function properties(): Map { return $this->properties; } - /** - * {@inheritdoc} - */ public function class(): ClassName { return $this->class; diff --git a/src/Metadatas.php b/src/Metadatas.php index 28545b3..1932364 100644 --- a/src/Metadatas.php +++ b/src/Metadatas.php @@ -32,10 +32,8 @@ public function __invoke(string $class): Entity /** * Register a new entity metadata */ - private function register(Entity $meta): self + private function register(Entity $meta): void { - $this->mapping = $this->mapping->put($meta->class()->toString(), $meta); - - return $this; + $this->mapping = ($this->mapping)($meta->class()->toString(), $meta); } } diff --git a/src/Persister/DelegationPersister.php b/src/Persister/DelegationPersister.php index 43d42f1..42153d3 100644 --- a/src/Persister/DelegationPersister.php +++ b/src/Persister/DelegationPersister.php @@ -19,9 +19,6 @@ public function __construct(Persister ...$persisters) $this->persisters = $persisters; } - /** - * {@inheritdoc} - */ public function __invoke(Connection $connection, Container $container): void { foreach ($this->persisters as $persist) { diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index a8b54ac..282f243 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -55,14 +55,11 @@ public function __construct( $this->variables = Sequence::strings(); } - /** - * {@inheritdoc} - */ public function __invoke(Connection $connection, Container $container): void { $entities = $container->state(State::new()); - if ($entities->size() === 0) { + if ($entities->empty()) { return; } @@ -76,7 +73,7 @@ public function __invoke(Connection $connection, Container $container): void $container->push($identity, $entity, State::managed()); $this->changeset->use( $identity, - ($this->extract)($entity) + ($this->extract)($entity), ); ($this->dispatch)(new EntityPersisted($identity, $entity)); }); @@ -103,7 +100,7 @@ private function queryFor(Map $entities): Query $query, function(Query $carry, Identity $identity, object $entity): Query { return $this->createAggregate($identity, $entity, $carry); - } + }, ); $query = $partitions ->get(false) @@ -111,7 +108,7 @@ function(Query $carry, Identity $identity, object $entity): Query { $query, function(Query $carry, Identity $identity, object $entity): Query { return $this->createRelationship($identity, $entity, $carry); - } + }, ); $this->variables = $this->variables->clear(); @@ -138,7 +135,7 @@ private function createAggregate( $paramKey = $varName->append('_props'); $properties = $this->buildProperties( $meta->properties(), - $paramKey + $paramKey, ); $keysToKeep = $data->keys()->intersect($properties->keys()); @@ -150,7 +147,7 @@ private function createAggregate( ->prepend('{') ->append('}.') ->append($meta->identity()->property()) - ->toString() + ->toString(), ) ->withProperties($properties->reduce( [], @@ -158,7 +155,7 @@ static function(array $carry, string $property, string $cypher): array { $carry[$property] = $cypher; return $carry; - } + }, )) ->withParameter( $paramKey->toString(), @@ -177,8 +174,8 @@ static function(array $carry, string $key, $value): array { $carry[$key] = $value; return $carry; - } - ) + }, + ), ); $query = $meta @@ -191,9 +188,9 @@ function(Query $carry, string $property, Child $child) use ($varName, $data): Qu $child, $varName, $data->get($property), - $carry + $carry, ); - } + }, ); $this->variables = $this->variables->add($varName->toString()); @@ -220,11 +217,11 @@ private function createAggregateChild( ->append($meta->relationship()->childProperty()); $endNodeProperties = $this->buildProperties( $meta->properties(), - $endNodeParamKey = $endNodeName->append('_props') + $endNodeParamKey = $endNodeName->append('_props'), ); $relationshipProperties = $this->buildProperties( $meta->relationship()->properties(), - $relationshipParamKey = $relationshipName->append('_props') + $relationshipParamKey = $relationshipName->append('_props'), ); /** @@ -244,7 +241,7 @@ static function(array $carry, string $property, string $cypher): array { $carry[$property] = $cypher; return $carry; - } + }, )) ->withParameter( $endNodeParamKey->toString(), @@ -257,13 +254,13 @@ static function(array $carry, string $key, $value): array { $carry[$key] = $value; return $carry; - } - ) + }, + ), ) ->through( $meta->relationship()->type()->toString(), $relationshipName->toString(), - 'left' + 'left', ) ->withProperties($relationshipProperties->reduce( [], @@ -271,7 +268,7 @@ static function(array $carry, string $property, string $cypher): array { $carry[$property] = $cypher; return $carry; - } + }, )) ->withParameter( $relationshipParamKey->toString(), @@ -284,8 +281,8 @@ static function(array $carry, string $key, $value): array { $carry[$key] = $value; return $carry; - } - ) + }, + ), ); } @@ -296,21 +293,17 @@ static function(array $carry, string $key, $value): array { * * @return Map */ - private function buildProperties( - Map $properties, - Str $name - ): Map { + private function buildProperties(Map $properties, Str $name): Map + { $name = $name->prepend('{')->append('}.'); /** @var Map */ - return $properties->reduce( - Map::of('string', 'string'), - static function(Map $carry, string $property) use ($name): Map { - return $carry->put( - $property, - $name->append($property)->toString(), - ); - } + return $properties->toMapOf( + 'string', + 'string', + static function(string $property) use ($name): \Generator { + yield $property => $name->append($property)->toString(); + }, ); } @@ -347,15 +340,15 @@ private function createRelationship( $startName, $meta->startNode(), $start, - $query - ) + $query, + ), ) ->create($startName->toString()) ->linkedTo($endName->toString()) ->through( $meta->type()->toString(), $varName->toString(), - 'right' + 'right', ) ->withProperty( $meta->identity()->property(), @@ -371,7 +364,7 @@ static function(array $carry, string $property, string $cypher): array { $carry[$property] = $cypher; return $carry; - } + }, )) ->withParameter( $paramKey->toString(), @@ -387,8 +380,8 @@ static function(array $carry, string $key, $value): array { $carry[$key] = $value; return $carry; - } - ) + }, + ), ); } @@ -408,11 +401,11 @@ private function matchEdge( return $query; } - if ($this->variables->size() > 0) { + if (!$this->variables->empty()) { $query = $query->with(...unwrap($this->variables)); } - $this->variables = $this->variables->add($name->toString()); + $this->variables = ($this->variables)($name->toString()); return $query ->match($name->toString()) @@ -428,7 +421,7 @@ private function matchEdge( $name->append('_props')->toString(), [ $meta->target() => $value, - ] + ], ); } } diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 9becfae..6b44944 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -49,9 +49,6 @@ public function __construct( $this->variables = Sequence::strings(); } - /** - * {@inheritdoc} - */ public function __invoke(Connection $connection, Container $container): void { $entities = $container->state(State::toBeRemoved()); @@ -59,7 +56,7 @@ public function __invoke(Connection $connection, Container $container): void ($this->dispatch)(new EntityAboutToBeRemoved($identity, $object)); }); - if ($entities->size() === 0) { + if ($entities->empty()) { return; } @@ -93,7 +90,7 @@ private function queryFor(Map $entities): Query $query, function(Query $carry, Identity $identity, object $entity): Query { return $this->matchRelationship($identity, $entity, $carry); - } + }, ); $query = $partitions ->get(false) @@ -101,7 +98,7 @@ function(Query $carry, Identity $identity, object $entity): Query { $query, function(Query $carry, Identity $identity, object $entity): Query { return $this->matchAggregate($identity, $entity, $carry); - } + }, ); $query = $this ->variables @@ -109,7 +106,7 @@ function(Query $carry, Identity $identity, object $entity): Query { $query, static function(Query $carry, string $variable): Query { return $carry->delete($variable); - } + }, ); $this->variables = $this->variables->clear(); @@ -127,7 +124,7 @@ private function matchRelationship( /** @var Relationship */ $meta = ($this->metadata)(\get_class($entity)); $name = $this->name->sprintf(\md5($identity->toString())); - $this->variables = $this->variables->add($name->toString()); + $this->variables = ($this->variables)($name->toString()); return $query ->match() @@ -145,7 +142,7 @@ private function matchRelationship( ) ->withParameter( $name->append('_identity')->toString(), - $identity->value() + $identity->value(), ); } @@ -160,7 +157,7 @@ private function matchAggregate( /** @var Aggregate */ $meta = ($this->metadata)(\get_class($entity)); $name = $this->name->sprintf(\md5($identity->toString())); - $this->variables = $this->variables->add($name->toString()); + $this->variables = ($this->variables)($name->toString()); $query = $query ->match( @@ -172,11 +169,11 @@ private function matchAggregate( $name ->prepend('{') ->append('_identity}') - ->toString() + ->toString(), ) ->withParameter( $name->append('_identity')->toString(), - $identity->value() + $identity->value(), ); return $meta @@ -202,12 +199,10 @@ function(Query $carry, string $property, Child $child) use ($name): Query { ->append($child->relationship()->property()) ->toString(), ); - $this->variables = $this->variables - ->add($childName) - ->add($relName); + $this->variables = ($this->variables)($childName)($relName); return $carry; - } + }, ); } } diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index 5a2af72..bc4534f 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -54,9 +54,6 @@ public function __construct( $this->variables = Map::of(Str::class, Map::class); } - /** - * {@inheritdoc} - */ public function __invoke(Connection $connection, Container $container): void { $entities = $container->state(State::managed()); @@ -67,15 +64,15 @@ function(Map $carry, Identity $identity, object $entity): Map { $data = ($this->extract)($entity); $changeset = $this->changeset->compute($identity, $data); - if ($changeset->size() === 0) { + if ($changeset->empty()) { return $carry; } - return $carry->put($identity, $changeset); + return ($carry)($identity, $changeset); } ); - if ($changesets->size() === 0) { + if ($changesets->empty()) { return; } @@ -84,8 +81,8 @@ function(Map $carry, Identity $identity, object $entity): Map { new EntityAboutToBeUpdated( $identity, $entities->get($identity), - $changeset - ) + $changeset, + ), ); }); @@ -95,14 +92,14 @@ function(Map $carry, Identity $identity, object $entity): Map { $entity = $entities->get($identity); $this->changeset->use( $identity, - ($this->extract)($entity) + ($this->extract)($entity), ); ($this->dispatch)( new EntityUpdated( $identity, $entity, - $changeset - ) + $changeset, + ), ); }); } @@ -113,10 +110,8 @@ function(Map $carry, Identity $identity, object $entity): Map { * @param Map> $changesets * @param Map $entities */ - private function queryFor( - Map $changesets, - Map $entities - ): Query { + private function queryFor(Map $changesets, Map $entities): Query + { $this->variables = $this->variables->clear(); $query = $changesets->reduce( @@ -131,7 +126,7 @@ function(Query $carry, Identity $identity, Map $changeset) use ($entities): Quer $entity, $meta, $changeset, - $carry + $carry, ); } else if ($meta instanceof Relationship) { return $this->matchRelationship( @@ -139,13 +134,13 @@ function(Query $carry, Identity $identity, Map $changeset) use ($entities): Quer $entity, $meta, $changeset, - $carry + $carry, ); } $class = \get_class($meta); throw new LogicException("Unknown metadata '$class'"); - } + }, ); $query = $this ->variables @@ -153,7 +148,7 @@ function(Query $carry, Identity $identity, Map $changeset) use ($entities): Quer $query, function(Query $carry, Str $variable, Map $changeset): Query { return $this->update($variable, $changeset, $carry); - } + }, ); $this->variables = $this->variables->clear(); @@ -187,14 +182,14 @@ private function matchAggregate( ) ->withParameter( $name->append('_identity')->toString(), - $identity->value() + $identity->value(), ); - $this->variables = $this->variables->put( + $this->variables = ($this->variables)( $name, $this->buildProperties( $changeset, - $meta->properties() - ) + $meta->properties(), + ), ); return $meta @@ -211,26 +206,26 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): $relName = $name ->append('_') ->append($property); - $this->variables = $this->variables->put( + $this->variables = ($this->variables)( $relName, $this->buildProperties( $changeset, - $child->relationship()->properties() - ) + $child->relationship()->properties(), + ), ); if ($changeset->contains($child->relationship()->childProperty())) { $childName = $relName ->append('_') ->append( - $child->relationship()->childProperty() + $child->relationship()->childProperty(), ); /** @psalm-suppress MixedArgument */ - $this->variables = $this->variables->put( + $this->variables = ($this->variables)( $childName, $changeset->get( - $child->relationship()->childProperty() - ) + $child->relationship()->childProperty(), + ), ); } @@ -244,7 +239,7 @@ function(Query $carry, string $property, Child $child) use ($changeset, $name): $child->relationship()->type()->toString(), $relName->toString(), ); - } + }, ); } @@ -261,12 +256,12 @@ private function matchRelationship( Query $query ): Query { $name = $this->name->sprintf(\md5($identity->toString())); - $this->variables = $this->variables->put( + $this->variables = ($this->variables)( $name, $this->buildProperties( $changeset, - $meta->properties() - ) + $meta->properties(), + ), ); return $query @@ -285,7 +280,7 @@ private function matchRelationship( ) ->withParameter( $name->append('_identity')->toString(), - $identity->value() + $identity->value(), ); } @@ -297,10 +292,8 @@ private function matchRelationship( * * @return Map */ - private function buildProperties( - Map $changeset, - Map $properties - ): Map { + private function buildProperties(Map $changeset, Map $properties): Map + { return $changeset->filter(static function(string $property) use ($properties) { return $properties->contains($property); }); @@ -315,13 +308,10 @@ private function buildProperties( * * @return Query */ - private function update( - Str $variable, - Map $changeset, - Query $query - ): Query { + private function update(Str $variable, Map $changeset, Query $query): Query + { return $query - ->set(sprintf( + ->set(\sprintf( '%s += {%s_props}', $variable->toString(), $variable->toString(), @@ -335,8 +325,8 @@ static function(array $carry, string $key, $value): array { $carry[$key] = $value; return $carry; - } - ) + }, + ), ); } } diff --git a/src/Query/PropertiesMatch.php b/src/Query/PropertiesMatch.php index 73a5b1c..c1d767e 100644 --- a/src/Query/PropertiesMatch.php +++ b/src/Query/PropertiesMatch.php @@ -4,6 +4,7 @@ namespace Innmind\Neo4j\ONM\Query; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class PropertiesMatch { @@ -18,19 +19,8 @@ final class PropertiesMatch */ public function __construct(Map $properties, Map $parameters) { - if ( - (string) $properties->keyType() !== 'string' || - (string) $properties->valueType() !== 'string' - ) { - throw new \TypeError('Argument 1 must be of type Map'); - } - - if ( - (string) $parameters->keyType() !== 'string' || - (string) $parameters->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 2 must be of type Map'); - } + assertMap('string', 'string', $properties, 1); + assertMap('string', 'mixed', $parameters, 2); $this->properties = $properties; $this->parameters = $parameters; @@ -56,7 +46,7 @@ public function merge(self $match): self { return new self( $this->properties()->merge($match->properties()), - $this->parameters()->merge($match->parameters()) + $this->parameters()->merge($match->parameters()), ); } } diff --git a/src/Query/Where.php b/src/Query/Where.php index c978532..de05498 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -8,6 +8,7 @@ Map, Str, }; +use function Innmind\Immutable\assertMap; final class Where { @@ -24,12 +25,7 @@ public function __construct(string $cypher, Map $parameters) throw new DomainException; } - if ( - (string) $parameters->keyType() !== 'string' || - (string) $parameters->valueType() !== 'mixed' - ) { - throw new \TypeError('Argument 2 must be of type Map'); - } + assertMap('string', 'mixed', $parameters, 2); $this->cypher = $cypher; $this->parameters = $parameters; @@ -52,7 +48,7 @@ public function and(self $where): self { return new self( \sprintf('(%s AND %s)', $this->cypher(), $where->cypher()), - $this->parameters()->merge($where->parameters()) + $this->parameters()->merge($where->parameters()), ); } @@ -60,7 +56,7 @@ public function or(self $where): self { return new self( \sprintf('(%s OR %s)', $this->cypher(), $where->cypher()), - $this->parameters()->merge($where->parameters()) + $this->parameters()->merge($where->parameters()), ); } @@ -68,7 +64,7 @@ public function not(): self { return new self( \sprintf('NOT (%s)', $this->cypher()), - $this->parameters() + $this->parameters(), ); } } diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 7ceda31..010a316 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -37,13 +37,10 @@ public function __construct( $this->allowedStates = Set::of( State::class, State::new(), - State::managed() + State::managed(), ); } - /** - * {@inheritdoc} - */ public function add(object $entity): RepositoryInterface { $this->unitOfWork()->persist($entity); @@ -51,9 +48,6 @@ public function add(object $entity): RepositoryInterface return $this; } - /** - * {@inheritdoc} - */ public function has(Identity $identity): bool { if ($this->unitOfWork()->contains($identity)) { @@ -69,14 +63,11 @@ public function has(Identity $identity): bool return (bool) $this->find($identity); } - /** - * {@inheritdoc} - */ public function get(Identity $identity): object { $entity = $this->unitOfWork()->get( $this->metadata()->class()->toString(), - $identity + $identity, ); $state = $this->unitOfWork()->stateFor($identity); @@ -87,9 +78,6 @@ public function get(Identity $identity): object return $entity; } - /** - * {@inheritdoc} - */ public function find(Identity $identity): ?object { try { @@ -99,9 +87,6 @@ public function find(Identity $identity): ?object } } - /** - * {@inheritdoc} - */ public function remove(object $entity): RepositoryInterface { $this->unitOfWork()->remove($entity); @@ -109,32 +94,26 @@ public function remove(object $entity): RepositoryInterface return $this; } - /** - * {@inheritdoc} - */ public function all(): Set { $match = ($this->all)($this->metadata()); return $this->unitOfWork()->execute( $match->query(), - $match->variables() + $match->variables(), ); } - /** - * {@inheritdoc} - */ public function matching(Specification $specification): Set { $match = ($this->matching)( $this->metadata(), - $specification + $specification, ); return $this->unitOfWork()->execute( $match->query(), - $match->variables() + $match->variables(), ); } diff --git a/src/RepositoryFactory.php b/src/RepositoryFactory.php index 971d5a2..b1401ab 100644 --- a/src/RepositoryFactory.php +++ b/src/RepositoryFactory.php @@ -9,6 +9,7 @@ Metadata\Entity, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class RepositoryFactory { @@ -30,16 +31,7 @@ public function __construct( /** @var Map */ $repositories ??= Map::of(Entity::class, Repository::class); - if ( - (string) $repositories->keyType() !== Entity::class || - (string) $repositories->valueType() !== Repository::class - ) { - throw new \TypeError(sprintf( - 'Argument 4 must be of type Map<%s, %s>', - Entity::class, - Repository::class - )); - } + assertMap(Entity::class, Repository::class, $repositories, 4); $this->unitOfWork = $unitOfWork; $this->matchTranslator = $matchTranslator; @@ -62,7 +54,7 @@ public function __invoke(Entity $meta): Repository $this->unitOfWork, $this->matchTranslator, $this->specificationTranslator, - $meta + $meta, ); $this->register($meta, $repository); @@ -74,15 +66,11 @@ public function __invoke(Entity $meta): Repository * * To be used in case the repository can't be instanciated automatically */ - private function register( - Entity $meta, - Repository $repository - ): self { - $this->repositories = $this->repositories->put( + private function register(Entity $meta, Repository $repository): void + { + $this->repositories = ($this->repositories)( $meta, - $repository + $repository, ); - - return $this; } } diff --git a/src/Translation/EntityTranslator.php b/src/Translation/EntityTranslator.php index 3e388bb..50fec34 100644 --- a/src/Translation/EntityTranslator.php +++ b/src/Translation/EntityTranslator.php @@ -17,9 +17,5 @@ interface EntityTranslator * * @return Set> */ - public function __invoke( - string $variable, - Entity $meta, - Result $result - ): Set; + public function __invoke(string $variable, Entity $meta, Result $result): Set; } diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index f7abe0c..6be90f9 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -29,9 +29,6 @@ public function __construct() $this->variables = Set::strings(); } - /** - * {@inheritdoc} - */ public function __invoke( Entity $meta, Identity $identity @@ -43,11 +40,11 @@ public function __invoke( $query = (new Query) ->match( 'entity', - ...unwrap($meta->labels()) + ...unwrap($meta->labels()), ) ->withProperty( $meta->identity()->property(), - '{entity_identity}' + '{entity_identity}', ) ->withParameter('entity_identity', $identity->value()) ->with('entity'); @@ -72,12 +69,12 @@ function( ->match('entity') ->linkedTo( $childName->toString(), - ...unwrap($child->labels()) + ...unwrap($child->labels()), ) ->through( $child->relationship()->type()->toString(), $relName->toString(), - 'left' + 'left', ); }); @@ -88,7 +85,7 @@ function( return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } } diff --git a/src/Translation/IdentityMatch/DelegationTranslator.php b/src/Translation/IdentityMatch/DelegationTranslator.php index c67411b..f617185 100644 --- a/src/Translation/IdentityMatch/DelegationTranslator.php +++ b/src/Translation/IdentityMatch/DelegationTranslator.php @@ -12,6 +12,7 @@ IdentityMatch, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class DelegationTranslator implements IdentityMatchTranslator { @@ -31,22 +32,14 @@ public function __construct(Map $translators = null) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); - if ( - (string) $this->translators->keyType() !== 'string' || - (string) $this->translators->valueType() !== IdentityMatchTranslator::class - ) { - throw new \TypeError(sprintf( - 'Argument 1 must be of type Map', - IdentityMatchTranslator::class - )); - } + assertMap('string', IdentityMatchTranslator::class, $this->translators, 1); } public function __invoke( Entity $meta, Identity $identity ): IdentityMatch { - $translate = $this->translators->get(get_class($meta)); + $translate = $this->translators->get(\get_class($meta)); return $translate($meta, $identity); } diff --git a/src/Translation/IdentityMatch/RelationshipTranslator.php b/src/Translation/IdentityMatch/RelationshipTranslator.php index 8e4f21e..783f07d 100644 --- a/src/Translation/IdentityMatch/RelationshipTranslator.php +++ b/src/Translation/IdentityMatch/RelationshipTranslator.php @@ -15,9 +15,6 @@ final class RelationshipTranslator implements IdentityMatchTranslator { - /** - * {@inheritdoc} - */ public function __invoke( Entity $meta, Identity $identity @@ -32,11 +29,11 @@ public function __invoke( ->through( $meta->type()->toString(), 'entity', - 'right' + 'right', ) ->withProperty( $meta->identity()->property(), - '{entity_identity}' + '{entity_identity}', ) ->withParameter('entity_identity', $identity->value()) ->return('start', 'end', 'entity'); @@ -46,7 +43,7 @@ public function __invoke( return new IdentityMatch( $query, Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } } diff --git a/src/Translation/IdentityMatchTranslator.php b/src/Translation/IdentityMatchTranslator.php index 08a305c..0352820 100644 --- a/src/Translation/IdentityMatchTranslator.php +++ b/src/Translation/IdentityMatchTranslator.php @@ -14,8 +14,5 @@ interface IdentityMatchTranslator /** * Translate an identity into a query to match the expected element */ - public function __invoke( - Entity $meta, - Identity $identity - ): IdentityMatch; + public function __invoke(Entity $meta, Identity $identity): IdentityMatch; } diff --git a/src/Translation/Match/AggregateTranslator.php b/src/Translation/Match/AggregateTranslator.php index 5bfe53d..90ba58e 100644 --- a/src/Translation/Match/AggregateTranslator.php +++ b/src/Translation/Match/AggregateTranslator.php @@ -28,9 +28,6 @@ public function __construct() $this->variables = Set::strings(); } - /** - * {@inheritdoc} - */ public function __invoke(Entity $meta): IdentityMatch { if (!$meta instanceof Aggregate) { @@ -56,9 +53,9 @@ function( $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $this->variables = $this->variables - ->add($relName->toString()) - ->add($childName->toString()); + $this->variables = ($this->variables) + ($relName->toString()) + ($childName->toString()); return $query ->match('entity') @@ -69,7 +66,7 @@ function( ->through( $child->relationship()->type()->toString(), $relName->toString(), - 'left' + 'left', ); }); @@ -80,7 +77,7 @@ function( return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } } diff --git a/src/Translation/Match/DelegationTranslator.php b/src/Translation/Match/DelegationTranslator.php index c39f6fb..faecd7f 100644 --- a/src/Translation/Match/DelegationTranslator.php +++ b/src/Translation/Match/DelegationTranslator.php @@ -11,6 +11,7 @@ IdentityMatch, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class DelegationTranslator implements MatchTranslator { @@ -30,20 +31,12 @@ public function __construct(Map $translators = null) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); - if ( - (string) $this->translators->keyType() !== 'string' || - (string) $this->translators->valueType() !== MatchTranslator::class - ) { - throw new \TypeError(sprintf( - 'Argument 1 must be of type Map', - MatchTranslator::class - )); - } + assertMap('string', MatchTranslator::class, $this->translators, 1); } public function __invoke(Entity $meta): IdentityMatch { - $translate = $this->translators->get(get_class($meta)); + $translate = $this->translators->get(\get_class($meta)); return $translate($meta); } diff --git a/src/Translation/Match/RelationshipTranslator.php b/src/Translation/Match/RelationshipTranslator.php index e731ede..8f46db3 100644 --- a/src/Translation/Match/RelationshipTranslator.php +++ b/src/Translation/Match/RelationshipTranslator.php @@ -14,9 +14,6 @@ final class RelationshipTranslator implements MatchTranslator { - /** - * {@inheritdoc} - */ public function __invoke(Entity $meta): IdentityMatch { if (!$meta instanceof Relationship) { @@ -29,7 +26,7 @@ public function __invoke(Entity $meta): IdentityMatch ->through( $meta->type()->toString(), 'entity', - 'right' + 'right', ) ->return('start', 'end', 'entity'); @@ -38,7 +35,7 @@ public function __invoke(Entity $meta): IdentityMatch return new IdentityMatch( $query, Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } } diff --git a/src/Translation/Result/AggregateTranslator.php b/src/Translation/Result/AggregateTranslator.php index b6fb38c..6dd3acd 100644 --- a/src/Translation/Result/AggregateTranslator.php +++ b/src/Translation/Result/AggregateTranslator.php @@ -27,9 +27,6 @@ final class AggregateTranslator implements EntityTranslator { - /** - * {@inheritdoc} - */ public function __invoke( string $variable, Entity $meta, @@ -53,12 +50,12 @@ public function __invoke( Set::of(Map::class), function(Set $carry, Row $row) use ($meta, $result): Set { /** @psalm-suppress PossiblyInvalidArrayAccess */ - return $carry->add($this->translateNode( + return ($carry)($this->translateNode( $row->value()[$meta->identity()->property()], $meta, - $result + $result, )); - } + }, ); } @@ -89,8 +86,8 @@ private function translateNode( ( $meta->identity()->property(), $node->properties()->get( - $meta->identity()->property() - ) + $meta->identity()->property(), + ), ); $data = $meta @@ -108,11 +105,11 @@ private function translateNode( ->reduce( $data, static function(Map $carry, string $name) use ($node): Map { - return $carry->put( + return ($carry)( $name, - $node->properties()->get($name) + $node->properties()->get($name), ); - } + }, ); try { @@ -122,11 +119,11 @@ static function(Map $carry, string $name) use ($node): Map { ->reduce( $data, function(Map $carry, string $name, Child $meta) use ($node, $result): Map { - return $carry->put( + return ($carry)( $name, - $this->translateChild($meta, $result, $node) + $this->translateChild($meta, $result, $node), ); - } + }, ); } catch (MoreThanOneRelationshipFound $e) { throw $e->on($meta); @@ -160,7 +157,7 @@ private function translateChild( return $this->translateRelationship( $meta, $result, - $relationships->first() + $relationships->first(), ); } @@ -186,22 +183,20 @@ private function translateRelationship( return true; }) - ->reduce( - Map::of('string', 'mixed'), - static function(Map $carry, string $name) use ($relationship): Map { - return $carry->put( - $name, - $relationship->properties()->get($name) - ); - } + ->toMapOf( + 'string', + 'mixed', + static function(string $name) use ($relationship): \Generator { + yield $name => $relationship->properties()->get($name); + }, ) ->put( $meta->relationship()->childProperty(), $this->translateValueObject( $meta, $result, - $relationship - ) + $relationship, + ), ); } @@ -226,14 +221,12 @@ private function translateValueObject( return true; }) - ->reduce( - Map::of('string', 'mixed'), - static function(Map $carry, string $name) use ($node): Map { - return $carry->put( - $name, - $node->properties()->get($name) - ); - } + ->toMapOf( + 'string', + 'mixed', + static function(string $name) use ($node): \Generator { + yield $name => $node->properties()->get($name); + }, ); } } diff --git a/src/Translation/Result/RelationshipTranslator.php b/src/Translation/Result/RelationshipTranslator.php index c8fbb3b..276b4cd 100644 --- a/src/Translation/Result/RelationshipTranslator.php +++ b/src/Translation/Result/RelationshipTranslator.php @@ -23,9 +23,6 @@ final class RelationshipTranslator implements EntityTranslator { - /** - * {@inheritdoc} - */ public function __invoke( string $variable, Entity $meta, @@ -49,14 +46,14 @@ public function __invoke( Set::of(Map::class), function(Set $carry, Row $row) use ($meta, $result): Set { /** @psalm-suppress PossiblyInvalidArrayAccess */ - return $carry->add( + return ($carry)( $this->translateRelationship( $row->value()[$meta->identity()->property()], $meta, - $result - ) + $result, + ), ); - } + }, ); } @@ -87,8 +84,8 @@ private function translateRelationship( ( $meta->identity()->property(), $relationship->properties()->get( - $meta->identity()->property() - ) + $meta->identity()->property(), + ), ) ( $meta->startNode()->property(), @@ -96,7 +93,7 @@ private function translateRelationship( ->nodes() ->get($relationship->startNode()->value()) ->properties() - ->get($meta->startNode()->target()) + ->get($meta->startNode()->target()), ) ( $meta->endNode()->property(), @@ -104,7 +101,7 @@ private function translateRelationship( ->nodes() ->get($relationship->endNode()->value()) ->properties() - ->get($meta->endNode()->target()) + ->get($meta->endNode()->target()), ); /** @var Map */ @@ -123,11 +120,11 @@ private function translateRelationship( ->reduce( $data, static function(Map $carry, string $name) use ($relationship): Map { - return $carry->put( + return ($carry)( $name, - $relationship->properties()->get($name) + $relationship->properties()->get($name), ); - } + }, ); } } diff --git a/src/Translation/ResultTranslator.php b/src/Translation/ResultTranslator.php index 49024b3..85fe5de 100644 --- a/src/Translation/ResultTranslator.php +++ b/src/Translation/ResultTranslator.php @@ -18,6 +18,7 @@ Map, Set, }; +use function Innmind\Immutable\assertMap; final class ResultTranslator { @@ -37,15 +38,7 @@ public function __construct(Map $translators = null) (Aggregate::class, new AggregateTranslator) (Relationship::class, new RelationshipTranslator); - if ( - (string) $this->translators->keyType() !== 'string' || - (string) $this->translators->valueType() !== EntityTranslator::class - ) { - throw new \TypeError(sprintf( - 'Argument 1 must be of type Map', - EntityTranslator::class - )); - } + assertMap('string', EntityTranslator::class, $this->translators, 1); } /** @@ -55,19 +48,9 @@ public function __construct(Map $translators = null) * * @return Map>> */ - public function __invoke( - Result $result, - Map $variables - ): Map { - if ( - (string) $variables->keyType() !== 'string' || - (string) $variables->valueType() !== Entity::class - ) { - throw new \TypeError(sprintf( - 'Argument 2 must be of type Map', - Entity::class - )); - } + public function __invoke(Result $result, Map $variables): Map + { + assertMap('string', Entity::class, $variables, 2); /** @var Map>> */ return $variables @@ -78,18 +61,18 @@ public function __invoke( return $row->column() === $variable; }); - return $forVariable->size() > 0; + return !$forVariable->empty(); }) ->reduce( Map::of('string', Set::class), function(Map $carry, string $variable, Entity $meta) use ($result): Map { $translate = $this->translators->get(get_class($meta)); - return $carry->put( + return ($carry)( $variable, - $translate($variable, $meta, $result) + $translate($variable, $meta, $result), ); - } + }, ); } } diff --git a/src/Translation/Specification/AggregateTranslator.php b/src/Translation/Specification/AggregateTranslator.php index b6fccb0..3d32595 100644 --- a/src/Translation/Specification/AggregateTranslator.php +++ b/src/Translation/Specification/AggregateTranslator.php @@ -33,9 +33,6 @@ public function __construct() $this->variables = Set::strings(); } - /** - * {@inheritdoc} - */ public function __invoke( Entity $meta, Specification $specification @@ -56,7 +53,7 @@ public function __invoke( ...unwrap($meta->labels()), ), 'entity', - $mapping + $mapping, ) ->with('entity'); @@ -87,15 +84,15 @@ function( ...unwrap($child->labels()), ), $childName->toString(), - $mapping + $mapping, ) ->through( $child->relationship()->type()->toString(), $relName->toString(), - 'left' + 'left', ), $relName->toString(), - $mapping + $mapping, ); }); } catch (SpecificationNotApplicableAsPropertyMatch $e) { @@ -117,9 +114,9 @@ function( $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $this->variables = $this->variables - ->add($relName->toString()) - ->add($childName->toString()); + $this->variables = ($this->variables) + ($relName->toString()) + ($childName->toString()); return $query ->match('entity') @@ -130,7 +127,7 @@ function( ->through( $child->relationship()->type()->toString(), $relName->toString(), - 'left' + 'left', ); }); $condition = (new AggregateCypherVisitor($meta))($specification); @@ -139,7 +136,7 @@ function( $query, static function(Query $query, string $key, $value): Query { return $query->withParameter($key, $value); - } + }, ); } @@ -153,7 +150,7 @@ static function(Query $query, string $key, $value): Query { return new IdentityMatch( $query->return('entity', ...unwrap($variables)), Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } @@ -171,13 +168,13 @@ private function addProperties( $query, static function(Query $query, string $property, string $cypher): Query { return $query->withProperty($property, $cypher); - } + }, ); $query = $match->parameters()->reduce( $query, static function(Query $query, string $key, $value): Query { return $query->withParameter($key, $value); - } + }, ); } diff --git a/src/Translation/Specification/DelegationTranslator.php b/src/Translation/Specification/DelegationTranslator.php index 73d5d6d..bd86dfb 100644 --- a/src/Translation/Specification/DelegationTranslator.php +++ b/src/Translation/Specification/DelegationTranslator.php @@ -12,6 +12,7 @@ Exception\SpecificationNotApplicable, }; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; use Innmind\Specification\Specification; final class DelegationTranslator implements SpecificationTranslator @@ -36,15 +37,7 @@ public function __construct( (Relationship::class, new RelationshipTranslator); $this->validate = $validate ?? new Validator\DelegationValidator; - if ( - (string) $this->translators->keyType() !== 'string' || - (string) $this->translators->valueType() !== SpecificationTranslator::class - ) { - throw new \TypeError(sprintf( - 'Argument 1 must be of type Map', - SpecificationTranslator::class - )); - } + assertMap('string', SpecificationTranslator::class, $this->translators, 1); } public function __invoke( @@ -55,7 +48,7 @@ public function __invoke( throw new SpecificationNotApplicable; } - $translate = $this->translators->get(get_class($meta)); + $translate = $this->translators->get(\get_class($meta)); return $translate($meta, $specification); } diff --git a/src/Translation/Specification/RelationshipTranslator.php b/src/Translation/Specification/RelationshipTranslator.php index 1b4ab86..d162f24 100644 --- a/src/Translation/Specification/RelationshipTranslator.php +++ b/src/Translation/Specification/RelationshipTranslator.php @@ -19,9 +19,6 @@ final class RelationshipTranslator implements SpecificationTranslator { - /** - * {@inheritdoc} - */ public function __invoke( Entity $meta, Specification $specification @@ -40,19 +37,19 @@ public function __invoke( ->addProperties( (new Query)->match('start'), 'start', - $mapping + $mapping, ) ->linkedTo('end'), 'end', - $mapping + $mapping, ) ->through( $meta->type()->toString(), 'entity', - 'right' + 'right', ), 'entity', - $mapping + $mapping, ); } catch (SpecificationNotApplicableAsPropertyMatch $e) { $condition = (new RelationshipCypherVisitor($meta))($specification); @@ -62,14 +59,14 @@ public function __invoke( ->through( $meta->type()->toString(), 'entity', - 'right' + 'right', ) ->where($condition->cypher()); $query = $condition->parameters()->reduce( $query, static function(Query $query, string $key, $value): Query { return $query->withParameter($key, $value); - } + }, ); } @@ -77,7 +74,7 @@ static function(Query $query, string $key, $value): Query { return new IdentityMatch( $query->return('start', 'end', 'entity'), Map::of('string', Entity::class) - ('entity', $meta) + ('entity', $meta), ); } @@ -95,13 +92,13 @@ private function addProperties( $query, static function(Query $query, string $property, string $cypher): Query { return $query->withProperty($property, $cypher); - } + }, ); $query = $match->parameters()->reduce( $query, static function(Query $query, string $key, $value): Query { return $query->withParameter($key, $value); - } + }, ); } diff --git a/src/Translation/Specification/Validator.php b/src/Translation/Specification/Validator.php index 65870bb..95284b6 100644 --- a/src/Translation/Specification/Validator.php +++ b/src/Translation/Specification/Validator.php @@ -11,8 +11,5 @@ interface Validator /** * Check if the given specification is applicable for the given entity definition */ - public function __invoke( - Specification $specification, - Entity $meta - ): bool; + public function __invoke(Specification $specification, Entity $meta): bool; } diff --git a/src/Translation/Specification/Validator/AggregateValidator.php b/src/Translation/Specification/Validator/AggregateValidator.php index 85f2097..8492856 100644 --- a/src/Translation/Specification/Validator/AggregateValidator.php +++ b/src/Translation/Specification/Validator/AggregateValidator.php @@ -19,9 +19,6 @@ final class AggregateValidator implements Validator { - /** - * {@inheritdoc} - */ public function __invoke( Specification $specification, Entity $meta @@ -34,7 +31,7 @@ public function __invoke( case $specification instanceof Comparator: return $this->isValidProperty( $specification->property(), - $meta + $meta, ); case $specification instanceof Composite: @@ -51,10 +48,8 @@ public function __invoke( return false; } - private function isValidProperty( - string $property, - Aggregate $meta - ): bool { + private function isValidProperty(string $property, Aggregate $meta): bool + { if ($meta->properties()->contains($property)) { return true; } diff --git a/src/Translation/Specification/Validator/DelegationValidator.php b/src/Translation/Specification/Validator/DelegationValidator.php index c71b9a6..d18d4b4 100644 --- a/src/Translation/Specification/Validator/DelegationValidator.php +++ b/src/Translation/Specification/Validator/DelegationValidator.php @@ -11,6 +11,7 @@ }; use Innmind\Specification\Specification; use Innmind\Immutable\Map; +use function Innmind\Immutable\assertMap; final class DelegationValidator implements Validator { @@ -30,25 +31,12 @@ public function __construct(Map $validators = null) (Aggregate::class, new AggregateValidator) (Relationship::class, new RelationshipValidator); - if ( - (string) $this->validators->keyType() !== 'string' || - (string) $this->validators->valueType() !== Validator::class - ) { - throw new \TypeError(sprintf( - 'Argument 1 must be of type Map', - Validator::class - )); - } + assertMap('string', Validator::class, $this->validators, 1); } - /** - * {@inheritdoc} - */ - public function __invoke( - Specification $specification, - Entity $meta - ): bool { - $validate = $this->validators->get(get_class($meta)); + public function __invoke(Specification $specification, Entity $meta): bool + { + $validate = $this->validators->get(\get_class($meta)); return $validate($specification, $meta); } diff --git a/src/Translation/Specification/Validator/RelationshipValidator.php b/src/Translation/Specification/Validator/RelationshipValidator.php index 74d7fdf..233a38a 100644 --- a/src/Translation/Specification/Validator/RelationshipValidator.php +++ b/src/Translation/Specification/Validator/RelationshipValidator.php @@ -18,13 +18,8 @@ final class RelationshipValidator implements Validator { - /** - * {@inheritdoc} - */ - public function __invoke( - Specification $specification, - Entity $meta - ): bool { + public function __invoke(Specification $specification, Entity $meta): bool + { if (!$meta instanceof Relationship) { throw new InvalidArgumentException; } diff --git a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php index b172d7b..95a3ec5 100644 --- a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php @@ -34,9 +34,6 @@ public function __construct(Aggregate $meta) $this->convert = new ConvertSign; } - /** - * {@inheritdo} - */ public function __invoke(Specification $specification): Where { switch (true) { @@ -78,9 +75,8 @@ private function buildCondition(Comparator $specification): Where } } - private function buildPropertyCondition( - Comparator $specification - ): Where { + private function buildPropertyCondition(Comparator $specification): Where + { $prop = $specification->property(); $key = Str::of('entity_') ->append($prop) @@ -98,13 +94,12 @@ private function buildPropertyCondition( $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) + ($key->toString(), $specification->value()), ); } - private function buildSubPropertyCondition( - Comparator $specification - ): Where { + private function buildSubPropertyCondition(Comparator $specification): Where + { $prop = Str::of($specification->property()); $pieces = $prop->split('.'); $var = Str::of('entity_')->append( @@ -136,7 +131,7 @@ private function buildSubPropertyCondition( $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) + ($key->toString(), $specification->value()), ); } } diff --git a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php index d707cc2..241f900 100644 --- a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php @@ -35,9 +35,6 @@ public function __construct(Relationship $meta) $this->convert = new ConvertSign; } - /** - * {@inheritdo} - */ public function __invoke(Specification $specification): Where { switch (true) { @@ -75,14 +72,14 @@ private function buildCondition(Comparator $specification): Where return $this->buildEdgeCondition( $specification, $this->meta->startNode(), - 'start' + 'start', ); case $this->meta->endNode()->property() === $property: return $this->buildEdgeCondition( $specification, $this->meta->endNode(), - 'end' + 'end', ); default: @@ -90,9 +87,8 @@ private function buildCondition(Comparator $specification): Where } } - private function buildPropertyCondition( - Comparator $specification - ): Where { + private function buildPropertyCondition(Comparator $specification): Where + { $prop = $specification->property(); $key = Str::of('entity_') ->append($prop) @@ -110,7 +106,7 @@ private function buildPropertyCondition( $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) + ($key->toString(), $specification->value()), ); } @@ -144,7 +140,7 @@ private function buildEdgeCondition( $key->prepend('{')->append('}')->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $value) + ($key->toString(), $value), ); } } diff --git a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php index ca93657..2a8a764 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php @@ -32,9 +32,6 @@ public function __construct(Aggregate $meta) $this->meta = $meta; } - /** - * {@inheritdo} - */ public function __invoke(Specification $specification): Map { switch (true) { @@ -52,7 +49,7 @@ public function __invoke(Specification $specification): Map return $this->merge( ($this)($specification->left()), - ($this)($specification->right()) + ($this)($specification->right()), ); } @@ -97,8 +94,8 @@ private function buildPropertyMapping(Comparator $specification): Map Map::of('string', 'string') ($prop, $key->prepend('{')->append('}')->toString()), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) - ) + ($key->toString(), $specification->value()), + ), ); } @@ -137,8 +134,8 @@ private function buildSubPropertyMapping(Comparator $specification): Map ->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) - ) + ($key->toString(), $specification->value()), + ), ); } @@ -155,14 +152,14 @@ private function merge(Map $left, Map $right): Map $left, static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { if (!$carry->contains($var)) { - return $carry->put($var, $data); + return ($carry)($var, $data); } - return $carry->put( + return ($carry)( $var, - $data->merge($left->get($var)) + $data->merge($left->get($var)), ); - } + }, ); } } diff --git a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php index 5ef3327..19764b8 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php @@ -33,9 +33,6 @@ public function __construct(Relationship $meta) $this->meta = $meta; } - /** - * {@inheritdo} - */ public function __invoke(Specification $specification): Map { switch (true) { @@ -53,7 +50,7 @@ public function __invoke(Specification $specification): Map return $this->merge( ($this)($specification->left()), - ($this)($specification->right()) + ($this)($specification->right()), ); } @@ -75,14 +72,14 @@ private function buildMapping(Comparator $specification): Map return $this->buildEdgeMapping( $specification, $this->meta->startNode(), - 'start' + 'start', ); case $this->meta->endNode()->property() === $property: return $this->buildEdgeMapping( $specification, $this->meta->endNode(), - 'end' + 'end', ); default: @@ -109,8 +106,8 @@ private function buildPropertyMapping(Comparator $specification): Map Map::of('string', 'string') ($prop, $key->prepend('{')->append('}')->toString()), Map::of('string', 'mixed') - ($key->toString(), $specification->value()) - ) + ($key->toString(), $specification->value()), + ), ); } @@ -147,11 +144,11 @@ private function buildEdgeMapping( $key ->prepend('{') ->append('}') - ->toString() + ->toString(), ), Map::of('string', 'mixed') - ($key->toString(), $value) - ) + ($key->toString(), $value), + ), ); } @@ -168,12 +165,12 @@ private function merge(Map $left, Map $right): Map $left, static function(Map $carry, string $var, PropertiesMatch $data) use ($left): Map { if (!$carry->contains($var)) { - return $carry->put($var, $data); + return ($carry)($var, $data); } - return $carry->put( + return ($carry)( $var, - $data->merge($left->get($var)) + $data->merge($left->get($var)), ); } ); diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 5760ac8..eb2a30d 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -30,9 +30,6 @@ public static function nullable(Type $inner): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -50,9 +47,6 @@ public function forDatabase($value) return $array; } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { $array = []; @@ -66,9 +60,6 @@ public function fromDatabase($value) return $array; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/BooleanType.php b/src/Type/BooleanType.php index 1f0a96e..e2c63d9 100644 --- a/src/Type/BooleanType.php +++ b/src/Type/BooleanType.php @@ -17,9 +17,6 @@ public static function nullable(): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -29,17 +26,11 @@ public function forDatabase($value) return (bool) $value; } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { return (bool) $value; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/DateType.php b/src/Type/DateType.php index 76de3f2..f27a613 100644 --- a/src/Type/DateType.php +++ b/src/Type/DateType.php @@ -44,33 +44,27 @@ public static function nullableMutable(string $format = null): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { return null; } - if (is_string($value)) { + if (\is_string($value)) { $value = new \DateTimeImmutable($value); } if (!$value instanceof \DateTimeInterface) { /** @psalm-suppress MixedArgument */ - throw new InvalidArgumentException(sprintf( + throw new InvalidArgumentException(\sprintf( 'The value "%s" must be an instance of DateTimeInterface', - $value + $value, )); } return $value->format($this->format); } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { if ($this->immutable) { @@ -82,9 +76,6 @@ public function fromDatabase($value) return \DateTime::createFromFormat($this->format, $value); } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/FloatType.php b/src/Type/FloatType.php index 9fa42c2..658fe7a 100644 --- a/src/Type/FloatType.php +++ b/src/Type/FloatType.php @@ -17,9 +17,6 @@ public static function nullable(): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -29,17 +26,11 @@ public function forDatabase($value) return (float) $value; } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { return (float) $value; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/IntType.php b/src/Type/IntType.php index 742351d..bbdcdfd 100644 --- a/src/Type/IntType.php +++ b/src/Type/IntType.php @@ -17,9 +17,6 @@ public static function nullable(): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -29,17 +26,11 @@ public function forDatabase($value) return (int) $value; } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { return (int) $value; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/PointInTimeType.php b/src/Type/PointInTimeType.php index aac3ab7..ba288a6 100644 --- a/src/Type/PointInTimeType.php +++ b/src/Type/PointInTimeType.php @@ -32,9 +32,6 @@ public static function nullable(Format $format = null): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -43,27 +40,21 @@ public function forDatabase($value) if (!$value instanceof PointInTimeInterface) { /** @psalm-suppress MixedArgument */ - throw new InvalidArgumentException(sprintf( + throw new InvalidArgumentException(\sprintf( 'The value "%s" must be an instance of PointInTimeInterface', - $value + $value, )); } return $value->format($this->format); } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { /** @psalm-suppress MixedArgument */ return new PointInTime($value); } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/SetType.php b/src/Type/SetType.php index d3f6869..4030284 100644 --- a/src/Type/SetType.php +++ b/src/Type/SetType.php @@ -34,9 +34,6 @@ public static function nullable(Type $inner, string $type): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -45,11 +42,11 @@ public function forDatabase($value) if ( !$value instanceof Set || - (string) $value->type() !== $this->type + !$value->isOfType($this->type) ) { - throw new InvalidArgumentException(sprintf( + throw new InvalidArgumentException(\sprintf( 'The set must be an instance of Set<%s>', - $this->type + $this->type, )); } @@ -60,13 +57,10 @@ function(array $carry, $value): array { $carry[] = $this->inner->forDatabase($value); return $carry; - } + }, ); } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { $set = Set::of($this->type); @@ -74,15 +68,12 @@ public function fromDatabase($value) /** @var mixed $sub */ foreach ($value as $sub) { /** @psalm-suppress MixedArgument */ - $set = $set->add($this->inner->fromDatabase($sub)); + $set = ($set)($this->inner->fromDatabase($sub)); } return $set; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/Type/StringType.php b/src/Type/StringType.php index 160ccb7..eeefe77 100644 --- a/src/Type/StringType.php +++ b/src/Type/StringType.php @@ -17,9 +17,6 @@ public static function nullable(): self return $self; } - /** - * {@inheritdoc} - */ public function forDatabase($value) { if ($this->nullable && $value === null) { @@ -29,17 +26,11 @@ public function forDatabase($value) return (string) $value; } - /** - * {@inheritdoc} - */ public function fromDatabase($value) { return (string) $value; } - /** - * {@inheritdoc} - */ public function isNullable(): bool { return $this->nullable; diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index c1394cc..30c3d52 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -67,11 +67,11 @@ public function persist(object $entity): self $identity = $this->extractIdentity($entity); if (!$this->container->contains($identity)) { - $meta = ($this->metadata)(get_class($entity)); + $meta = ($this->metadata)(\get_class($entity)); $this->container->push( $identity, $entity, - State::new() + State::new(), ); $this ->generators @@ -123,7 +123,7 @@ public function get(string $class, Identity $identity): object $match = ($this->match)($meta, $identity); $entities = $this->execute( $match->query(), - $match->variables() + $match->variables(), ); if ($entities->size() !== 1) { @@ -148,7 +148,7 @@ public function remove(object $entity): self $this->container->push( $identity, $entity, - State::removed() + State::removed(), ); break; @@ -156,7 +156,7 @@ public function remove(object $entity): self $this->container->push( $identity, $entity, - State::toBeRemoved() + State::toBeRemoved(), ); break; } @@ -173,7 +173,7 @@ public function remove(object $entity): self public function detach(object $entity): self { $this->container->detach( - $this->extractIdentity($entity) + $this->extractIdentity($entity), ); return $this; @@ -186,13 +186,11 @@ public function detach(object $entity): self * * @return Set */ - public function execute( - Query $query, - Map $variables - ): Set { + public function execute(Query $query, Map $variables): Set + { return ($this->makeEntity)( $this->connection->execute($query), - $variables + $variables, ); } @@ -211,7 +209,7 @@ public function commit(): self */ private function extractIdentity(object $entity): Identity { - $identity = ($this->metadata)(get_class($entity))->identity()->property(); + $identity = ($this->metadata)(\get_class($entity))->identity()->property(); /** @var Identity */ return ReflectionObject::of($entity) diff --git a/src/bootstrap.php b/src/bootstrap.php index 4310d7d..ceb3557 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -20,15 +20,15 @@ use function Innmind\Immutable\unwrap; /** - * @param Set $metas - * @param Map|null $additionalGenerators - * @param Map|null $repositories - * @param Set|null $entityFactories - * @param Map|null $resultTranslators - * @param Map|null $identityMatchTranslators - * @param Map|null $matchTranslators - * @param Map|null $specificationTranslators - * @param Map|null $dataExtractors + * @param Set $metas + * @param Map|null $additionalGenerators + * @param Map|null $repositories + * @param Set|null $entityFactories + * @param Map|null $resultTranslators + * @param Map|null $identityMatchTranslators + * @param Map|null $matchTranslators + * @param Map|null $specificationTranslators + * @param Map|null $dataExtractors * * @return array{manager: Manager, command_bus: array{clear_domain_events: callable(CommandBusInterface): CommandBusInterface, dispatch_domain_events: callable(CommandBusInterface): CommandBusInterface, flush: callable(CommandBusInterface): CommandBusInterface, transaction: callable(CommandBusInterface): CommandBusInterface}} */ @@ -89,7 +89,7 @@ function bootstrap( $entityFactories = $entityFactories ?? Set::of( EntityFactory::class, new EntityFactory\AggregateFactory, - new EntityFactory\RelationshipFactory($identityGenerators) + new EntityFactory\RelationshipFactory($identityGenerators), ); $metadatas = new Metadatas(...unwrap($metas)); @@ -97,7 +97,7 @@ function bootstrap( $entityChangeset = new Entity\ChangesetComputer; $dataExtractor = new Entity\DataExtractor\DataExtractor( $metadatas, - $dataExtractors + $dataExtractors, ); $persister = $persister ?? new Persister\DelegationPersister( @@ -105,19 +105,19 @@ function bootstrap( $entityChangeset, $eventBus, $dataExtractor, - $metadatas + $metadatas, ), new Persister\UpdatePersister( $entityChangeset, $eventBus, $dataExtractor, - $metadatas + $metadatas, ), new Persister\RemovePersister( $entityChangeset, $eventBus, - $metadatas - ) + $metadatas, + ), ); $entityContainer = new Entity\Container; @@ -129,12 +129,12 @@ function bootstrap( new Translation\ResultTranslator($resultTranslators), $identityGenerators, new EntityFactory\Resolver(...unwrap($entityFactories)), - $entityContainer + $entityContainer, ), new Translation\IdentityMatch\DelegationTranslator($identityMatchTranslators), $metadatas, $persister, - $identityGenerators + $identityGenerators, ); $manager = new Manager\Manager( @@ -144,9 +144,9 @@ function bootstrap( $unitOfWork, new Translation\Match\DelegationTranslator($matchTranslators), new Translation\Specification\DelegationTranslator($specificationTranslators), - $repositories + $repositories, ), - $identityGenerators + $identityGenerators, ); return [ From 4d46fa40a60348889a856b67a913eb2d60ed4d97 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 18:20:57 +0100 Subject: [PATCH 11/17] rename has() to contains() --- src/Repository.php | 2 +- src/Repository/Repository.php | 2 +- tests/Repository/RepositoryTest.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Repository.php b/src/Repository.php index c2d58c2..07b6079 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -17,7 +17,7 @@ public function add(object $entity): self; /** * Check if the repository has an entity with the given id */ - public function has(Identity $identity): bool; + public function contains(Identity $identity): bool; /** * Return the entity with the given id diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 010a316..91dc62e 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -48,7 +48,7 @@ public function add(object $entity): RepositoryInterface return $this; } - public function has(Identity $identity): bool + public function contains(Identity $identity): bool { if ($this->unitOfWork()->contains($identity)) { $state = $this->unitOfWork()->stateFor($identity); diff --git a/tests/Repository/RepositoryTest.php b/tests/Repository/RepositoryTest.php index 30a4bad..5e1ab5e 100644 --- a/tests/Repository/RepositoryTest.php +++ b/tests/Repository/RepositoryTest.php @@ -131,15 +131,15 @@ public function testInterface() $entity = new $this->class; $entity->uuid = new Uuid('21111111-1111-1111-1111-111111111111'); - $this->assertFalse($this->repository->has($entity->uuid)); + $this->assertFalse($this->repository->contains($entity->uuid)); $this->assertSame($this->repository, $this->repository->add($entity)); - $this->assertTrue($this->repository->has($entity->uuid)); + $this->assertTrue($this->repository->contains($entity->uuid)); $this->assertSame( $entity, $this->repository->get($entity->uuid) ); $this->assertSame($this->repository, $this->repository->remove($entity)); - $this->assertFalse($this->repository->has($entity->uuid)); + $this->assertFalse($this->repository->contains($entity->uuid)); $this->expectException(EntityNotFound::class); $this->repository->get($entity->uuid); From 436bbf0624dd3a8093823c879b4d33f7b748a3c8 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 18:32:33 +0100 Subject: [PATCH 12/17] methods with side effects must return void --- src/Entity/ChangesetComputer.php | 4 +- src/Entity/Container.php | 8 +- src/EntityFactory/EntityFactory.php | 2 +- src/Identity/Generator.php | 2 +- src/Identity/Generator/UuidGenerator.php | 4 +- src/Manager.php | 2 +- src/Manager/Manager.php | 4 +- src/Repository.php | 4 +- src/Repository/Repository.php | 8 +- src/UnitOfWork.php | 16 +-- tests/CommandBus/ClearDomainEventsTest.php | 129 +++++++++--------- tests/CommandBus/DispatchDomainEventsTest.php | 129 +++++++++--------- tests/Entity/ChangesetComputerTest.php | 3 +- tests/Entity/ContainerTest.php | 5 +- .../Identity/Generator/UuidGeneratorTest.php | 2 +- tests/Manager/ManagerTest.php | 2 +- tests/Persister/UpdatePersisterTest.php | 33 +++-- tests/Repository/RepositoryTest.php | 32 ++--- tests/UnitOfWorkTest.php | 18 +-- 19 files changed, 184 insertions(+), 223 deletions(-) diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index 9fbba2a..5cfe0fb 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -26,13 +26,11 @@ public function __construct() * * @param Map $source */ - public function use(Identity $identity, Map $source): self + public function use(Identity $identity, Map $source): void { assertMap('string', 'mixed', $source, 2); $this->sources = $this->sources->put($identity, $source); - - return $this; } /** diff --git a/src/Entity/Container.php b/src/Entity/Container.php index 7b5ce43..21f0376 100644 --- a/src/Entity/Container.php +++ b/src/Entity/Container.php @@ -32,7 +32,7 @@ public function __construct() /** * Inject the given entity with the wished state */ - public function push(Identity $identity, object $entity, State $wished): self + public function push(Identity $identity, object $entity, State $wished): void { if (!$this->states->contains($wished)) { throw new DomainException; @@ -52,8 +52,6 @@ public function push(Identity $identity, object $entity, State $wished): self return $entities->remove($identity); }); - - return $this; } /** @@ -69,7 +67,7 @@ public function state(State $state): Map /** * Remove the entity with the given identity from any state */ - public function detach(Identity $identity): self + public function detach(Identity $identity): void { $this->states = $this->states->map(static function( State $state, @@ -79,8 +77,6 @@ public function detach(Identity $identity): self ) { return $entities->remove($identity); }); - - return $this; } /** diff --git a/src/EntityFactory/EntityFactory.php b/src/EntityFactory/EntityFactory.php index 43132a5..956ee68 100644 --- a/src/EntityFactory/EntityFactory.php +++ b/src/EntityFactory/EntityFactory.php @@ -90,7 +90,7 @@ private function makeEntity(Entity $meta, Map $data): object $entity = ($this->resolve)($meta)($identity, $meta, $data); - $this->entities = $this->entities->push( + $this->entities->push( $identity, $entity, State::managed(), diff --git a/src/Identity/Generator.php b/src/Identity/Generator.php index 3f62dbc..904b986 100644 --- a/src/Identity/Generator.php +++ b/src/Identity/Generator.php @@ -26,7 +26,7 @@ public function get($value): Identity; /** * Add the given identity to the known ones by this generator */ - public function add(Identity $identity): self; + public function add(Identity $identity): void; /** * Return an identity instance with the given value diff --git a/src/Identity/Generator/UuidGenerator.php b/src/Identity/Generator/UuidGenerator.php index 1d4e0e5..901f259 100644 --- a/src/Identity/Generator/UuidGenerator.php +++ b/src/Identity/Generator/UuidGenerator.php @@ -58,15 +58,13 @@ public function get($value): Identity return $this->identities->get($value); } - public function add(Identity $identity): Generator + public function add(Identity $identity): void { /** @psalm-suppress ArgumentTypeCoercion */ $this->identities = ($this->identities)( $identity->toString(), $identity, ); - - return $this; } public function for($value): Identity diff --git a/src/Manager.php b/src/Manager.php index caa2fb5..9e2694f 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -14,6 +14,6 @@ public function repository(string $class): Repository; /** * Persist all the entities' modifications */ - public function flush(): self; + public function flush(): void; public function identities(): Generators; } diff --git a/src/Manager/Manager.php b/src/Manager/Manager.php index aa9d9a6..7c75871 100644 --- a/src/Manager/Manager.php +++ b/src/Manager/Manager.php @@ -45,11 +45,9 @@ public function repository(string $class): Repository ); } - public function flush(): ManagerInterface + public function flush(): void { $this->unitOfWork->commit(); - - return $this; } public function identities(): Generators diff --git a/src/Repository.php b/src/Repository.php index 07b6079..436fe6d 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -12,7 +12,7 @@ interface Repository /** * Add a new entity to the repository */ - public function add(object $entity): self; + public function add(object $entity): void; /** * Check if the repository has an entity with the given id @@ -34,7 +34,7 @@ public function find(Identity $identity): ?object; /** * Remove the given entity from the repository */ - public function remove(object $entity): self; + public function remove(object $entity): void; /** * Return all the entities from the repository diff --git a/src/Repository/Repository.php b/src/Repository/Repository.php index 91dc62e..667477e 100644 --- a/src/Repository/Repository.php +++ b/src/Repository/Repository.php @@ -41,11 +41,9 @@ public function __construct( ); } - public function add(object $entity): RepositoryInterface + public function add(object $entity): void { $this->unitOfWork()->persist($entity); - - return $this; } public function contains(Identity $identity): bool @@ -87,11 +85,9 @@ public function find(Identity $identity): ?object } } - public function remove(object $entity): RepositoryInterface + public function remove(object $entity): void { $this->unitOfWork()->remove($entity); - - return $this; } public function all(): Set diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 30c3d52..3e7f8bf 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -62,7 +62,7 @@ public function connection(): Connection /** * Add the given entity to the ones to be persisted */ - public function persist(object $entity): self + public function persist(object $entity): void { $identity = $this->extractIdentity($entity); @@ -78,8 +78,6 @@ public function persist(object $entity): self ->get($meta->identity()->type()) ->add($identity); } - - return $this; } /** @@ -136,7 +134,7 @@ public function get(string $class, Identity $identity): object /** * Plan the given entity to be removed */ - public function remove(object $entity): self + public function remove(object $entity): void { $identity = $this->extractIdentity($entity); @@ -163,20 +161,16 @@ public function remove(object $entity): self } catch (IdentityNotManaged $e) { //pass } - - return $this; } /** * Detach the given entity from the unit of work */ - public function detach(object $entity): self + public function detach(object $entity): void { $this->container->detach( $this->extractIdentity($entity), ); - - return $this; } /** @@ -197,11 +191,9 @@ public function execute(Query $query, Map $variables): Set /** * Send the modifications to the database */ - public function commit(): self + public function commit(): void { ($this->persist)($this->connection, $this->container); - - return $this; } /** diff --git a/tests/CommandBus/ClearDomainEventsTest.php b/tests/CommandBus/ClearDomainEventsTest.php index e7f93bb..21522ab 100644 --- a/tests/CommandBus/ClearDomainEventsTest.php +++ b/tests/CommandBus/ClearDomainEventsTest.php @@ -38,75 +38,74 @@ public function testHandle() ->method('__invoke') ->with($command); $container = new Container; - $container - ->push( - $this->createMock(Identity::class), - new class {}, - State::new() - ) - ->push( - $this->createMock(Identity::class), - $entity1 = new class implements ContainsRecordedEvents { - use EventRecorder; + $container->push( + $this->createMock(Identity::class), + new class {}, + State::new() + ); + $container->push( + $this->createMock(Identity::class), + $entity1 = new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::new() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::managed() - ) - ->push( - $this->createMock(Identity::class), - $entity2 = new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::new() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::managed() + ); + $container->push( + $this->createMock(Identity::class), + $entity2 = new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::managed() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::toBeRemoved() - ) - ->push( - $this->createMock(Identity::class), - $entity3 = new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::managed() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::toBeRemoved() + ); + $container->push( + $this->createMock(Identity::class), + $entity3 = new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::toBeRemoved() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::removed() - ) - ->push( - $this->createMock(Identity::class), - $entity4 = new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::toBeRemoved() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::removed() + ); + $container->push( + $this->createMock(Identity::class), + $entity4 = new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::removed() - ); + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::removed() + ); $handle = new ClearDomainEvents($commandBus, $container); $this->assertNull($handle($command)); diff --git a/tests/CommandBus/DispatchDomainEventsTest.php b/tests/CommandBus/DispatchDomainEventsTest.php index f8c2fec..07c4ce7 100644 --- a/tests/CommandBus/DispatchDomainEventsTest.php +++ b/tests/CommandBus/DispatchDomainEventsTest.php @@ -47,75 +47,74 @@ public function testHandle() return $event instanceof \stdClass; })); $container = new Container; - $container - ->push( - $this->createMock(Identity::class), - new class {}, - State::new() - ) - ->push( - $this->createMock(Identity::class), - new class implements ContainsRecordedEvents { - use EventRecorder; + $container->push( + $this->createMock(Identity::class), + new class {}, + State::new() + ); + $container->push( + $this->createMock(Identity::class), + new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::new() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::managed() - ) - ->push( - $this->createMock(Identity::class), - new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::new() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::managed() + ); + $container->push( + $this->createMock(Identity::class), + new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::managed() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::toBeRemoved() - ) - ->push( - $this->createMock(Identity::class), - new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::managed() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::toBeRemoved() + ); + $container->push( + $this->createMock(Identity::class), + new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::toBeRemoved() - ) - ->push( - $this->createMock(Identity::class), - new class {}, - State::removed() - ) - ->push( - $this->createMock(Identity::class), - new class implements ContainsRecordedEvents { - use EventRecorder; + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::toBeRemoved() + ); + $container->push( + $this->createMock(Identity::class), + new class {}, + State::removed() + ); + $container->push( + $this->createMock(Identity::class), + new class implements ContainsRecordedEvents { + use EventRecorder; - public function __construct() - { - $this->record(new \stdClass); - } - }, - State::removed() - ); + public function __construct() + { + $this->record(new \stdClass); + } + }, + State::removed() + ); $handle = new DispatchDomainEvents($commandBus, $eventBus, $container); $this->assertNull($handle($command)); diff --git a/tests/Entity/ChangesetComputerTest.php b/tests/Entity/ChangesetComputerTest.php index e4d9887..447abe3 100644 --- a/tests/Entity/ChangesetComputerTest.php +++ b/tests/Entity/ChangesetComputerTest.php @@ -40,8 +40,7 @@ public function testComputeWithoutSource() public function testComputeWithSource() { - $this->assertSame( - $this->computer, + $this->assertNull( $this->computer->use( $identity = $this->createMock(Identity::class), Map::of('string', 'mixed') diff --git a/tests/Entity/ContainerTest.php b/tests/Entity/ContainerTest.php index c2e0b95..fbfacb9 100644 --- a/tests/Entity/ContainerTest.php +++ b/tests/Entity/ContainerTest.php @@ -23,8 +23,7 @@ public function testInterface() $this->assertSame(0, $container->state(State::new())->size()); $this->assertSame(0, $container->state(State::toBeRemoved())->size()); $this->assertSame(0, $container->state(State::removed())->size()); - $this->assertSame( - $container, + $this->assertNull( $container->push($identity, $entity = new \stdClass, State::new()) ); $this->assertSame(0, $container->state(State::managed())->size()); @@ -34,7 +33,7 @@ public function testInterface() $this->assertSame(State::new(), $container->stateFor($identity)); $this->assertSame($entity, $container->get($identity)); $this->assertTrue($container->contains($identity)); - $this->assertSame($container, $container->detach($identity)); + $this->assertNull($container->detach($identity)); $this->assertFalse($container->contains($identity)); $this->assertSame(0, $container->state(State::managed())->size()); $this->assertSame(0, $container->state(State::new())->size()); diff --git a/tests/Identity/Generator/UuidGeneratorTest.php b/tests/Identity/Generator/UuidGeneratorTest.php index 2deaa83..4d94d7e 100644 --- a/tests/Identity/Generator/UuidGeneratorTest.php +++ b/tests/Identity/Generator/UuidGeneratorTest.php @@ -32,7 +32,7 @@ public function testAdd() $uuid = new Uuid($string = '11111111-1111-1111-1111-111111111111'); $this->assertFalse($generator->knows($string)); - $this->assertSame($generator, $generator->add($uuid)); + $this->assertNull($generator->add($uuid)); $this->assertTrue($generator->knows($string)); } diff --git a/tests/Manager/ManagerTest.php b/tests/Manager/ManagerTest.php index 53c89f3..134dfa8 100644 --- a/tests/Manager/ManagerTest.php +++ b/tests/Manager/ManagerTest.php @@ -75,7 +75,7 @@ public function testInterface() $this->assertInstanceOf(ManagerInterface::class, $manager); $this->assertSame($conn, $manager->connection()); $this->assertInstanceOf(get_class($mock), $manager->repository('foo')); - $this->assertSame($manager, $manager->flush()); + $this->assertNull($manager->flush()); $this->assertInstanceOf(Uuid::class, $manager->identities()->new(Uuid::class)); } } diff --git a/tests/Persister/UpdatePersisterTest.php b/tests/Persister/UpdatePersisterTest.php index e62032d..08c12a9 100644 --- a/tests/Persister/UpdatePersisterTest.php +++ b/tests/Persister/UpdatePersisterTest.php @@ -151,27 +151,26 @@ public function testPersist() $relationship->end = new Uuid($e = '11111111-1111-1111-1111-111111111114'); $container->push($relationship->uuid, $relationship, State::managed()); $count = 0; - $changeset - ->use( - $aggregate->uuid, - Map::of('string', 'mixed') + $changeset->use( + $aggregate->uuid, + Map::of('string', 'mixed') + ('created', new \DateTimeImmutable('2015-01-01')) + ('empty', null) + ('rel', Map::of('string', 'mixed') ('created', new \DateTimeImmutable('2015-01-01')) ('empty', null) - ('rel', Map::of('string', 'mixed') - ('created', new \DateTimeImmutable('2015-01-01')) + ('child', Map::of('string', 'mixed') + ('content', 'bar') ('empty', null) - ('child', Map::of('string', 'mixed') - ('content', 'bar') - ('empty', null) - ) ) - ) - ->use( - $relationship->uuid, - Map::of('string', 'mixed') - ('created', new \DateTimeImmutable('2015-01-01')) - ('empty', null) - ); + ) + ); + $changeset->use( + $relationship->uuid, + Map::of('string', 'mixed') + ('created', new \DateTimeImmutable('2015-01-01')) + ('empty', null) + ); $conn ->method('execute') diff --git a/tests/Repository/RepositoryTest.php b/tests/Repository/RepositoryTest.php index 5e1ab5e..92280fe 100644 --- a/tests/Repository/RepositoryTest.php +++ b/tests/Repository/RepositoryTest.php @@ -132,13 +132,13 @@ public function testInterface() $entity->uuid = new Uuid('21111111-1111-1111-1111-111111111111'); $this->assertFalse($this->repository->contains($entity->uuid)); - $this->assertSame($this->repository, $this->repository->add($entity)); + $this->assertNull($this->repository->add($entity)); $this->assertTrue($this->repository->contains($entity->uuid)); $this->assertSame( $entity, $this->repository->get($entity->uuid) ); - $this->assertSame($this->repository, $this->repository->remove($entity)); + $this->assertNull($this->repository->remove($entity)); $this->assertFalse($this->repository->contains($entity->uuid)); $this->expectException(EntityNotFound::class); @@ -167,10 +167,8 @@ public function testAll() $entity2 = new $this->class; $entity2->uuid = new Uuid('41111111-1111-1111-1111-111111111111'); - $this - ->repository - ->add($entity) - ->add($entity2); + $this->repository->add($entity); + $this->repository->add($entity2); $this->uow->commit(); $all = $this->repository->all(); @@ -179,10 +177,8 @@ public function testAll() $this->assertSame(2, $all->size()); $this->assertTrue($all->contains($entity)); $this->assertTrue($all->contains($entity2)); - $this - ->repository - ->remove($entity) - ->remove($entity2); + $this->repository->remove($entity); + $this->repository->remove($entity2); $this->uow->commit(); } @@ -198,11 +194,9 @@ public function testMatching() $entity3->uuid = new Uuid('71111111-1111-1111-1111-111111111111'); $entity3->content = 'bar'; - $this - ->repository - ->add($entity) - ->add($entity2) - ->add($entity3); + $this->repository->add($entity); + $this->repository->add($entity2); + $this->repository->add($entity3); $this->uow->commit(); $entities = $this->repository->matching(new Property('content', Sign::contains(), 'foo.*')); @@ -213,11 +207,9 @@ public function testMatching() $this->assertTrue($entities->contains($entity)); $this->assertTrue($entities->contains($entity2)); - $this - ->repository - ->remove($entity) - ->remove($entity2) - ->remove($entity3); + $this->repository->remove($entity); + $this->repository->remove($entity2); + $this->repository->remove($entity3); $this->uow->commit(); } } diff --git a/tests/UnitOfWorkTest.php b/tests/UnitOfWorkTest.php index 2d195b1..e7cd810 100644 --- a/tests/UnitOfWorkTest.php +++ b/tests/UnitOfWorkTest.php @@ -130,8 +130,7 @@ public function testPersist() $entity->uuid = new Uuid('11111111-1111-1111-1111-111111111111'); $this->assertFalse($this->uow->contains($entity->uuid)); - $this->assertSame( - $this->uow, + $this->assertNull( $this->uow->persist($entity) ); $this->assertTrue($this->uow->contains($entity->uuid)); @@ -153,8 +152,7 @@ public function testCommit(array $args) { list($uow, $entity) = $args; - $this->assertSame( - $uow, + $this->assertNull( $uow->commit() ); $this->assertSame( @@ -241,7 +239,7 @@ public function testRemoveNewEntity() $entity->uuid = new Uuid('11111111-1111-1111-1111-111111111111'); $this->uow->persist($entity); - $this->assertSame($this->uow, $this->uow->remove($entity)); + $this->assertNull($this->uow->remove($entity)); $this->assertSame( State::removed(), $this->uow->stateFor($entity->uuid) @@ -255,8 +253,7 @@ public function testRemoveManagedEntity(array $args) { list($uow, $entity) = $args; - $this->assertSame( - $uow, + $this->assertNull( $uow->remove($entity) ); $this->assertSame( @@ -271,7 +268,7 @@ public function testRemoveUnmanagedEntity() $entity = new $this->aggregateClass; $entity->uuid = new Uuid('11111111-1111-1111-1111-111111111111'); - $this->assertSame($this->uow, $this->uow->remove($entity)); + $this->assertNull($this->uow->remove($entity)); $this->expectException(IdentityNotManaged::class); $this->uow->stateFor($entity->uuid); @@ -284,8 +281,7 @@ public function testDetach(array $args) { list($uow, $entity) = $args; - $this->assertSame( - $uow, + $this->assertNull( $uow->detach($entity) ); $this->assertFalse($uow->contains($entity->uuid)); @@ -298,6 +294,6 @@ public function testDetachUnmanagedEntity() $entity = new $this->aggregateClass; $entity->uuid = new Uuid('11111111-1111-1111-1111-111111111111'); - $this->assertSame($this->uow, $this->uow->detach($entity)); + $this->assertNull($this->uow->detach($entity)); } } From 28e96d80eee3432f2e9f5e64d3ec252a12836b5b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 25 Mar 2020 18:34:11 +0100 Subject: [PATCH 13/17] CS --- src/Entity/ChangesetComputer.php | 4 ++-- src/Persister/InsertPersister.php | 2 +- src/Translation/IdentityMatch/AggregateTranslator.php | 6 +++--- src/Translation/Specification/AggregateTranslator.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Entity/ChangesetComputer.php b/src/Entity/ChangesetComputer.php index 5cfe0fb..d87fa25 100644 --- a/src/Entity/ChangesetComputer.php +++ b/src/Entity/ChangesetComputer.php @@ -30,7 +30,7 @@ public function use(Identity $identity, Map $source): void { assertMap('string', 'mixed', $source, 2); - $this->sources = $this->sources->put($identity, $source); + $this->sources = ($this->sources)($identity, $source); } /** @@ -83,7 +83,7 @@ private function diff(Map $source, Map $target): Map ->reduce( $changeset, static function(Map $carry, string $property) use ($target): Map { - return $carry->put($property, null); + return ($carry)($property, null); }, ) ->map(function(string $property, $value) use ($source, $target) { diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index 282f243..a978b56 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -192,7 +192,7 @@ function(Query $carry, string $property, Child $child) use ($varName, $data): Qu ); }, ); - $this->variables = $this->variables->add($varName->toString()); + $this->variables = ($this->variables)($varName->toString()); return $query; } diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index 6be90f9..dc84a70 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -61,9 +61,9 @@ function( $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $this->variables = $this->variables - ->add($relName->toString()) - ->add($childName->toString()); + $this->variables = ($this->variables) + ($relName->toString()) + ($childName->toString()); return $query ->match('entity') diff --git a/src/Translation/Specification/AggregateTranslator.php b/src/Translation/Specification/AggregateTranslator.php index 3d32595..5e7bded 100644 --- a/src/Translation/Specification/AggregateTranslator.php +++ b/src/Translation/Specification/AggregateTranslator.php @@ -70,9 +70,9 @@ function( $childName = $relName ->append('_') ->append($child->relationship()->childProperty()); - $this->variables = $this->variables - ->add($relName->toString()) - ->add($childName->toString()); + $this->variables = ($this->variables) + ($relName->toString()) + ($childName->toString()); return $this->addProperties( $this From 7d630f18665ec0089280589c862e54b1dd9d88a8 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 26 Mar 2020 10:46:31 +0100 Subject: [PATCH 14/17] replace travis by github ci --- .gitattributes | 4 +-- .github/workflows/ci.yml | 70 ++++++++++++++++++++++++++++++++++++++++ .scrutinizer.yml | 7 ---- .travis.yml | 20 ------------ README.md | 8 ++--- codecov.yml | 3 ++ 6 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml create mode 100644 codecov.yml diff --git a/.gitattributes b/.gitattributes index 614472a..7d503af 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,5 @@ /.gitattributes export-ignore /.gitignore export-ignore -/.scrutinizer.yml export-ignore -/circle.yml export-ignore /phpunit.xml.dist export-ignore /fixtures export-ignore -/Tests export-ignore +/tests export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dba4a6a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +name: CI + +on: [push] + +jobs: + phpunit: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + php-version: ['7.4'] + neo4j-version: ['3.4'] + name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }} - Neo4j/${{ matrix.neo4j-version }}' + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Setup Neo4j + uses: baptouuuu/setup-neo4j@v1.1.0 + with: + tag: ${{ matrix.neo4j-version }} + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: xdebug + ini-values: xdebug.max_nesting_level=2048 + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Dependencies + run: composer install --no-progress + - name: PHPUnit + run: vendor/bin/phpunit --coverage-clover=coverage.clover + - uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + psalm: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4'] + name: 'Psalm - PHP/${{ matrix.php-version }}' + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Dependencies + run: composer install --no-progress + - name: Psalm + run: vendor/bin/psalm --shepherd diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 202086f..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,7 +0,0 @@ -tools: - external_code_coverage: - runs: 2 -filter: - excluded_paths: - - tests/* - - graph.php diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dac3760..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php -php: - - 7.2 - - 7.3 - - nightly -matrix: - allow_failures: - - php: nightly -jdk: - - oraclejdk7 -before_script: - - wget dist.neo4j.org/neo4j-community-2.2.5-unix.tar.gz - - tar -xzf neo4j-community-2.2.5-unix.tar.gz - - sed -i.bak s/dbms.security.auth_enabled=true/dbms.security.auth_enabled=false/g neo4j-community-2.2.5/conf/neo4j-server.properties - - neo4j-community-2.2.5/bin/neo4j start - - composer install -script: phpunit --coverage-clover=coverage.clover -after_script: - - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/README.md b/README.md index 6b31043..ff5d45f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ # Neo4j-ONM -| `master` | `develop` | -|----------|-----------| -| [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/?branch=develop) | -| [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/?branch=master) | [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/?branch=develop) | -| [![Build Status](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/build-status/master) | [![Build Status](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/badges/build.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/neo4j-onm/build-status/develop) | +[![Build Status](https://github.com/Innmind/neo4j-onm/workflows/CI/badge.svg)](https://github.com/Innmind/neo4j-onm/actions?query=workflow%3ACI) +[![codecov](https://codecov.io/gh/Innmind/neo4j-onm/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/neo4j-onm) +[![Type Coverage](https://shepherd.dev/github/Innmind/neo4j-onm/coverage.svg)](https://shepherd.dev/github/Innmind/neo4j-onm) This an _ORM_ for the [Neo4j](http://neo4j.com/) graph database, with an emphasis on Domain Driven Design (DDD). It will allow you to easily build `Entities`, `Repositories` and query them via `Specification`s. Another important aspect is that each block of this library is fully replaceable. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..146e512 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +ignore: + - graph.php + - fixtures/ From f0192b314be27bb9eee83b8927f6e1a89b73dcd4 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 26 Mar 2020 11:07:38 +0100 Subject: [PATCH 15/17] add support for neo4j 4.0 --- .github/workflows/ci.yml | 2 +- src/Persister/InsertPersister.php | 14 +++++++------- src/Persister/RemovePersister.php | 8 ++++---- src/Persister/UpdatePersister.php | 10 +++++----- .../IdentityMatch/AggregateTranslator.php | 2 +- .../IdentityMatch/RelationshipTranslator.php | 2 +- .../Visitor/Cypher/AggregateVisitor.php | 4 ++-- .../Visitor/Cypher/RelationshipVisitor.php | 4 ++-- .../Visitor/PropertyMatch/AggregateVisitor.php | 5 ++--- .../Visitor/PropertyMatch/RelationshipVisitor.php | 5 ++--- tests/Persister/InsertPersisterTest.php | 2 +- tests/Persister/RemovePersisterTest.php | 2 +- tests/Persister/UpdatePersisterTest.php | 2 +- .../IdentityMatch/AggregateTranslatorTest.php | 2 +- .../IdentityMatch/DelegationTranslatorTest.php | 4 ++-- .../IdentityMatch/RelationshipTranslatorTest.php | 2 +- .../Specification/AggregateTranslatorTest.php | 4 ++-- .../Specification/RelationshipTranslatorTest.php | 4 ++-- .../Visitor/Cypher/AggregateVisitorTest.php | 2 +- .../Visitor/Cypher/RelationshipVisitorTest.php | 2 +- .../Visitor/PropertyMatch/AggregateVisitorTest.php | 12 ++++++------ .../PropertyMatch/RelationshipVisitorTest.php | 8 ++++---- 22 files changed, 50 insertions(+), 52 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba4a6a..47bf180 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: matrix: os: [ubuntu-latest] php-version: ['7.4'] - neo4j-version: ['3.4'] + neo4j-version: ['3.4', '4.0'] name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }} - Neo4j/${{ matrix.neo4j-version }}' steps: - name: Checkout diff --git a/src/Persister/InsertPersister.php b/src/Persister/InsertPersister.php index a978b56..f605bb4 100644 --- a/src/Persister/InsertPersister.php +++ b/src/Persister/InsertPersister.php @@ -144,8 +144,8 @@ private function createAggregate( ->withProperty( $meta->identity()->property(), $paramKey - ->prepend('{') - ->append('}.') + ->prepend('$') + ->append('.') ->append($meta->identity()->property()) ->toString(), ) @@ -295,7 +295,7 @@ static function(array $carry, string $key, $value): array { */ private function buildProperties(Map $properties, Str $name): Map { - $name = $name->prepend('{')->append('}.'); + $name = $name->prepend('$')->append('.'); /** @var Map */ return $properties->toMapOf( @@ -353,8 +353,8 @@ private function createRelationship( ->withProperty( $meta->identity()->property(), $paramKey - ->prepend('{') - ->append('}.') + ->prepend('$') + ->append('.') ->append($meta->identity()->property()) ->toString(), ) @@ -412,8 +412,8 @@ private function matchEdge( ->withProperty( $meta->target(), $name - ->prepend('{') - ->append('_props}.') + ->prepend('$') + ->append('_props.') ->append($meta->target()) ->toString(), ) diff --git a/src/Persister/RemovePersister.php b/src/Persister/RemovePersister.php index 6b44944..521fd49 100644 --- a/src/Persister/RemovePersister.php +++ b/src/Persister/RemovePersister.php @@ -136,8 +136,8 @@ private function matchRelationship( ->withProperty( $meta->identity()->property(), $name - ->prepend('{') - ->append('_identity}') + ->prepend('$') + ->append('_identity') ->toString(), ) ->withParameter( @@ -167,8 +167,8 @@ private function matchAggregate( ->withProperty( $meta->identity()->property(), $name - ->prepend('{') - ->append('_identity}') + ->prepend('$') + ->append('_identity') ->toString(), ) ->withParameter( diff --git a/src/Persister/UpdatePersister.php b/src/Persister/UpdatePersister.php index bc4534f..2d4bc4d 100644 --- a/src/Persister/UpdatePersister.php +++ b/src/Persister/UpdatePersister.php @@ -176,8 +176,8 @@ private function matchAggregate( ->withProperty( $meta->identity()->property(), $name - ->prepend('{') - ->append('_identity}') + ->prepend('$') + ->append('_identity') ->toString(), ) ->withParameter( @@ -274,8 +274,8 @@ private function matchRelationship( ->withProperty( $meta->identity()->property(), $name - ->prepend('{') - ->append('_identity}') + ->prepend('$') + ->append('_identity') ->toString(), ) ->withParameter( @@ -312,7 +312,7 @@ private function update(Str $variable, Map $changeset, Query $query): Query { return $query ->set(\sprintf( - '%s += {%s_props}', + '%s += $%s_props', $variable->toString(), $variable->toString(), )) diff --git a/src/Translation/IdentityMatch/AggregateTranslator.php b/src/Translation/IdentityMatch/AggregateTranslator.php index dc84a70..4676fd5 100644 --- a/src/Translation/IdentityMatch/AggregateTranslator.php +++ b/src/Translation/IdentityMatch/AggregateTranslator.php @@ -44,7 +44,7 @@ public function __invoke( ) ->withProperty( $meta->identity()->property(), - '{entity_identity}', + '$entity_identity', ) ->withParameter('entity_identity', $identity->value()) ->with('entity'); diff --git a/src/Translation/IdentityMatch/RelationshipTranslator.php b/src/Translation/IdentityMatch/RelationshipTranslator.php index 783f07d..b1dda23 100644 --- a/src/Translation/IdentityMatch/RelationshipTranslator.php +++ b/src/Translation/IdentityMatch/RelationshipTranslator.php @@ -33,7 +33,7 @@ public function __invoke( ) ->withProperty( $meta->identity()->property(), - '{entity_identity}', + '$entity_identity', ) ->withParameter('entity_identity', $identity->value()) ->return('start', 'end', 'entity'); diff --git a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php index 95a3ec5..402f2fb 100644 --- a/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/AggregateVisitor.php @@ -91,7 +91,7 @@ private function buildPropertyCondition(Comparator $specification): Where 'entity.%s %s %s', $prop, ($this->convert)($specification->sign()), - $key->prepend('{')->append('}')->toString(), + $key->prepend('$')->toString(), ), Map::of('string', 'mixed') ($key->toString(), $specification->value()), @@ -128,7 +128,7 @@ private function buildSubPropertyCondition(Comparator $specification): Where ->append($pieces->last()->toString()) ->toString(), ($this->convert)($specification->sign()), - $key->prepend('{')->append('}')->toString(), + $key->prepend('$')->toString(), ), Map::of('string', 'mixed') ($key->toString(), $specification->value()), diff --git a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php index 241f900..073a0bf 100644 --- a/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/Cypher/RelationshipVisitor.php @@ -103,7 +103,7 @@ private function buildPropertyCondition(Comparator $specification): Where 'entity.%s %s %s', $prop, ($this->convert)($specification->sign()), - $key->prepend('{')->append('}')->toString(), + $key->prepend('$')->toString(), ), Map::of('string', 'mixed') ($key->toString(), $specification->value()), @@ -137,7 +137,7 @@ private function buildEdgeCondition( $side, $edge->target(), ($this->convert)($specification->sign()), - $key->prepend('{')->append('}')->toString(), + $key->prepend('$')->toString(), ), Map::of('string', 'mixed') ($key->toString(), $value), diff --git a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php index 2a8a764..b14e6cc 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/AggregateVisitor.php @@ -92,7 +92,7 @@ private function buildPropertyMapping(Comparator $specification): Map 'entity', new PropertiesMatch( Map::of('string', 'string') - ($prop, $key->prepend('{')->append('}')->toString()), + ($prop, $key->prepend('$')->toString()), Map::of('string', 'mixed') ($key->toString(), $specification->value()), ), @@ -129,8 +129,7 @@ private function buildSubPropertyMapping(Comparator $specification): Map ( $pieces->last()->toString(), $key - ->prepend('{') - ->append('}') + ->prepend('$') ->toString(), ), Map::of('string', 'mixed') diff --git a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php index 19764b8..717b961 100644 --- a/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php +++ b/src/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitor.php @@ -104,7 +104,7 @@ private function buildPropertyMapping(Comparator $specification): Map 'entity', new PropertiesMatch( Map::of('string', 'string') - ($prop, $key->prepend('{')->append('}')->toString()), + ($prop, $key->prepend('$')->toString()), Map::of('string', 'mixed') ($key->toString(), $specification->value()), ), @@ -142,8 +142,7 @@ private function buildEdgeMapping( ( $edge->target(), $key - ->prepend('{') - ->append('}') + ->prepend('$') ->toString(), ), Map::of('string', 'mixed') diff --git a/tests/Persister/InsertPersisterTest.php b/tests/Persister/InsertPersisterTest.php index a3614ce..9cd8a9a 100644 --- a/tests/Persister/InsertPersisterTest.php +++ b/tests/Persister/InsertPersisterTest.php @@ -155,7 +155,7 @@ public function testPersist() ->method('execute') ->will($this->returnCallback(function($query) use (&$count) { $this->assertSame( - 'CREATE (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: {e38c6cbd28bf165070d070980dd1fb595_props}.uuid, created: {e38c6cbd28bf165070d070980dd1fb595_props}.created, empty: {e38c6cbd28bf165070d070980dd1fb595_props}.empty }), (e38c6cbd28bf165070d070980dd1fb595)<-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO { created: {e38c6cbd28bf165070d070980dd1fb595_rel_props}.created, empty: {e38c6cbd28bf165070d070980dd1fb595_rel_props}.empty }]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel { content: {e38c6cbd28bf165070d070980dd1fb595_rel_child_props}.content, empty: {e38c6cbd28bf165070d070980dd1fb595_rel_child_props}.empty }) WITH e38c6cbd28bf165070d070980dd1fb595 MATCH (e3c0eb72d56d7c664157fe196fa61f653 { uuid: {e3c0eb72d56d7c664157fe196fa61f653_props}.uuid }) WITH e38c6cbd28bf165070d070980dd1fb595, e3c0eb72d56d7c664157fe196fa61f653 MATCH (e4519d9310a314e2fce041e833b6553a9 { uuid: {e4519d9310a314e2fce041e833b6553a9_props}.uuid }) CREATE (e3c0eb72d56d7c664157fe196fa61f653)-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: {e50ead852f3361489a400ab5c70f6c5cf_props}.uuid, created: {e50ead852f3361489a400ab5c70f6c5cf_props}.created, empty: {e50ead852f3361489a400ab5c70f6c5cf_props}.empty }]->(e4519d9310a314e2fce041e833b6553a9)', + 'CREATE (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: $e38c6cbd28bf165070d070980dd1fb595_props.uuid, created: $e38c6cbd28bf165070d070980dd1fb595_props.created, empty: $e38c6cbd28bf165070d070980dd1fb595_props.empty }), (e38c6cbd28bf165070d070980dd1fb595)<-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO { created: $e38c6cbd28bf165070d070980dd1fb595_rel_props.created, empty: $e38c6cbd28bf165070d070980dd1fb595_rel_props.empty }]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel { content: $e38c6cbd28bf165070d070980dd1fb595_rel_child_props.content, empty: $e38c6cbd28bf165070d070980dd1fb595_rel_child_props.empty }) WITH e38c6cbd28bf165070d070980dd1fb595 MATCH (e3c0eb72d56d7c664157fe196fa61f653 { uuid: $e3c0eb72d56d7c664157fe196fa61f653_props.uuid }) WITH e38c6cbd28bf165070d070980dd1fb595, e3c0eb72d56d7c664157fe196fa61f653 MATCH (e4519d9310a314e2fce041e833b6553a9 { uuid: $e4519d9310a314e2fce041e833b6553a9_props.uuid }) CREATE (e3c0eb72d56d7c664157fe196fa61f653)-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: $e50ead852f3361489a400ab5c70f6c5cf_props.uuid, created: $e50ead852f3361489a400ab5c70f6c5cf_props.created, empty: $e50ead852f3361489a400ab5c70f6c5cf_props.empty }]->(e4519d9310a314e2fce041e833b6553a9)', $query->cypher() ); $this->assertCount(6, $query->parameters()); diff --git a/tests/Persister/RemovePersisterTest.php b/tests/Persister/RemovePersisterTest.php index 5e8bfc0..fb3754e 100644 --- a/tests/Persister/RemovePersisterTest.php +++ b/tests/Persister/RemovePersisterTest.php @@ -122,7 +122,7 @@ public function testPersist() ->method('execute') ->will($this->returnCallback(function($query) use (&$count) { $this->assertSame( - 'MATCH ()-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: {e50ead852f3361489a400ab5c70f6c5cf_identity} }]-(), (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: {e38c6cbd28bf165070d070980dd1fb595_identity} }), (e38c6cbd28bf165070d070980dd1fb595)-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel) DELETE e50ead852f3361489a400ab5c70f6c5cf, e38c6cbd28bf165070d070980dd1fb595, e38c6cbd28bf165070d070980dd1fb595_rel_child, e38c6cbd28bf165070d070980dd1fb595_rel', + 'MATCH ()-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: $e50ead852f3361489a400ab5c70f6c5cf_identity }]-(), (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: $e38c6cbd28bf165070d070980dd1fb595_identity }), (e38c6cbd28bf165070d070980dd1fb595)-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel) DELETE e50ead852f3361489a400ab5c70f6c5cf, e38c6cbd28bf165070d070980dd1fb595, e38c6cbd28bf165070d070980dd1fb595_rel_child, e38c6cbd28bf165070d070980dd1fb595_rel', $query->cypher() ); $this->assertCount(2, $query->parameters()); diff --git a/tests/Persister/UpdatePersisterTest.php b/tests/Persister/UpdatePersisterTest.php index 08c12a9..2f869d1 100644 --- a/tests/Persister/UpdatePersisterTest.php +++ b/tests/Persister/UpdatePersisterTest.php @@ -176,7 +176,7 @@ public function testPersist() ->method('execute') ->will($this->returnCallback(function($query) use (&$count) { $this->assertSame( - 'MATCH (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: {e38c6cbd28bf165070d070980dd1fb595_identity} }), (e38c6cbd28bf165070d070980dd1fb595)-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel), ()-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: {e50ead852f3361489a400ab5c70f6c5cf_identity} }]-() SET e38c6cbd28bf165070d070980dd1fb595 += {e38c6cbd28bf165070d070980dd1fb595_props}, e38c6cbd28bf165070d070980dd1fb595_rel += {e38c6cbd28bf165070d070980dd1fb595_rel_props}, e38c6cbd28bf165070d070980dd1fb595_rel_child += {e38c6cbd28bf165070d070980dd1fb595_rel_child_props}, e50ead852f3361489a400ab5c70f6c5cf += {e50ead852f3361489a400ab5c70f6c5cf_props}', + 'MATCH (e38c6cbd28bf165070d070980dd1fb595:Label { uuid: $e38c6cbd28bf165070d070980dd1fb595_identity }), (e38c6cbd28bf165070d070980dd1fb595)-[e38c6cbd28bf165070d070980dd1fb595_rel:FOO]-(e38c6cbd28bf165070d070980dd1fb595_rel_child:AnotherLabel), ()-[e50ead852f3361489a400ab5c70f6c5cf:type { uuid: $e50ead852f3361489a400ab5c70f6c5cf_identity }]-() SET e38c6cbd28bf165070d070980dd1fb595 += $e38c6cbd28bf165070d070980dd1fb595_props, e38c6cbd28bf165070d070980dd1fb595_rel += $e38c6cbd28bf165070d070980dd1fb595_rel_props, e38c6cbd28bf165070d070980dd1fb595_rel_child += $e38c6cbd28bf165070d070980dd1fb595_rel_child_props, e50ead852f3361489a400ab5c70f6c5cf += $e50ead852f3361489a400ab5c70f6c5cf_props', $query->cypher() ); $this->assertCount(6, $query->parameters()); diff --git a/tests/Translation/IdentityMatch/AggregateTranslatorTest.php b/tests/Translation/IdentityMatch/AggregateTranslatorTest.php index 906f011..d44606c 100644 --- a/tests/Translation/IdentityMatch/AggregateTranslatorTest.php +++ b/tests/Translation/IdentityMatch/AggregateTranslatorTest.php @@ -73,7 +73,7 @@ public function testTranslate() $this->assertInstanceOf(IdentityMatch::class, $identityMatch); $this->assertSame( - 'MATCH (entity:Label { id: {entity_identity} }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) RETURN entity, entity_rel, entity_rel_child', + 'MATCH (entity:Label { id: $entity_identity }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) RETURN entity, entity_rel, entity_rel_child', $identityMatch->query()->cypher() ); $this->assertCount(1, $identityMatch->query()->parameters()); diff --git a/tests/Translation/IdentityMatch/DelegationTranslatorTest.php b/tests/Translation/IdentityMatch/DelegationTranslatorTest.php index 722ac3a..e3c71cf 100644 --- a/tests/Translation/IdentityMatch/DelegationTranslatorTest.php +++ b/tests/Translation/IdentityMatch/DelegationTranslatorTest.php @@ -74,7 +74,7 @@ public function testTranslateAggregate() $this->assertInstanceOf(IdentityMatch::class, $identityMatch); $this->assertSame( - 'MATCH (entity:Label { id: {entity_identity} }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) RETURN entity, entity_rel, entity_rel_child', + 'MATCH (entity:Label { id: $entity_identity }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) RETURN entity, entity_rel, entity_rel_child', $identityMatch->query()->cypher() ); $this->assertCount(1, $identityMatch->query()->parameters()); @@ -116,7 +116,7 @@ public function testTranslateRelationship() $this->assertInstanceOf(IdentityMatch::class, $identityMatch); $this->assertSame( - 'MATCH (start)-[entity:type { id: {entity_identity} }]->(end) RETURN start, end, entity', + 'MATCH (start)-[entity:type { id: $entity_identity }]->(end) RETURN start, end, entity', $identityMatch->query()->cypher() ); $this->assertCount(1, $identityMatch->query()->parameters()); diff --git a/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php b/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php index ba634d2..3a9df11 100644 --- a/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php +++ b/tests/Translation/IdentityMatch/RelationshipTranslatorTest.php @@ -53,7 +53,7 @@ public function testTranslate() $this->assertInstanceOf(IdentityMatch::class, $identityMatch); $this->assertSame( - 'MATCH (start)-[entity:type { id: {entity_identity} }]->(end) RETURN start, end, entity', + 'MATCH (start)-[entity:type { id: $entity_identity }]->(end) RETURN start, end, entity', $identityMatch->query()->cypher() ); $this->assertCount(1, $identityMatch->query()->parameters()); diff --git a/tests/Translation/Specification/AggregateTranslatorTest.php b/tests/Translation/Specification/AggregateTranslatorTest.php index 18ae8e6..364d108 100644 --- a/tests/Translation/Specification/AggregateTranslatorTest.php +++ b/tests/Translation/Specification/AggregateTranslatorTest.php @@ -84,7 +84,7 @@ public function testTranslateWithPropertyMatch() $this->assertInstanceOf(IdentityMatch::class, $match); $this->assertSame( - 'MATCH (entity:Label { empty: {entity_empty}, created: {entity_created} }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF { empty: {entity_rel_empty}, created: {entity_rel_created} }]-(entity_rel_child:AnotherLabel { empty: {entity_rel_child_empty}, content: {entity_rel_child_content} }) RETURN entity, entity_rel, entity_rel_child', + 'MATCH (entity:Label { empty: $entity_empty, created: $entity_created }) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF { empty: $entity_rel_empty, created: $entity_rel_created }]-(entity_rel_child:AnotherLabel { empty: $entity_rel_child_empty, content: $entity_rel_child_content }) RETURN entity, entity_rel, entity_rel_child', $match->query()->cypher() ); $this->assertCount(6, $match->query()->parameters()); @@ -127,7 +127,7 @@ public function testTranslateWithWhereClause() $this->assertInstanceOf(IdentityMatch::class, $match); $this->assertSame( - 'MATCH (entity:Label) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) WHERE (((((entity.created = {entity_created1} AND entity.empty = {entity_empty2}) OR entity_rel.created = {entity_rel_created3}) AND entity_rel.empty = {entity_rel_empty4}) AND entity_rel_child.content = {entity_rel_child_content5}) AND NOT (entity_rel_child.empty = {entity_rel_child_empty6})) RETURN entity, entity_rel, entity_rel_child', + 'MATCH (entity:Label) WITH entity MATCH (entity)<-[entity_rel:CHILD1_OF]-(entity_rel_child:AnotherLabel) WHERE (((((entity.created = $entity_created1 AND entity.empty = $entity_empty2) OR entity_rel.created = $entity_rel_created3) AND entity_rel.empty = $entity_rel_empty4) AND entity_rel_child.content = $entity_rel_child_content5) AND NOT (entity_rel_child.empty = $entity_rel_child_empty6)) RETURN entity, entity_rel, entity_rel_child', $match->query()->cypher() ); $this->assertCount(6, $match->query()->parameters()); diff --git a/tests/Translation/Specification/RelationshipTranslatorTest.php b/tests/Translation/Specification/RelationshipTranslatorTest.php index 7da3fbf..b06de71 100644 --- a/tests/Translation/Specification/RelationshipTranslatorTest.php +++ b/tests/Translation/Specification/RelationshipTranslatorTest.php @@ -65,7 +65,7 @@ public function testTranslateWithPropertyMatch() $this->assertInstanceOf(IdentityMatch::class, $match); $this->assertSame( - 'MATCH (start { id: {start_id} })-[entity:type { empty: {entity_empty}, created: {entity_created} }]->(end { id: {end_id} }) RETURN start, end, entity', + 'MATCH (start { id: $start_id })-[entity:type { empty: $entity_empty, created: $entity_created }]->(end { id: $end_id }) RETURN start, end, entity', $match->query()->cypher() ); $this->assertCount(4, $match->query()->parameters()); @@ -104,7 +104,7 @@ public function testTranslateWithWhereClause() $this->assertInstanceOf(IdentityMatch::class, $match); $this->assertSame( - 'MATCH (start)-[entity:type]->(end) WHERE (((entity.created = {entity_created1} OR entity.empty = {entity_empty2}) AND start.id = {start_id3}) AND NOT (end.id = {end_id4})) RETURN start, end, entity', + 'MATCH (start)-[entity:type]->(end) WHERE (((entity.created = $entity_created1 OR entity.empty = $entity_empty2) AND start.id = $start_id3) AND NOT (end.id = $end_id4)) RETURN start, end, entity', $match->query()->cypher() ); $this->assertCount(4, $match->query()->parameters()); diff --git a/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php b/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php index 95b372d..a1295e6 100644 --- a/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php +++ b/tests/Translation/Specification/Visitor/Cypher/AggregateVisitorTest.php @@ -77,7 +77,7 @@ public function testVisit() ); $this->assertSame( - '(((((entity.created = {entity_created1} AND entity.empty = {entity_empty2}) OR entity_rel.created = {entity_rel_created3}) AND entity_rel.empty = {entity_rel_empty4}) AND entity_rel_child.content = {entity_rel_child_content5}) AND NOT (entity_rel_child.empty = {entity_rel_child_empty6}))', + '(((((entity.created = $entity_created1 AND entity.empty = $entity_empty2) OR entity_rel.created = $entity_rel_created3) AND entity_rel.empty = $entity_rel_empty4) AND entity_rel_child.content = $entity_rel_child_content5) AND NOT (entity_rel_child.empty = $entity_rel_child_empty6))', $condition->cypher() ); $this->assertSame('string', (string) $condition->parameters()->keyType()); diff --git a/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php b/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php index 9ab69c1..17f3408 100644 --- a/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php +++ b/tests/Translation/Specification/Visitor/Cypher/RelationshipVisitorTest.php @@ -60,7 +60,7 @@ public function testVisit() ); $this->assertSame( - '(((entity.created = {entity_created1} OR entity.empty = {entity_empty2}) AND start.id = {start_id3}) AND NOT (end.id = {end_id4}))', + '(((entity.created = $entity_created1 OR entity.empty = $entity_empty2) AND start.id = $start_id3) AND NOT (end.id = $end_id4))', $condition->cypher() ); $this->assertSame('string', (string) $condition->parameters()->keyType()); diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php index 13afc1f..b39e66b 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/AggregateVisitorTest.php @@ -90,20 +90,20 @@ public function testVisit() unwrap($mapping->keys()), ); $this->assertCount(2, $mapping->get('entity')->properties()); - $this->assertSame('{entity_empty}', $mapping->get('entity')->properties()->get('empty')); - $this->assertSame('{entity_created}', $mapping->get('entity')->properties()->get('created')); + $this->assertSame('$entity_empty', $mapping->get('entity')->properties()->get('empty')); + $this->assertSame('$entity_created', $mapping->get('entity')->properties()->get('created')); $this->assertCount(2, $mapping->get('entity')->parameters()); $this->assertNull($mapping->get('entity')->parameters()->get('entity_empty')); $this->assertNull($mapping->get('entity')->parameters()->get('entity_created')); $this->assertCount(2, $mapping->get('entity_rel')->properties()); - $this->assertSame('{entity_rel_empty}', $mapping->get('entity_rel')->properties()->get('empty')); - $this->assertSame('{entity_rel_created}', $mapping->get('entity_rel')->properties()->get('created')); + $this->assertSame('$entity_rel_empty', $mapping->get('entity_rel')->properties()->get('empty')); + $this->assertSame('$entity_rel_created', $mapping->get('entity_rel')->properties()->get('created')); $this->assertCount(2, $mapping->get('entity_rel')->parameters()); $this->assertNull($mapping->get('entity_rel')->parameters()->get('entity_rel_empty')); $this->assertNull($mapping->get('entity_rel')->parameters()->get('entity_rel_created')); $this->assertCount(2, $mapping->get('entity_rel_child')->properties()); - $this->assertSame('{entity_rel_child_empty}', $mapping->get('entity_rel_child')->properties()->get('empty')); - $this->assertSame('{entity_rel_child_content}', $mapping->get('entity_rel_child')->properties()->get('content')); + $this->assertSame('$entity_rel_child_empty', $mapping->get('entity_rel_child')->properties()->get('empty')); + $this->assertSame('$entity_rel_child_content', $mapping->get('entity_rel_child')->properties()->get('content')); $this->assertCount(2, $mapping->get('entity_rel_child')->parameters()); $this->assertNull($mapping->get('entity_rel_child')->parameters()->get('entity_rel_child_empty')); $this->assertNull($mapping->get('entity_rel_child')->parameters()->get('entity_rel_child_content')); diff --git a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php index d77d58c..1d1a261 100644 --- a/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php +++ b/tests/Translation/Specification/Visitor/PropertyMatch/RelationshipVisitorTest.php @@ -70,16 +70,16 @@ public function testVisit() ['entity', 'start', 'end'], unwrap($mapping->keys()), ); - $this->assertSame('{entity_empty}', $mapping->get('entity')->properties()->get('empty')); - $this->assertSame('{entity_created}', $mapping->get('entity')->properties()->get('created')); + $this->assertSame('$entity_empty', $mapping->get('entity')->properties()->get('empty')); + $this->assertSame('$entity_created', $mapping->get('entity')->properties()->get('created')); $this->assertNull($mapping->get('entity')->parameters()->get('entity_empty')); $this->assertNull($mapping->get('entity')->parameters()->get('entity_created')); $this->assertCount(1, $mapping->get('start')->properties()); - $this->assertSame('{start_id}', $mapping->get('start')->properties()->get('id')); + $this->assertSame('$start_id', $mapping->get('start')->properties()->get('id')); $this->assertCount(1, $mapping->get('start')->parameters()); $this->assertSame('foo', $mapping->get('start')->parameters()->get('start_id')); $this->assertCount(1, $mapping->get('end')->properties()); - $this->assertSame('{end_id}', $mapping->get('end')->properties()->get('id')); + $this->assertSame('$end_id', $mapping->get('end')->properties()->get('id')); $this->assertCount(1, $mapping->get('end')->parameters()); $this->assertSame('bar', $mapping->get('end')->parameters()->get('end_id')); } From 6b590109ac7ed41b266f01f1e1981d876b8163cd Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 26 Mar 2020 11:15:47 +0100 Subject: [PATCH 16/17] fix incompatible query --- tests/UnitOfWorkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnitOfWorkTest.php b/tests/UnitOfWorkTest.php index e7cd810..899fcde 100644 --- a/tests/UnitOfWorkTest.php +++ b/tests/UnitOfWorkTest.php @@ -184,7 +184,7 @@ public function testLoadEntityFromDatabase() $this->conn->execute( (new Query) ->create('n', 'Label') - ->withProperty('uuid', '{uuid}') + ->withProperty('uuid', '$uuid') ->withParameter('uuid', $uuid = '11111111-1111-1111-1111-111111111112') ); From 71e71d2279243d8ed4d2ee793a8e4cded49ba777 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 26 Mar 2020 11:21:34 +0100 Subject: [PATCH 17/17] update the documentation --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ff5d45f..5de7c44 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Each entity is fully managed by its own `Repository`, meaning it's used to `add` **Note**: for performance issues, when you `add` an entity to its repository it's not directly inserted in the graph. -To access an entity repository, you'll use a `Manager` which only contains 4 methods: `connection`, `repository`, `flush` and `identities`. The first one gives you access to the DBAL [`Connection`](https://github.com/Innmind/neo4j-dbal/blob/master/Connection.php) so you can open/commit transactions. The method `repository` takes the entity class in order to return the associated repository. `flush` will persist in the graph all of your modifications from your repositories. Finally, `identities` allows you to generate a new identity of the specified type +To access an entity repository, you'll use a `Manager` which only contains 4 methods: `connection`, `repository`, `flush` and `identities`. The first one gives you access to the DBAL [`Connection`](https://github.com/Innmind/neo4j-dbal/blob/master/src/Connection.php) so you can open/commit transactions. The method `repository` takes the entity class in order to return the associated repository. `flush` will persist in the graph all of your modifications from your repositories. Finally, `identities` allows you to generate a new identity of the specified type When you `flush` the sequence of how the modifications are persisted is as follow: @@ -159,7 +159,7 @@ Now that you know how to add/remove, let's learn how query our entities back fro $image = images->get(new Uuid($_GET['wished_image_id'])); ``` -**Note**: the usage of `$_GET` here is only to be framework agnostic, but even if you'd use it would be pretty safe as `Uuid` validates the data (as you can see [here](Identity/Uuid.php#L20)). +**Note**: the usage of `$_GET` here is only to be framework agnostic, but even if you'd use it would be pretty safe as `Uuid` validates the data (as you can see [here](src/Identity/Uuid.php#L20)). But accessing entities through their identifiers is not enough, that's why a repository as a method called `matching` which allows only a single parameter that has to be a [specification](https://github.com/Innmind/Specification). @@ -193,7 +193,7 @@ By default there's only 7 types you can use for your entities' properties: * `SetType` (similar as `ArrayType` except it uses the immutable [`Set`](https://github.com/Innmind/Immutable#set)) * `StringType` -To add your own type you need to create a class implementing [`Type.php`](Type.php). +To add your own type you need to create a class implementing [`Type.php`](src/Type.php). #### Entity Translators @@ -255,7 +255,7 @@ $services = bootstrap( By default this library only use UUIDs as identity objects. But you can easily add your own kind of identity object. -You need to create the identity class implementing [`Identity`](Identity.php) and the corresponding generator implementing [`Generator`](Identity/Generator.php). +You need to create the identity class implementing [`Identity`](src/Identity.php) and the corresponding generator implementing [`Generator`](src/Identity/Generator.php). ```php use Innmind\Neo4j\ONM\{