Skip to content

Commit 2958223

Browse files
committed
used generics in phpDoc [WIP]
1 parent 297cc6d commit 2958223

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
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
{
@@ -150,6 +152,7 @@ final public function getName(): ?string
150152

151153
/**
152154
* Returns the parent container if any.
155+
* @return T
153156
*/
154157
final public function getParent(): ?IContainer
155158
{
@@ -160,6 +163,7 @@ final public function getParent(): ?IContainer
160163
/**
161164
* Sets or removes the parent of this component. This method is managed by containers and should
162165
* not be called by applications
166+
* @param T $parent
163167
* @throws Nette\InvalidStateException
164168
* @internal
165169
*/
@@ -201,6 +205,7 @@ public function setParent(?IContainer $parent, ?string $name = null): static
201205
/**
202206
* Validates the new parent before it's set.
203207
* Descendant classes can override this to implement custom validation logic.
208+
* @param T $parent
204209
* @throws Nette\InvalidStateException
205210
*/
206211
protected function validateParent(IContainer $parent): void

src/ComponentModel/Container.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
/**
1717
* Manages a collection of child components.
1818
*
19-
* @property-read IComponent[] $components
19+
* @template T of IComponent
20+
* @implements IContainer<T>
21+
* @property-read T[] $components
2022
*/
2123
class Container extends Component implements IContainer
2224
{

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,29 +14,33 @@
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
* @return static
2325
*/
2426
function addComponent(IComponent $component, ?string $name);
2527

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

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

3741
/**
3842
* Returns immediate child components.
39-
* @return array<int|string,IComponent>
43+
* @return array<int|string,T>
4044
*/
4145
function getComponents(): iterable;
4246
}

0 commit comments

Comments
 (0)