Skip to content

Commit ccb19b3

Browse files
committed
used generics in phpDoc [WIP]
1 parent 20b94c3 commit ccb19b3

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
@@ -14,13 +14,14 @@
1414

1515
/**
1616
* Implementation of \ArrayAccess for IContainer.
17+
* @template T of IComponent
1718
*/
1819
trait ArrayAccess
1920
{
2021
/**
2122
* Adds the component to the container.
2223
* @param string|int $name
23-
* @param IComponent $component
24+
* @param T $component
2425
*/
2526
public function offsetSet($name, $component): void
2627
{
@@ -32,6 +33,7 @@ public function offsetSet($name, $component): void
3233
/**
3334
* Returns component specified by name. Throws exception if component doesn't exist.
3435
* @param string|int $name
36+
* @return T
3537
* @throws Nette\InvalidArgumentException
3638
*/
3739
public function offsetGet($name): IComponent

src/ComponentModel/Component.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
/**
1616
* Base class for all components. Components have a parent, name, and can be monitored by ancestors.
1717
*
18+
* @template T of IContainer
19+
* @implements IComponent<T>
1820
* @property-read string $name
19-
* @property-read IContainer|null $parent
21+
* @property-read T|null $parent
2022
*/
2123
abstract class Component implements IComponent
2224
{
@@ -149,6 +151,7 @@ final public function getName(): ?string
149151

150152
/**
151153
* Returns the parent container if any.
154+
* @return T
152155
*/
153156
final public function getParent(): ?IContainer
154157
{
@@ -159,6 +162,7 @@ final public function getParent(): ?IContainer
159162
/**
160163
* Sets or removes the parent of this component. This method is managed by containers and should
161164
* not be called by applications
165+
* @param T $parent
162166
* @throws Nette\InvalidStateException
163167
* @internal
164168
*/
@@ -200,6 +204,7 @@ public function setParent(?IContainer $parent, ?string $name = null): static
200204
/**
201205
* Validates the new parent before it's set.
202206
* Descendant classes can override this to implement custom validation logic.
207+
* @param T $parent
203208
* @throws Nette\InvalidStateException
204209
*/
205210
protected function validateParent(IContainer $parent): void

src/ComponentModel/Container.php

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

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)