Skip to content

Commit

Permalink
TASK: Remove PropertyCollectionInterface and make `PropertyCollecti…
Browse files Browse the repository at this point in the history
…on` not array like

resolves #4464
  • Loading branch information
mhsdesign committed Sep 3, 2023
1 parent 6cccfed commit 17c989e
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

namespace Neos\ContentRepository\Core\Feature\NodeDuplication\Dto;

use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindReferencesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;

/**
* Implementation detail of {@see CopyNodesRecursively}
Expand Down Expand Up @@ -51,7 +50,6 @@ public static function fromSubgraphAndStartNode(ContentSubgraphInterface $subgra
) {
$childNodes[] = self::fromSubgraphAndStartNode($subgraph, $sourceChildNode);
}
/** @var PropertyCollectionInterface $properties */
$properties = $sourceNode->properties;

return new self(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function __construct(
* References are NOT part of this API, but can be read through
* the subgraph {@see ContentSubgraphInterface::findReferences()}.
*
* You can also read the serialized properties {@see PropertyCollectionInterface::serialized()}.
* You can also read the serialized properties {@see PropertyCollection::serialized()}.
*/
public readonly PropertyCollectionInterface $properties,
public readonly PropertyCollection $properties,
public readonly ?NodeName $nodeName,
public readonly Timestamps $timestamps,
) {
Expand All @@ -84,7 +84,7 @@ public function __construct(
*/
public function getProperty(string $propertyName): mixed
{
return $this->properties->offsetGet($propertyName);
return $this->properties->get($propertyName);
}

/**
Expand All @@ -97,7 +97,7 @@ public function getProperty(string $propertyName): mixed
*/
public function hasProperty(string $propertyName): bool
{
return $this->properties->offsetExists($propertyName);
return $this->properties->has($propertyName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

/**
* The property collection implementation
* @internal
*
* @extends \IteratorAggregate<string,mixed>
* @api
*/
final class PropertyCollection implements PropertyCollectionInterface
final class PropertyCollection implements \IteratorAggregate

Check failure on line 26 in Neos.ContentRepository.Core/Classes/Projection/ContentGraph/PropertyCollection.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Class Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollection has @extends tag, but does not extend any class.

Check failure on line 26 in Neos.ContentRepository.Core/Classes/Projection/ContentGraph/PropertyCollection.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Class Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollection implements generic interface IteratorAggregate but does not specify its types: TKey, TValue
{
/**
* Properties from Nodes
Expand All @@ -46,33 +48,23 @@ public function __construct(
$this->propertyConverter = $propertyConverter;
}

public function offsetExists($offset): bool
public function has(string $propertyName): bool
{
return $this->serializedPropertyValues->propertyExists($offset);
return $this->serializedPropertyValues->propertyExists($propertyName);
}

public function offsetGet($offset): mixed
public function get(string $propertyName): mixed
{
if (!isset($this->deserializedPropertyValuesRuntimeCache[$offset])) {
$serializedProperty = $this->serializedPropertyValues->getProperty($offset);
if (!isset($this->deserializedPropertyValuesRuntimeCache[$propertyName])) {
$serializedProperty = $this->serializedPropertyValues->getProperty($propertyName);
if ($serializedProperty === null) {
return null;
}
$this->deserializedPropertyValuesRuntimeCache[$offset] =
$this->deserializedPropertyValuesRuntimeCache[$propertyName] =
$this->propertyConverter->deserializePropertyValue($serializedProperty);
}

return $this->deserializedPropertyValuesRuntimeCache[$offset];
}

public function offsetSet($offset, $value): never
{
throw new \RuntimeException("Do not use!");
}

public function offsetUnset($offset): never
{
throw new \RuntimeException("Do not use!");
return $this->deserializedPropertyValuesRuntimeCache[$propertyName];
}

/**
Expand All @@ -81,7 +73,7 @@ public function offsetUnset($offset): never
public function getIterator(): \Generator
{
foreach ($this->serializedPropertyValues as $propertyName => $_) {
yield $propertyName => $this->offsetGet($propertyName);
yield $propertyName => $this->get($propertyName);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Reference
public function __construct(
public readonly Node $node,
public readonly ReferenceName $name,
public readonly ?PropertyCollectionInterface $properties
public readonly ?PropertyCollection $properties
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,6 @@ public function propertiesCanBeIterated(): void
self::assertSame(['someProperty' => 'some deserialized value'], iterator_to_array($collection));
}

/**
* @test
*/
public function offsetSetThrowsAnException(): void
{
$collection = new PropertyCollection(SerializedPropertyValues::fromArray([]), $this->mockPropertyConverter);
$this->expectException(\RuntimeException::class);
$collection->offsetSet('foo', 'bar');
}

/**
* @test
*/
public function offsetUnsetThrowsAnException(): void
{
$collection = new PropertyCollection(SerializedPropertyValues::fromArray([]), $this->mockPropertyConverter);
$this->expectException(\RuntimeException::class);
$collection->offsetUnset('foo');
}

/**
* @test
*/
Expand All @@ -109,5 +89,4 @@ public function serializedReturnsSerializedPropertyValues(): void
$collection = new PropertyCollection($serializedPropertyValues, $this->mockPropertyConverter);
self::assertSame($serializedPropertyValues, $collection->serialized());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\ContentRepository\NodeMigration\Filter;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;

/**
* Filter nodes having the given property and its value not empty.
Expand Down Expand Up @@ -45,7 +44,6 @@ public function matches(Node $node): bool
if (is_null($this->propertyName) || !$node->hasProperty($this->propertyName)) {
return false;
}
/** @var PropertyCollectionInterface $properties */
$properties = $node->properties;
$serializedPropertyValue = $properties->serialized()->getProperty($this->propertyName);
if (!$serializedPropertyValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
use Neos\ContentRepository\Core\CommandHandler\CommandResult;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetSerializedNodeProperties;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValue;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

/**
* Change the value of a given property.
Expand Down Expand Up @@ -107,7 +105,6 @@ public function execute(
ContentStreamId $contentStreamForWriting
): ?CommandResult {
if ($node->hasProperty($this->propertyName)) {
/** @var PropertyCollectionInterface $properties */
$properties = $node->properties;
$currentProperty = $properties->serialized()->getProperty($this->propertyName);
/** @var \Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValue $currentProperty safe since Node::hasProperty */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
use Neos\ContentRepository\Core\CommandHandler\CommandResult;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetSerializedNodeProperties;
use Neos\ContentRepository\Core\Feature\NodeAggregateCommandHandler;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

/**
* Remove the property
Expand Down Expand Up @@ -64,7 +61,6 @@ public function execute(
): ?CommandResult
{
if ($node->hasProperty($this->from)) {
/** @var PropertyCollectionInterface $properties */
$properties = $node->properties;
return $this->contentRepository->handle(
new SetSerializedNodeProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
use Neos\ContentRepository\Core\CommandHandler\CommandResult;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetSerializedNodeProperties;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValue;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

/**
* Strip all tags on a given property
Expand Down Expand Up @@ -56,10 +54,9 @@ public function execute(
ContentStreamId $contentStreamForWriting
): ?CommandResult {
if ($node->hasProperty($this->propertyName)) {
/** @var PropertyCollectionInterface $properties */
$properties = $node->properties;
/** @var \Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValue $serializedPropertyValue safe since Node::hasProperty */
$serializedPropertyValue = $properties->serialized()->getProperty($this->propertyName);
assert($serializedPropertyValue !== null); // safe since Node::hasProperty
$propertyValue = $serializedPropertyValue->value;
if (!is_string($propertyValue)) {
throw new \Exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollectionInterface;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValue;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\EventStore\Model\EventStream\ExpectedVersion;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\EventStore\Model\EventStream\ExpectedVersion;

class PropertyAdjustment
{
Expand Down Expand Up @@ -44,7 +42,6 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat
foreach ($nodeAggregate->getNodes() as $node) {
$propertyKeysInNode = [];

/** @var PropertyCollectionInterface $properties */
$properties = $node->properties;
foreach ($properties->serialized() as $propertyKey => $property) {
$propertyKeysInNode[$propertyKey] = $propertyKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ public function iExpectThisNodeToHaveTheFollowingProperties(TableNode $expectedP
$this->assertOnCurrentNode(function (Node $currentNode) use ($expectedProperties) {
$properties = $currentNode->properties;
foreach ($expectedProperties->getHash() as $row) {
Assert::assertTrue($properties->offsetExists($row['Key']), 'Property "' . $row['Key'] . '" not found');
Assert::assertTrue($properties->has($row['Key']), 'Property "' . $row['Key'] . '" not found');
$expectedPropertyValue = $this->resolvePropertyValue($row['Value']);
$actualPropertyValue = $properties->offsetGet($row['Key']);
$actualPropertyValue = $properties->get($row['Key']);
if ($row['Value'] === 'Date:now') {
// we accept 10s offset for the projector to be fine
Assert::assertLessThan($actualPropertyValue, $expectedPropertyValue->sub(new \DateInterval('PT10S')), 'Node property ' . $row['Key'] . ' does not match. Expected: ' . json_encode($expectedPropertyValue) . '; Actual: ' . json_encode($actualPropertyValue));
Expand Down Expand Up @@ -398,11 +398,11 @@ private function assertReferencesMatch(TableNode $expectedReferencesTable, Refer
} else {
foreach ($rawExpectedProperties as $propertyName => $rawExpectedPropertyValue) {
Assert::assertTrue(
$actualProperties->offsetExists($propertyName),
$actualProperties->has($propertyName),
'Reference property "' . $propertyName . '" not found.'
);
$expectedPropertyValue = $this->resolvePropertyValue($rawExpectedPropertyValue);
$actualPropertyValue = $actualProperties->offsetGet($propertyName);
$actualPropertyValue = $actualProperties->get($propertyName);
if ($rawExpectedPropertyValue === 'Date:now') {
// we accept 10s offset for the projector to be fine
Assert::assertLessThan(
Expand Down
Loading

0 comments on commit 17c989e

Please sign in to comment.