Skip to content

Commit e197add

Browse files
committed
improved phpDoc
1 parent 0125dee commit e197add

21 files changed

Lines changed: 298 additions & 230 deletions

src/HtmlStringable.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
namespace Nette;
1111

1212

13+
/**
14+
* Represents object convertible to HTML string.
15+
*/
1316
interface HtmlStringable
1417
{
1518
/**
16-
* Returns string in HTML format
19+
* Returns string in HTML format.
1720
*/
1821
function __toString(): string;
1922
}

src/Iterators/CachingIterator.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313

1414

1515
/**
16-
* Smarter caching iterator.
16+
* Enhanced caching iterator with first/last/counter tracking.
1717
*
18+
* @template TKey
19+
* @template TValue
20+
* @extends \CachingIterator<TKey, TValue, \Iterator<TKey, TValue>>
1821
* @property-read bool $first
1922
* @property-read bool $last
2023
* @property-read bool $empty
2124
* @property-read bool $odd
2225
* @property-read bool $even
2326
* @property-read int $counter
24-
* @property-read mixed $nextKey
25-
* @property-read mixed $nextValue
27+
* @property-read TKey $nextKey
28+
* @property-read TValue $nextValue
2629
*/
2730
class CachingIterator extends \CachingIterator implements \Countable
2831
{
@@ -31,6 +34,7 @@ class CachingIterator extends \CachingIterator implements \Countable
3134
private int $counter = 0;
3235

3336

37+
/** @param iterable<TKey, TValue>|\stdClass $iterable */
3438
public function __construct(iterable|\stdClass $iterable)
3539
{
3640
$iterable = $iterable instanceof \stdClass
@@ -58,45 +62,30 @@ public function isLast(?int $gridWidth = null): bool
5862
}
5963

6064

61-
/**
62-
* Is the iterator empty?
63-
*/
6465
public function isEmpty(): bool
6566
{
6667
return $this->counter === 0;
6768
}
6869

6970

70-
/**
71-
* Is the counter odd?
72-
*/
7371
public function isOdd(): bool
7472
{
7573
return $this->counter % 2 === 1;
7674
}
7775

7876

79-
/**
80-
* Is the counter even?
81-
*/
8277
public function isEven(): bool
8378
{
8479
return $this->counter % 2 === 0;
8580
}
8681

8782

88-
/**
89-
* Returns the counter.
90-
*/
9183
public function getCounter(): int
9284
{
9385
return $this->counter;
9486
}
9587

9688

97-
/**
98-
* Returns the count of elements.
99-
*/
10089
public function count(): int
10190
{
10291
$inner = $this->getInnerIterator();
@@ -131,18 +120,14 @@ public function rewind(): void
131120
}
132121

133122

134-
/**
135-
* Returns the next key.
136-
*/
123+
/** @return TKey */
137124
public function getNextKey(): mixed
138125
{
139126
return $this->getInnerIterator()->key();
140127
}
141128

142129

143-
/**
144-
* Returns the next element.
145-
*/
130+
/** @return TValue */
146131
public function getNextValue(): mixed
147132
{
148133
return $this->getInnerIterator()->current();

src/SmartObject.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
trait SmartObject
2323
{
2424
/**
25+
* @param mixed[] $args
2526
* @return mixed
2627
* @throws MemberAccessException
2728
*/
@@ -47,6 +48,8 @@ public function __call(string $name, array $args)
4748

4849

4950
/**
51+
* @param mixed[] $args
52+
* @return never
5053
* @throws MemberAccessException
5154
*/
5255
public static function __callStatic(string $name, array $args)

src/StaticClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
/**
14-
* Static class.
14+
* Prevents instantiation.
1515
*/
1616
trait StaticClass
1717
{

src/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
/**
14-
* Translator adapter.
14+
* Translation provider.
1515
*/
1616
interface Translator
1717
{

src/Utils/ArrayHash.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
/**
17-
* Provides objects to work as array.
17+
* Array-like object with property access.
1818
* @template T
1919
* @implements \IteratorAggregate<array-key, T>
2020
* @implements \ArrayAccess<array-key, T>
@@ -39,7 +39,6 @@ public static function from(array $array, bool $recursive = true): static
3939

4040

4141
/**
42-
* Returns an iterator over all items.
4342
* @return \Iterator<array-key, T>
4443
*/
4544
public function &getIterator(): \Iterator
@@ -50,9 +49,6 @@ public function &getIterator(): \Iterator
5049
}
5150

5251

53-
/**
54-
* Returns items count.
55-
*/
5652
public function count(): int
5753
{
5854
return count((array) $this);

src/Utils/ArrayList.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414

1515

1616
/**
17-
* Provides the base class for a generic list (items can be accessed by index).
17+
* Generic list with integer indices.
1818
* @template T
1919
* @implements \IteratorAggregate<int, T>
2020
* @implements \ArrayAccess<int, T>
2121
*/
2222
class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
2323
{
24+
/** @var list<T> */
2425
private array $list = [];
2526

2627

@@ -41,7 +42,6 @@ public static function from(array $array): static
4142

4243

4344
/**
44-
* Returns an iterator over all items.
4545
* @return \Iterator<int, T>
4646
*/
4747
public function &getIterator(): \Iterator
@@ -52,9 +52,6 @@ public function &getIterator(): \Iterator
5252
}
5353

5454

55-
/**
56-
* Returns items count.
57-
*/
5855
public function count(): int
5956
{
6057
return count($this->list);
@@ -63,7 +60,7 @@ public function count(): int
6360

6461
/**
6562
* Replaces or appends an item.
66-
* @param int|null $index
63+
* @param ?int $index
6764
* @param T $value
6865
* @throws Nette\OutOfRangeException
6966
*/

src/Utils/Arrays.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function &getRef(array &$array, string|int|array $key): mixed
7979
* @template T2
8080
* @param array<T1> $array1
8181
* @param array<T2> $array2
82-
* @return array<T1|T2>
82+
* @return array<T1|T2|array<mixed>>
8383
*/
8484
public static function mergeTree(array $array1, array $array2): array
8585
{
@@ -96,6 +96,7 @@ public static function mergeTree(array $array1, array $array2): array
9696

9797
/**
9898
* Returns zero-indexed position of given array key. Returns null if key is not found.
99+
* @param array<mixed> $array
99100
*/
100101
public static function getKeyOffset(array $array, string|int $key): ?int
101102
{
@@ -104,6 +105,7 @@ public static function getKeyOffset(array $array, string|int $key): ?int
104105

105106

106107
/**
108+
* @param array<mixed> $array
107109
* @deprecated use getKeyOffset()
108110
*/
109111
public static function searchKey(array $array, string|int $key): ?int
@@ -114,6 +116,7 @@ public static function searchKey(array $array, string|int $key): ?int
114116

115117
/**
116118
* Tests an array for the presence of value.
119+
* @param array<mixed> $array
117120
*/
118121
public static function contains(array $array, mixed $value): bool
119122
{
@@ -125,9 +128,11 @@ public static function contains(array $array, mixed $value): bool
125128
* Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
126129
* @template K of int|string
127130
* @template V
131+
* @template E
128132
* @param array<K, V> $array
129133
* @param ?callable(V, K, array<K, V>): bool $predicate
130-
* @return ?V
134+
* @param ?callable(): E $else
135+
* @return ($else is null ? ?V : V|E)
131136
*/
132137
public static function first(array $array, ?callable $predicate = null, ?callable $else = null): mixed
133138
{
@@ -142,9 +147,11 @@ public static function first(array $array, ?callable $predicate = null, ?callabl
142147
* Returns the last item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
143148
* @template K of int|string
144149
* @template V
150+
* @template E
145151
* @param array<K, V> $array
146152
* @param ?callable(V, K, array<K, V>): bool $predicate
147-
* @return ?V
153+
* @param ?callable(): E $else
154+
* @return ($else is null ? ?V : V|E)
148155
*/
149156
public static function last(array $array, ?callable $predicate = null, ?callable $else = null): mixed
150157
{
@@ -196,6 +203,8 @@ public static function lastKey(array $array, ?callable $predicate = null): int|s
196203
/**
197204
* Inserts the contents of the $inserted array into the $array immediately after the $key.
198205
* If $key is null (or does not exist), it is inserted at the beginning.
206+
* @param array<mixed> $array
207+
* @param array<mixed> $inserted
199208
*/
200209
public static function insertBefore(array &$array, string|int|null $key, array $inserted): void
201210
{
@@ -209,6 +218,8 @@ public static function insertBefore(array &$array, string|int|null $key, array $
209218
/**
210219
* Inserts the contents of the $inserted array into the $array before the $key.
211220
* If $key is null (or does not exist), it is inserted at the end.
221+
* @param array<mixed> $array
222+
* @param array<mixed> $inserted
212223
*/
213224
public static function insertAfter(array &$array, string|int|null $key, array $inserted): void
214225
{
@@ -224,6 +235,7 @@ public static function insertAfter(array &$array, string|int|null $key, array $i
224235

225236
/**
226237
* Renames key in array.
238+
* @param array<mixed> $array
227239
*/
228240
public static function renameKey(array &$array, string|int $oldKey, string|int $newKey): bool
229241
{
@@ -260,6 +272,8 @@ public static function grep(
260272

261273
/**
262274
* Transforms multidimensional array to flat array.
275+
* @param array<mixed> $array
276+
* @return array<mixed>
263277
*/
264278
public static function flatten(array $array, bool $preserveKeys = false): array
265279
{
@@ -284,7 +298,9 @@ public static function isList(mixed $value): bool
284298

285299
/**
286300
* Reformats table to associative tree. Path looks like 'field|field[]field->field=field'.
287-
* @param string|string[] $path
301+
* @param array<mixed> $array
302+
* @param string|list<string> $path
303+
* @return array<mixed>|\stdClass
288304
*/
289305
public static function associate(array $array, string|array $path): array|\stdClass
290306
{
@@ -338,6 +354,8 @@ public static function associate(array $array, string|array $path): array|\stdCl
338354

339355
/**
340356
* Normalizes array to associative array. Replace numeric keys with their values, the new value will be $filling.
357+
* @param array<mixed> $array
358+
* @return array<string, mixed>
341359
*/
342360
public static function normalize(array $array, mixed $filling = null): array
343361
{
@@ -481,6 +499,7 @@ public static function mapWithKeys(array $array, callable $transformer): array
481499
/**
482500
* Invokes all callbacks and returns array of results.
483501
* @param callable[] $callbacks
502+
* @return array<mixed>
484503
*/
485504
public static function invoke(iterable $callbacks, mixed ...$args): array
486505
{
@@ -496,6 +515,7 @@ public static function invoke(iterable $callbacks, mixed ...$args): array
496515
/**
497516
* Invokes method on every object in an array and returns array of results.
498517
* @param object[] $objects
518+
* @return array<mixed>
499519
*/
500520
public static function invokeMethod(iterable $objects, string $method, mixed ...$args): array
501521
{
@@ -511,6 +531,7 @@ public static function invokeMethod(iterable $objects, string $method, mixed ...
511531
/**
512532
* Copies the elements of the $array array to the $object object and then returns it.
513533
* @template T of object
534+
* @param iterable<mixed> $array
514535
* @param T $object
515536
* @return T
516537
*/

src/Utils/Callback.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ final class Callback
2222

2323
/**
2424
* Invokes internal PHP function with own error handler.
25+
* @param callable-string $function
26+
* @param list<mixed> $args
27+
* @param callable(string, int): (bool|void|null) $onError
2528
*/
2629
public static function invokeSafe(string $function, array $args, callable $onError): mixed
2730
{
@@ -116,6 +119,7 @@ public static function isStatic(callable $callable): bool
116119

117120
/**
118121
* Unwraps closure created by Closure::fromCallable().
122+
* @return callable|array{object|class-string, string}|string
119123
*/
120124
public static function unwrap(\Closure $closure): callable|array
121125
{

0 commit comments

Comments
 (0)