From 291cefd6f33bd9094e08c6f3bea0612a85559b30 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 17 May 2025 19:30:03 +0200 Subject: [PATCH 1/2] TASK: Satisfy phpstan 2.1 at level 8 --- Classes/Domain/NodeMetadataFactory.php | 6 +++--- Classes/Infrastructure/ComponentSerializer.php | 3 +++ Classes/Infrastructure/ComponentUnserializer.php | 2 +- Classes/Infrastructure/IsCollectionType.php | 4 ++++ Tests/Unit/Infrastructure/ComponentReconstitutionTest.php | 6 +----- Tests/Unit/Infrastructure/ComponentSerializerTest.php | 6 +----- Tests/Unit/Infrastructure/ComponentUnserializerTest.php | 6 +----- phpstan.neon | 3 +-- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Classes/Domain/NodeMetadataFactory.php b/Classes/Domain/NodeMetadataFactory.php index 53fab9b..471d839 100644 --- a/Classes/Domain/NodeMetadataFactory.php +++ b/Classes/Domain/NodeMetadataFactory.php @@ -21,13 +21,13 @@ final class NodeMetadataFactory extends ContentElementWrappingService protected NodeInfoHelper $nodeInfoHelper; /** - * @return array|null + * @return array */ public function getAugmenterAttributesForContentNode( Node $contentNode, ?RenderingEntryPoint $renderingEntryPoint = null, ?string $additionalClasses = null - ): ?array { + ): array { $contentRepository = $this->contentRepositoryRegistry->get($contentNode->contentRepositoryId); $renderingEntryPoint ??= RenderingEntryPoint::forContentRendererDelegation(); @@ -60,7 +60,7 @@ public function getScriptForContentNode(Node $contentNode): string /** * @return array */ - public function forDocumentNode(Node $documentNode, ?string $locator = null, ?Node $siteNode = null): ?array + public function forDocumentNode(Node $documentNode, ?string $locator = null, ?Node $siteNode = null): array { $locator = is_string($locator) ? $locator : '//' . $documentNode->aggregateId->value; diff --git a/Classes/Infrastructure/ComponentSerializer.php b/Classes/Infrastructure/ComponentSerializer.php index fabd138..4458f23 100755 --- a/Classes/Infrastructure/ComponentSerializer.php +++ b/Classes/Infrastructure/ComponentSerializer.php @@ -28,6 +28,7 @@ public static function serializeComponent(ComponentInterface $component): array { $reflectionClass = new \ReflectionClass($component); if ($component instanceof ComponentCollection) { + /** @var \ReflectionClass $reflectionClass */ return self::serializeComponentCollection($component, $reflectionClass); } elseif ($component instanceof CacheSegment) { return $component->serializeForCache(); @@ -70,6 +71,7 @@ public static function serializeComponent(ComponentInterface $component): array } /** + * @param \ReflectionClass $reflectionClass * @return array */ private static function serializeComponentCollection( @@ -90,6 +92,7 @@ private static function serializeComponentCollection( } /** + * @param \ReflectionClass $reflectionClass * @return array */ private static function serializeCollectionType( diff --git a/Classes/Infrastructure/ComponentUnserializer.php b/Classes/Infrastructure/ComponentUnserializer.php index b4b6dd0..5e5c550 100755 --- a/Classes/Infrastructure/ComponentUnserializer.php +++ b/Classes/Infrastructure/ComponentUnserializer.php @@ -47,7 +47,7 @@ public function unserializeComponent( if (!is_string($className)) { throw new \InvalidArgumentException('Class identifiers must be strings', 1659564301); } - /** @var class-string $className */ + /** @var class-string $className */ if (!in_array(ComponentInterface::class, class_implements($className) ?: [])) { throw new \InvalidArgumentException( 'Can only unserialize objects of type ' . ComponentInterface::class . ', ' . $className . ' given', diff --git a/Classes/Infrastructure/IsCollectionType.php b/Classes/Infrastructure/IsCollectionType.php index 26041b2..8d3c3bb 100644 --- a/Classes/Infrastructure/IsCollectionType.php +++ b/Classes/Infrastructure/IsCollectionType.php @@ -9,6 +9,7 @@ namespace Nezaniel\ComponentView\Infrastructure; use Neos\Flow\Annotations as Flow; +use Nezaniel\ComponentView\Domain\ComponentInterface; /** * The specification to determine whether a component class is a collection type @@ -16,6 +17,9 @@ #[Flow\Proxy(false)] final class IsCollectionType { + /** + * @param \ReflectionClass $reflectionClass + */ public static function isSatisfiedByReflectionClass(\ReflectionClass $reflectionClass): bool { $reflectionProperties = $reflectionClass->getProperties(); diff --git a/Tests/Unit/Infrastructure/ComponentReconstitutionTest.php b/Tests/Unit/Infrastructure/ComponentReconstitutionTest.php index ccf1212..d0c7131 100644 --- a/Tests/Unit/Infrastructure/ComponentReconstitutionTest.php +++ b/Tests/Unit/Infrastructure/ComponentReconstitutionTest.php @@ -59,12 +59,8 @@ final class ComponentReconstitutionTest extends TestCase private ComponentCache $cache; - /** - * @param array $data - */ - public function __construct(?string $name = null, array $data = [], $dataName = '') + public function setUp(): void { - parent::__construct($name, $data, $dataName); $this->unserializer = new ComponentUnserializer(); $this->subgraph = new TestingSubgraph(); $this->dummyNode = Node::create( diff --git a/Tests/Unit/Infrastructure/ComponentSerializerTest.php b/Tests/Unit/Infrastructure/ComponentSerializerTest.php index fa669ab..e0e01a0 100644 --- a/Tests/Unit/Infrastructure/ComponentSerializerTest.php +++ b/Tests/Unit/Infrastructure/ComponentSerializerTest.php @@ -32,12 +32,8 @@ final class ComponentSerializerTest extends TestCase { private ComponentSerializer $subject; - /** - * @param array $data - */ - public function __construct(?string $name = null, array $data = [], $dataName = '') + public function setUp(): void { - parent::__construct($name, $data, $dataName); $this->subject = new ComponentSerializer(); } diff --git a/Tests/Unit/Infrastructure/ComponentUnserializerTest.php b/Tests/Unit/Infrastructure/ComponentUnserializerTest.php index 0dd0263..042cdde 100644 --- a/Tests/Unit/Infrastructure/ComponentUnserializerTest.php +++ b/Tests/Unit/Infrastructure/ComponentUnserializerTest.php @@ -58,12 +58,8 @@ final class ComponentUnserializerTest extends TestCase private ComponentCache $cache; - /** - * @param array $data - */ - public function __construct(?string $name = null, array $data = [], $dataName = '') + public function setUp(): void { - parent::__construct($name, $data, $dataName); $this->subject = new ComponentUnserializer(); $this->subgraph = new TestingSubgraph(); $this->dummyNode = Node::create( diff --git a/phpstan.neon b/phpstan.neon index 1ed3407..c4586d1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,5 @@ parameters: - level: 9 + level: 8 paths: - Classes - Tests - checkGenericClassInNonGenericObjectType: false From e1710d12f31c82139bd404cd90fd3bd6c4c59615 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 17 May 2025 19:47:01 +0200 Subject: [PATCH 2/2] TASK: Raise to phpstan level 9 and guard making non string node property editable --- Classes/Application/AbstractComponentFactory.php | 6 +++++- phpstan.neon | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Classes/Application/AbstractComponentFactory.php b/Classes/Application/AbstractComponentFactory.php index d920ed2..0d59dc1 100644 --- a/Classes/Application/AbstractComponentFactory.php +++ b/Classes/Application/AbstractComponentFactory.php @@ -35,11 +35,15 @@ abstract class AbstractComponentFactory final protected function getEditableProperty(Node $node, string $propertyName, bool $block = false): string { + $value = $node->getProperty($propertyName); + if ($value !== null && !is_string($value)) { + throw new \InvalidArgumentException(sprintf('Cannot make non-string node property "%s" of type "%s" editable.', $propertyName, get_debug_type($value))); + } return $this->contentElementEditableService->wrapContentProperty( $node, $propertyName, ($block ? '
' : '') - . ($node->getProperty($propertyName) ?: '') + . ($value ?? '') . ($block ? '
' : '') ); } diff --git a/phpstan.neon b/phpstan.neon index c4586d1..dbfeae0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 8 + level: 9 paths: - Classes - Tests