From 25fcc930bcdda7ea695200f1a9c35c81e91aa762 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Sep 2021 23:36:26 +0200 Subject: [PATCH] used generics in phpDoc [WIP] --- src/ComponentModel/ArrayAccess.php | 4 +++- src/ComponentModel/Component.php | 7 ++++++- src/ComponentModel/Container.php | 2 ++ src/ComponentModel/IComponent.php | 3 +++ src/ComponentModel/IContainer.php | 6 +++++- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ComponentModel/ArrayAccess.php b/src/ComponentModel/ArrayAccess.php index 1bded8c..d873320 100644 --- a/src/ComponentModel/ArrayAccess.php +++ b/src/ComponentModel/ArrayAccess.php @@ -14,13 +14,14 @@ /** * Implementation of \ArrayAccess for IContainer. + * @template T of IComponent */ trait ArrayAccess { /** * Adds the component to the container. * @param string|int $name - * @param IComponent $component + * @param T $component */ public function offsetSet($name, $component): void { @@ -32,6 +33,7 @@ public function offsetSet($name, $component): void /** * Returns component specified by name. Throws exception if component doesn't exist. * @param string|int $name + * @return T * @throws Nette\InvalidArgumentException */ public function offsetGet($name): IComponent diff --git a/src/ComponentModel/Component.php b/src/ComponentModel/Component.php index 523c8e2..962e71b 100644 --- a/src/ComponentModel/Component.php +++ b/src/ComponentModel/Component.php @@ -17,8 +17,10 @@ * * Components are objects implementing IComponent. They has parent component and own name. * + * @template T of IContainer + * @implements IComponent * @property-read string $name - * @property-read IContainer|null $parent + * @property-read T|null $parent */ abstract class Component implements IComponent { @@ -151,6 +153,7 @@ final public function getName(): ?string /** * Returns the parent container if any. + * @return T */ final public function getParent(): ?IContainer { @@ -161,6 +164,7 @@ final public function getParent(): ?IContainer /** * Sets or removes the parent of this component. This method is managed by containers and should * not be called by applications + * @param T $parent * @throws Nette\InvalidStateException * @internal */ @@ -202,6 +206,7 @@ public function setParent(?IContainer $parent, ?string $name = null): static /** * Is called by a component when it is about to be set new parent. Descendant can * override this method to disallow a parent change by throwing an Nette\InvalidStateException + * @param T $parent * @throws Nette\InvalidStateException */ protected function validateParent(IContainer $parent): void diff --git a/src/ComponentModel/Container.php b/src/ComponentModel/Container.php index cf7f65c..d09e567 100644 --- a/src/ComponentModel/Container.php +++ b/src/ComponentModel/Container.php @@ -15,6 +15,8 @@ /** * ComponentContainer is default implementation of IContainer. * + * @template T of IComponent + * @implements IContainer * @property-read iterable $components */ class Container extends Component implements IContainer diff --git a/src/ComponentModel/IComponent.php b/src/ComponentModel/IComponent.php index eb21c97..767f3c3 100644 --- a/src/ComponentModel/IComponent.php +++ b/src/ComponentModel/IComponent.php @@ -12,6 +12,7 @@ /** * Provides functionality required by all components. + * @template T of IContainer */ interface IComponent { @@ -25,11 +26,13 @@ function getName(): ?string; /** * Returns the parent container if any. + * @return ?T */ function getParent(): ?IContainer; /** * Sets the parent of this component. + * @param ?T $parent */ function setParent(?IContainer $parent, ?string $name = null): static; } diff --git a/src/ComponentModel/IContainer.php b/src/ComponentModel/IContainer.php index 9ed605f..e8c49ee 100644 --- a/src/ComponentModel/IContainer.php +++ b/src/ComponentModel/IContainer.php @@ -14,29 +14,33 @@ /** * Containers are objects that logically contain zero or more IComponent components. + * @template T of IComponent */ interface IContainer extends IComponent { /** * Adds the component to the container. + * @param T $component * @return static */ function addComponent(IComponent $component, ?string $name); /** * Removes the component from the container. + * @param T $component */ function removeComponent(IComponent $component): void; /** * Returns component specified by name or path. + * @return T * @throws Nette\InvalidArgumentException if component doesn't exist */ function getComponent(string $name): ?IComponent; /** * Iterates over descendants components. - * @return iterable + * @return iterable */ function getComponents(): iterable; }