Skip to content

Commit 0614c98

Browse files
committed
used generics in phpDoc [WIP]
1 parent 48baaad commit 0614c98

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

src/ComponentModel/ArrayAccess.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

1616
/**
1717
* Implementation of \ArrayAccess for IContainer.
18+
* @template T of IComponent
1819
*/
1920
trait ArrayAccess
2021
{
2122
/**
2223
* Adds the component to the container.
2324
* @param string|int $name
24-
* @param IComponent $component
25+
* @param T $component
2526
*/
2627
public function offsetSet($name, $component): void
2728
{
@@ -33,6 +34,7 @@ public function offsetSet($name, $component): void
3334
/**
3435
* Returns component specified by name. Throws exception if component doesn't exist.
3536
* @param string|int $name
37+
* @return T
3638
* @throws Nette\InvalidArgumentException
3739
*/
3840
public function offsetGet($name): IComponent

src/ComponentModel/Component.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
/**
1717
* Base class for all components. Components have a parent, name, and can be monitored by ancestors.
1818
*
19+
* @template T of IContainer
20+
* @implements IComponent<T>
1921
* @property-read string $name
20-
* @property-read IContainer|null $parent
22+
* @property-read T|null $parent
2123
*/
2224
abstract class Component implements IComponent
2325
{
@@ -128,6 +130,7 @@ final public function getName(): ?string
128130

129131
/**
130132
* Returns the parent container if any.
133+
* @return T
131134
*/
132135
final public function getParent(): ?IContainer
133136
{
@@ -138,6 +141,7 @@ final public function getParent(): ?IContainer
138141
/**
139142
* Sets or removes the parent of this component. This method is managed by containers and should
140143
* not be called by applications
144+
* @param T $parent
141145
* @throws Nette\InvalidStateException
142146
* @internal
143147
*/
@@ -179,6 +183,7 @@ public function setParent(?IContainer $parent, ?string $name = null): static
179183
/**
180184
* Validates the new parent before it's set.
181185
* Descendant classes can override this to implement custom validation logic.
186+
* @param T $parent
182187
* @throws Nette\InvalidStateException
183188
*/
184189
protected function validateParent(IContainer $parent): void

src/ComponentModel/Container.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
/**
1717
* Manages a collection of child components.
18+
*
19+
* @template T of IComponent
20+
* @implements IContainer<T>
1821
*/
1922
class Container extends Component implements IContainer
2023
{

src/ComponentModel/IComponent.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* Defines core functionality required by all components.
15+
* @template T of IContainer
1516
*/
1617
interface IComponent
1718
{
@@ -25,11 +26,13 @@ function getName(): ?string;
2526

2627
/**
2728
* Returns the parent container if any.
29+
* @return ?T
2830
*/
2931
function getParent(): ?IContainer;
3032

3133
/**
3234
* Sets the parent container and optionally renames the component.
35+
* @param ?T $parent
3336
*/
3437
function setParent(?IContainer $parent, ?string $name = null): static;
3538
}

src/ComponentModel/IContainer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@
1414

1515
/**
1616
* Defines functionality for objects that can contain other components.
17+
* @template T of IComponent
1718
*/
1819
interface IContainer extends IComponent
1920
{
2021
/**
2122
* Adds the component to the container.
23+
* @param T $component
2224
*/
2325
function addComponent(IComponent $component, ?string $name): static;
2426

2527
/**
2628
* Removes the component from the container.
29+
* @param T $component
2730
*/
2831
function removeComponent(IComponent $component): void;
2932

3033
/**
3134
* Returns component specified by name or path.
35+
* @return T
3236
* @throws Nette\InvalidArgumentException if component doesn't exist
3337
*/
3438
function getComponent(string $name): ?IComponent;
3539

3640
/**
3741
* Returns immediate child components.
38-
* @return array<int|string,IComponent>
42+
* @return array<int|string,T>
3943
*/
4044
function getComponents(): iterable;
4145
}

0 commit comments

Comments
 (0)