From 3310d74b701430d05967283d78c6f0fca345ce6c Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:22:40 +0100 Subject: [PATCH] TASK: Adjust namings to remove obsolete `fromNameAnd` part and remove duplicated `fromReferences` naming in chain, now its `create` for root level --- .../Common/NodeReferencingInternals.php | 2 +- .../Dto/NodeSubtreeSnapshot.php | 2 +- .../Dto/NodeReferenceToWrite.php | 6 ++- .../Dto/NodeReferencesForName.php | 22 +++++------ .../Dto/NodeReferencesToWrite.php | 28 +++++++------- .../Dto/SerializedNodeReferencesForName.php | 4 +- .../NodeReferencesToWriteTest.php | 38 +++++++++---------- .../Classes/NodeDataToEventsProcessor.php | 2 +- .../Bootstrap/Features/NodeReferencing.php | 2 +- 9 files changed, 55 insertions(+), 51 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php b/Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php index 7ecf041dea2..6e39c1e0ebf 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php +++ b/Neos.ContentRepository.Core/Classes/Feature/Common/NodeReferencingInternals.php @@ -47,7 +47,7 @@ private function mapNodeReferencesToSerializedNodeReferences(NodeReferencesToWri ); } - $serializedReferencesByProperty[] = SerializedNodeReferencesForName::fromNameAndSerializedReferences( + $serializedReferencesByProperty[] = SerializedNodeReferencesForName::fromSerializedReferences( $referencesByProperty->referenceName, $serializedReferences ); diff --git a/Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeSubtreeSnapshot.php b/Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeSubtreeSnapshot.php index 8cf4c44ce9e..1a724f5dbef 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeSubtreeSnapshot.php +++ b/Neos.ContentRepository.Core/Classes/Feature/NodeDuplication/Dto/NodeSubtreeSnapshot.php @@ -127,7 +127,7 @@ private static function serializeProjectedReferences(References $references): Se } foreach ($serializedReferencesByName as $name => $referenceObjects) { - $serializedReferences[] = SerializedNodeReferencesForName::fromNameAndSerializedReferences(ReferenceName::fromString($name), $referenceObjects); + $serializedReferences[] = SerializedNodeReferencesForName::fromSerializedReferences(ReferenceName::fromString($name), $referenceObjects); } return SerializedNodeReferences::fromArray($serializedReferences); diff --git a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php index 54090dad326..ca19593f6dc 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php +++ b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferenceToWrite.php @@ -16,7 +16,6 @@ use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; -use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName; /** * A single node references to write @@ -40,6 +39,11 @@ private function __construct( ) { } + /** + * The node aggregate id as target of the reference to write + * + * To set a collection of node aggregate ids as targets see {@see NodeReferencesForName::fromTargets()} as utility + */ public static function fromTarget(NodeAggregateId $target): self { return new self($target, PropertyValuesToWrite::createEmpty()); diff --git a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesForName.php b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesForName.php index c07b157265b..4c0200cf7e3 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesForName.php +++ b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesForName.php @@ -45,26 +45,26 @@ private function __construct( $this->references = $references; } - public static function fromNameAndTargets(ReferenceName $name, NodeAggregateIds $nodeAggregateIds): self + /** + * As the previously set references will be replaced by writing new references specifying + * no references for a name will delete the previous ones + */ + public static function createEmpty(ReferenceName $name): self { - $references = array_map(NodeReferenceToWrite::fromTarget(...), iterator_to_array($nodeAggregateIds)); - return new self($name, ...$references); + return new self($name, ...[]); } - /** - * @param NodeReferenceToWrite[] $references - */ - public static function fromNameAndReferences(ReferenceName $name, array $references): self + public static function fromTargets(ReferenceName $name, NodeAggregateIds $nodeAggregateIds): self { + $references = array_map(NodeReferenceToWrite::fromTarget(...), iterator_to_array($nodeAggregateIds)); return new self($name, ...$references); } /** - * As the previously set references will be replaced by writing new references specifying - * no references for a name will delete the previous ones + * @param NodeReferenceToWrite[] $references */ - public static function createEmpty(ReferenceName $name): self + public static function fromReferences(ReferenceName $name, array $references): self { - return new self($name, ...[]); + return new self($name, ...$references); } } diff --git a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesToWrite.php b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesToWrite.php index d965fe2cf38..fae2924e38b 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesToWrite.php +++ b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/NodeReferencesToWrite.php @@ -28,18 +28,18 @@ /** * @var array */ - public array $references; + public array $referencesForName; - private function __construct(NodeReferencesForName ...$references) + private function __construct(NodeReferencesForName ...$items) { - $referencesByName = []; - foreach ($references as $reference) { - if (isset($referencesByName[$reference->referenceName->value])) { - throw new \InvalidArgumentException(sprintf('NodeReferencesToWrite does not accept references for the same name %s multiple times.', $reference->referenceName->value), 1718193720); + $referencesForName = []; + foreach ($items as $item) { + if (isset($referencesForName[$item->referenceName->value])) { + throw new \InvalidArgumentException(sprintf('NodeReferencesToWrite does not accept references for the same name %s multiple times.', $item->referenceName->value), 1718193720); } - $referencesByName[$reference->referenceName->value] = $reference; + $referencesForName[$item->referenceName->value] = $item; } - $this->references = $referencesByName; + $this->referencesForName = $referencesForName; } public static function createEmpty(): self @@ -47,9 +47,9 @@ public static function createEmpty(): self return new self(); } - public static function fromReferences(NodeReferencesForName ...$references): self + public static function create(NodeReferencesForName ...$referencesForName): self { - return new self(...$references); + return new self(...$referencesForName); } /** @@ -62,23 +62,23 @@ public static function fromArray(array $references): self public function withReference(NodeReferencesForName $referencesForName): self { - $references = $this->references; + $references = $this->referencesForName; $references[$referencesForName->referenceName->value] = $referencesForName; return new self(...$references); } public function merge(NodeReferencesToWrite $other): self { - return new self(...array_merge($this->references, $other->references)); + return new self(...array_merge($this->referencesForName, $other->referencesForName)); } public function getIterator(): \Traversable { - yield from array_values($this->references); + yield from array_values($this->referencesForName); } public function isEmpty(): bool { - return count($this->references) === 0; + return count($this->referencesForName) === 0; } } diff --git a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReferencesForName.php b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReferencesForName.php index a0f87372e65..8fa262aeb3f 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReferencesForName.php +++ b/Neos.ContentRepository.Core/Classes/Feature/NodeReferencing/Dto/SerializedNodeReferencesForName.php @@ -48,12 +48,12 @@ private function __construct( * @param SerializedNodeReference[] $references * @return self */ - public static function fromNameAndSerializedReferences(ReferenceName $referenceName, array $references): self + public static function fromSerializedReferences(ReferenceName $referenceName, array $references): self { return new self($referenceName, ...$references); } - public static function fromNameAndTargets(ReferenceName $referenceName, NodeAggregateIds $nodeAggregateIds): self + public static function fromTargets(ReferenceName $referenceName, NodeAggregateIds $nodeAggregateIds): self { $references = array_map(SerializedNodeReference::fromTarget(...), iterator_to_array($nodeAggregateIds)); return new self($referenceName, ...$references); diff --git a/Neos.ContentRepository.Core/Tests/Unit/Feature/NodeReferencing/NodeReferencesToWriteTest.php b/Neos.ContentRepository.Core/Tests/Unit/Feature/NodeReferencing/NodeReferencesToWriteTest.php index 3143366a006..9b76142793a 100644 --- a/Neos.ContentRepository.Core/Tests/Unit/Feature/NodeReferencing/NodeReferencesToWriteTest.php +++ b/Neos.ContentRepository.Core/Tests/Unit/Feature/NodeReferencing/NodeReferencesToWriteTest.php @@ -28,32 +28,32 @@ public function testMultipleNamesAreNotAllowedInConstructor(): void { self::expectException(\InvalidArgumentException::class); - NodeReferencesToWrite::fromReferences( + NodeReferencesToWrite::create( NodeReferencesForName::createEmpty(ReferenceName::fromString('foo')), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), ); } public function testMergeOverridesPrevious(): void { - $a = NodeReferencesToWrite::fromReferences( - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), + $a = NodeReferencesToWrite::create( + NodeReferencesForName::fromTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), ); - $b = NodeReferencesToWrite::fromReferences( - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('new'), NodeAggregateIds::fromArray(['la-li-lu'])), + $b = NodeReferencesToWrite::create( + NodeReferencesForName::fromTargets(ReferenceName::fromString('new'), NodeAggregateIds::fromArray(['la-li-lu'])), NodeReferencesForName::createEmpty(ReferenceName::fromString('foo')), ); $c = $a->merge($b); self::assertEquals( - iterator_to_array(NodeReferencesToWrite::fromReferences( + iterator_to_array(NodeReferencesToWrite::create( NodeReferencesForName::createEmpty(ReferenceName::fromString('foo')), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('new'), NodeAggregateIds::fromArray(['la-li-lu'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('new'), NodeAggregateIds::fromArray(['la-li-lu'])), )), iterator_to_array($c) ); @@ -61,19 +61,19 @@ public function testMergeOverridesPrevious(): void public function testAppendOverridesPrevious(): void { - $a = NodeReferencesToWrite::fromReferences( - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), + $a = NodeReferencesToWrite::create( + NodeReferencesForName::fromTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['fooo'])), ); - $b = NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['la-li-lu', 'second'])); + $b = NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['la-li-lu', 'second'])); $c = $a->withReference($b); self::assertEquals( - iterator_to_array(NodeReferencesToWrite::fromReferences( - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), - NodeReferencesForName::fromNameAndTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['la-li-lu', 'second'])) + iterator_to_array(NodeReferencesToWrite::create( + NodeReferencesForName::fromTargets(ReferenceName::fromString('foo'), NodeAggregateIds::fromArray(['abc'])), + NodeReferencesForName::fromTargets(ReferenceName::fromString('bar'), NodeAggregateIds::fromArray(['la-li-lu', 'second'])) )), iterator_to_array($c) ); @@ -83,7 +83,7 @@ public function testSameTargetsAreNotAllowedMultipleTimes(): void { self::expectException(\InvalidArgumentException::class); - NodeReferencesForName::fromNameAndReferences(ReferenceName::fromString('bar'), [ + NodeReferencesForName::fromReferences(ReferenceName::fromString('bar'), [ NodeReferenceToWrite::fromTarget(NodeAggregateId::fromString('node1')), NodeReferenceToWrite::fromTarget(NodeAggregateId::fromString('node-other')), NodeReferenceToWrite::fromTarget(NodeAggregateId::fromString('node1')), diff --git a/Neos.ContentRepository.LegacyNodeMigration/Classes/NodeDataToEventsProcessor.php b/Neos.ContentRepository.LegacyNodeMigration/Classes/NodeDataToEventsProcessor.php index 08a4d2bc818..894cfa441e9 100644 --- a/Neos.ContentRepository.LegacyNodeMigration/Classes/NodeDataToEventsProcessor.php +++ b/Neos.ContentRepository.LegacyNodeMigration/Classes/NodeDataToEventsProcessor.php @@ -360,7 +360,7 @@ public function extractPropertyValuesAndReferences(array $nodeDataRow, NodeType if (!is_array($propertyValue)) { $propertyValue = [$propertyValue]; } - $references[] = SerializedNodeReferencesForName::fromNameAndTargets( + $references[] = SerializedNodeReferencesForName::fromTargets( ReferenceName::fromString($propertyName), NodeAggregateIds::fromArray($propertyValue) ); diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeReferencing.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeReferencing.php index 5a931209a91..43cdfc68c60 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeReferencing.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/Features/NodeReferencing.php @@ -107,7 +107,7 @@ protected function mapRawNodeReferencesToNodeReferencesToWrite(array $deserializ $properties = isset($referenceData['properties']) ? $this->deserializeProperties($referenceData['properties']) : PropertyValuesToWrite::createEmpty(); $references[] = NodeReferenceToWrite::fromTargetAndProperties(NodeAggregateId::fromString($referenceData['target']), $properties); } - $referencesForProperty[] = NodeReferencesForName::fromNameAndReferences(ReferenceName::fromString($nodeReferencesForProperty['referenceName']), $references); + $referencesForProperty[] = NodeReferencesForName::fromReferences(ReferenceName::fromString($nodeReferencesForProperty['referenceName']), $references); } return NodeReferencesToWrite::fromArray($referencesForProperty); }