Skip to content

Commit 21fdb05

Browse files
committed
improved phpDoc types
1 parent a9766ce commit 21fdb05

25 files changed

Lines changed: 90 additions & 62 deletions

src/PhpGenerator/ClassLike.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ abstract class ClassLike
3535
private ?string $name;
3636

3737

38+
/** @param class-string|object $class */
3839
public static function from(string|object $class, bool $withBodies = false): static
3940
{
4041
$instance = (new Factory)
@@ -143,7 +144,7 @@ public function isEnum(): bool
143144
}
144145

145146

146-
/** @param string[] $names */
147+
/** @param list<string> $names */
147148
protected function validateNames(array $names): void
148149
{
149150
foreach ($names as $name) {

src/PhpGenerator/ClassManipulator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function inheritMethod(string $name, bool $returnIfExists = false): Metho
7575

7676
/**
7777
* Implements all methods from the given interface or abstract class.
78+
* @param class-string $name
7879
*/
7980
public function implement(string $name): void
8081
{

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class ClassType extends ClassLike
3333
private ?string $extends = null;
3434
private bool $readOnly = false;
3535

36-
/** @var string[] */
36+
/** @var list<string> */
3737
private array $implements = [];
3838

3939

@@ -101,9 +101,7 @@ public function getExtends(): ?string
101101
}
102102

103103

104-
/**
105-
* @param string[] $names
106-
*/
104+
/** @param list<string> $names */
107105
public function setImplements(array $names): static
108106
{
109107
$this->validateNames($names);
@@ -112,7 +110,7 @@ public function setImplements(array $names): static
112110
}
113111

114112

115-
/** @return string[] */
113+
/** @return list<string> */
116114
public function getImplements(): array
117115
{
118116
return $this->implements;

src/PhpGenerator/Closure.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ final class Closure
1616
use Traits\FunctionLike;
1717
use Traits\AttributeAware;
1818

19-
/** @var Parameter[] */
19+
/** @var list<Parameter> */
2020
private array $uses = [];
2121

2222

23+
/** @param \Closure(): mixed $closure */
2324
public static function from(\Closure $closure): self
2425
{
2526
return (new Factory)->fromFunctionReflection(new \ReflectionFunction($closure));
@@ -34,7 +35,7 @@ public function __toString(): string
3435

3536
/**
3637
* Replaces all uses.
37-
* @param Parameter[] $uses
38+
* @param list<Parameter> $uses
3839
*/
3940
public function setUses(array $uses): static
4041
{
@@ -44,7 +45,7 @@ public function setUses(array $uses): static
4445
}
4546

4647

47-
/** @return Parameter[] */
48+
/** @return list<Parameter> */
4849
public function getUses(): array
4950
{
5051
return $this->uses;

src/PhpGenerator/Dumper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ private function dumpArguments(array $args, int $column, bool $named): string
271271

272272

273273
/**
274+
* @param class-string $class
274275
* @param mixed[] $props
275276
* @internal
276277
*/

src/PhpGenerator/EnumType.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class EnumType extends ClassLike
1919
use Traits\MethodsAware;
2020
use Traits\TraitsAware;
2121

22-
/** @var string[] */
22+
/** @var list<string> */
2323
private array $implements = [];
2424

2525
/** @var array<string, EnumCase> */
@@ -40,9 +40,7 @@ public function getType(): ?string
4040
}
4141

4242

43-
/**
44-
* @param string[] $names
45-
*/
43+
/** @param list<string> $names */
4644
public function setImplements(array $names): static
4745
{
4846
$this->validateNames($names);
@@ -51,7 +49,7 @@ public function setImplements(array $names): static
5149
}
5250

5351

54-
/** @return string[] */
52+
/** @return list<string> */
5553
public function getImplements(): array
5654
{
5755
return $this->implements;
@@ -75,7 +73,7 @@ public function removeImplement(string $name): static
7573

7674
/**
7775
* Sets cases to enum
78-
* @param EnumCase[] $cases
76+
* @param list<EnumCase> $cases
7977
*/
8078
public function setCases(array $cases): static
8179
{
@@ -89,7 +87,7 @@ public function setCases(array $cases): static
8987
}
9088

9189

92-
/** @return EnumCase[] */
90+
/** @return array<string, EnumCase> */
9391
public function getCases(): array
9492
{
9593
return $this->cases;

src/PhpGenerator/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Extractor
2424
{
2525
private string $code;
2626

27-
/** @var Node[] */
27+
/** @var array<Node> */
2828
private array $statements;
2929
private PhpParser\PrettyPrinterAbstract $printer;
3030

src/PhpGenerator/Factory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
final class Factory
2020
{
21-
/** @var string[][] */
21+
/** @var array<string, array<string, string>> */
2222
private array $bodyCache = [];
2323

24-
/** @var Extractor[] */
24+
/** @var array<string, Extractor> */
2525
private array $extractorCache = [];
2626

2727

@@ -220,6 +220,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
220220
}
221221

222222

223+
/** @param callable(): mixed $from */
223224
public function fromCallable(callable $from): Method|GlobalFunction|Closure
224225
{
225226
$ref = Nette\Utils\Callback::toReflection($from);
@@ -366,7 +367,10 @@ public function fromCode(string $code): PhpFile
366367
}
367368

368369

369-
/** @return Attribute[] */
370+
/**
371+
* @param list<\ReflectionAttribute<object>> $attrs
372+
* @return list<Attribute>
373+
*/
370374
private function formatAttributes(array $attrs): array
371375
{
372376
$res = [];

src/PhpGenerator/GlobalFunction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class GlobalFunction
2020
use Traits\CommentAware;
2121
use Traits\AttributeAware;
2222

23+
/** @param string|(\Closure(): mixed) $function */
2324
public static function from(string|\Closure $function, bool $withBody = false): self
2425
{
2526
return (new Factory)->fromFunctionReflection(Nette\Utils\Callback::toReflection($function), $withBody);

src/PhpGenerator/Helpers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static function formatDocComment(string $content, bool $forceMultiLine =
6060
}
6161

6262

63+
/** @param PhpNamespace::Name* $of */
6364
public static function tagName(string $name, string $of = PhpNamespace::NameNormal): string
6465
{
6566
return isset(self::Keywords[strtolower($name)])
@@ -127,6 +128,7 @@ public static function tabsToSpaces(string $s, int $count = 4): string
127128

128129

129130
/**
131+
* @param class-string $class
130132
* @param mixed[] $props
131133
* @internal
132134
*/

0 commit comments

Comments
 (0)