Skip to content

Commit 59df327

Browse files
committed
improved phpDoc
1 parent 61433ce commit 59df327

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/ComponentModel/Component.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Base class for all components. Components have a parent, name, and can be monitored by ancestors.
1818
*
1919
* @property-read string $name
20-
* @property-read IContainer|null $parent
20+
* @property-read ?IContainer $parent
2121
*/
2222
abstract class Component implements IComponent
2323
{
@@ -31,7 +31,7 @@ abstract class Component implements IComponent
3131
* Combines cached lookup results with callback registrations for each monitored type.
3232
* Depth is used to detect when monitored ancestor becomes unreachable during detachment.
3333
* Structure: [type => [found object, depth to object, path to object, [[attached, ...], [detached, ...]]]]
34-
* @var array<string, array{?IComponent, ?int, ?string, array<int, ?array{\Closure[], \Closure[]}>}>
34+
* @var array<''|class-string<Nette\ComponentModel\IComponent>, array{?IComponent, ?int, ?string, ?array{list<\Closure(IComponent): void>, list<\Closure(IComponent): void>}}>
3535
*/
3636
private array $monitors = [];
3737

@@ -41,8 +41,10 @@ abstract class Component implements IComponent
4141

4242
/**
4343
* Finds the closest ancestor of specified type.
44-
* @param bool $throw throw exception if component doesn't exist?
45-
* @return ($throw is true ? IComponent : ?IComponent)
44+
* @template T of IComponent
45+
* @param ?class-string<T> $type
46+
* @param bool $throw throw exception if component doesn't exist?
47+
* @return ($type is null ? ($throw is true ? IComponent : ?IComponent) : ($throw is true ? T : ?T))
4648
*/
4749
final public function lookup(?string $type, bool $throw = true): ?IComponent
4850
{
@@ -81,7 +83,9 @@ final public function lookup(?string $type, bool $throw = true): ?IComponent
8183

8284
/**
8385
* Finds the closest ancestor specified by class or interface name and returns backtrace path.
84-
* A path is the concatenation of component names separated by self::NAME_SEPARATOR.
86+
* A path is the concatenation of component names separated by self::NameSeparator.
87+
* @param ?class-string<IComponent> $type
88+
* @param bool $throw throw exception if component doesn't exist?
8589
* @return ($throw is true ? string : ?string)
8690
*/
8791
final public function lookupPath(?string $type = null, bool $throw = true): ?string
@@ -93,6 +97,10 @@ final public function lookupPath(?string $type = null, bool $throw = true): ?str
9397

9498
/**
9599
* Starts monitoring ancestors for attach/detach events.
100+
* @template T of IComponent
101+
* @param class-string<T> $type
102+
* @param ?(callable(T): void) $attached called when attached to a monitored ancestor
103+
* @param ?(callable(T): void) $detached called before detaching from a monitored ancestor
96104
*/
97105
final public function monitor(string $type, ?callable $attached = null, ?callable $detached = null): void
98106
{
@@ -119,6 +127,7 @@ final public function monitor(string $type, ?callable $attached = null, ?callabl
119127

120128
/**
121129
* Stops monitoring ancestors of specified type.
130+
* @param class-string<IComponent> $type
122131
*/
123132
final public function unmonitor(string $type): void
124133
{
@@ -218,7 +227,7 @@ protected function validateParent(IContainer $parent): void
218227
/**
219228
* Refreshes monitors when attaching/detaching from component tree.
220229
* @param ?array<string, true> $missing null = detaching, array = attaching
221-
* @param array<int, array{\Closure, IComponent}> $listeners
230+
* @param array<int, array{\Closure(IComponent): void, IComponent}> $listeners
222231
*/
223232
private function refreshMonitors(int $depth, ?array &$missing = null, array &$listeners = []): void
224233
{

src/ComponentModel/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function createComponent(string $name): ?IComponent
175175

176176
/**
177177
* Returns all immediate child components.
178-
* @return array<int|string,IComponent>
178+
* @return array<int|string, IComponent>
179179
*/
180180
final public function getComponents(): iterable
181181
{

src/ComponentModel/IContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getComponent(string $name): ?IComponent;
3636

3737
/**
3838
* Returns immediate child components.
39-
* @return array<int|string,IComponent>
39+
* @return array<int|string, IComponent>
4040
*/
4141
function getComponents(): iterable;
4242
}

src/ComponentModel/RecursiveComponentIterator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/**
1616
* Recursive component iterator. See Container::getComponents().
1717
* @internal
18+
* @extends \RecursiveArrayIterator<int|string, IComponent>
1819
*/
1920
final class RecursiveComponentIterator extends \RecursiveArrayIterator implements \Countable
2021
{

0 commit comments

Comments
 (0)