Skip to content

Commit bfd55f4

Browse files
committed
improved phpDoc types
1 parent a7d81a7 commit bfd55f4

11 files changed

Lines changed: 44 additions & 15 deletions

File tree

src/PhpGenerator/Closure.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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

@@ -35,7 +35,7 @@ public function __toString(): string
3535

3636
/**
3737
* Replaces all uses.
38-
* @param Parameter[] $uses
38+
* @param list<Parameter> $uses
3939
*/
4040
public function setUses(array $uses): static
4141
{
@@ -45,7 +45,7 @@ public function setUses(array $uses): static
4545
}
4646

4747

48-
/** @return Parameter[] */
48+
/** @return list<Parameter> */
4949
public function getUses(): array
5050
{
5151
return $this->uses;

src/PhpGenerator/EnumType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function removeImplement(string $name): static
7373

7474
/**
7575
* Sets cases to enum
76-
* @param EnumCase[] $cases
76+
* @param list<EnumCase> $cases
7777
*/
7878
public function setCases(array $cases): static
7979
{
@@ -87,7 +87,7 @@ public function setCases(array $cases): static
8787
}
8888

8989

90-
/** @return EnumCase[] */
90+
/** @return array<string, EnumCase> */
9191
public function getCases(): array
9292
{
9393
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 list<Node> */
27+
/** @var array<Node> */
2828
private array $statements;
2929
private PhpParser\PrettyPrinterAbstract $printer;
3030

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
*/

src/PhpGenerator/PhpFile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public function getFunctions(): array
182182

183183
/**
184184
* Adds a use statement to the file, to the global namespace.
185+
* @param PhpNamespace::Name* $of
185186
*/
186187
public function addUse(string $name, ?string $alias = null, string $of = PhpNamespace::NameNormal): static
187188
{

src/PhpGenerator/PhpNamespace.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class PhpNamespace
4141

4242
private bool $bracketedSyntax = false;
4343

44-
/** @var string[][] */
44+
/** @var array<string, array<string, string>> */
4545
private array $aliases = [
4646
self::NameNormal => [],
4747
self::NameFunction => [],
@@ -89,6 +89,7 @@ public function hasBracketedSyntax(): bool
8989

9090
/**
9191
* Adds a use statement to the namespace for class, function or constant.
92+
* @param self::Name* $of
9293
* @throws InvalidStateException
9394
*/
9495
public function addUse(string $name, ?string $alias = null, string $of = self::NameNormal): static
@@ -131,6 +132,7 @@ public function addUse(string $name, ?string $alias = null, string $of = self::N
131132
}
132133

133134

135+
/** @param self::Name* $of */
134136
public function removeUse(string $name, string $of = self::NameNormal): void
135137
{
136138
foreach ($this->aliases[$of] as $alias => $item) {
@@ -159,7 +161,10 @@ public function addUseConstant(string $name, ?string $alias = null): static
159161
}
160162

161163

162-
/** @return array<string, string> */
164+
/**
165+
* @param self::Name* $of
166+
* @return array<string, string>
167+
*/
163168
public function getUses(string $of = self::NameNormal): array
164169
{
165170
uasort($this->aliases[$of], fn(string $a, string $b): int => strtr($a, '\\', ' ') <=> strtr($b, '\\', ' '));
@@ -173,6 +178,7 @@ public function getUses(string $of = self::NameNormal): array
173178

174179
/**
175180
* Resolves relative name to full name.
181+
* @param self::Name* $of
176182
*/
177183
public function resolveName(string $name, string $of = self::NameNormal): string
178184
{
@@ -197,6 +203,7 @@ public function resolveName(string $name, string $of = self::NameNormal): string
197203

198204
/**
199205
* Simplifies type hint with relative names.
206+
* @param self::Name* $of
200207
*/
201208
public function simplifyType(string $type, string $of = self::NameNormal): string
202209
{
@@ -206,6 +213,7 @@ public function simplifyType(string $type, string $of = self::NameNormal): strin
206213

207214
/**
208215
* Simplifies the full name of a class, function, or constant to a relative name.
216+
* @param self::Name* $of
209217
*/
210218
public function simplifyName(string $name, string $of = self::NameNormal): string
211219
{

src/PhpGenerator/Printer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public function printFile(PhpFile $file): string
287287
}
288288

289289

290+
/** @param PhpNamespace::Name* $of */
290291
protected function printUses(PhpNamespace $namespace, string $of = PhpNamespace::NameNormal): string
291292
{
292293
$prefix = [
@@ -423,6 +424,7 @@ protected function printType(?string $type, bool $nullable): string
423424
}
424425

425426

427+
/** @param PhpFile|ClassLike|GlobalFunction|Method|Property|Constant|Parameter|EnumCase|TraitUse|PropertyHook $commentable */
426428
protected function printDocComment(/*Traits\CommentAware*/ $commentable): string
427429
{
428430
$multiLine = $commentable instanceof GlobalFunction
@@ -441,7 +443,7 @@ protected function printReturnType(Closure|GlobalFunction|Method $function): str
441443
}
442444

443445

444-
/** @param Attribute[] $attrs */
446+
/** @param list<Attribute> $attrs */
445447
protected function printAttributes(array $attrs, bool $inline = false): string
446448
{
447449
if (!$attrs) {

src/PhpGenerator/PropertyHook.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class PropertyHook
1818
private bool $final = false;
1919
private bool $abstract = false;
2020

21-
/** @var Parameter[] */
21+
/** @var array<string, Parameter> */
2222
private array $parameters = [];
2323
private bool $returnReference = false;
2424

@@ -78,7 +78,7 @@ public function isAbstract(): bool
7878

7979

8080
/**
81-
* @param Parameter[] $val
81+
* @param list<Parameter> $val
8282
* @internal
8383
*/
8484
public function setParameters(array $val): static
@@ -94,7 +94,7 @@ public function setParameters(array $val): static
9494

9595

9696
/**
97-
* @return Parameter[]
97+
* @return array<string, Parameter>
9898
* @internal
9999
*/
100100
public function getParameters(): array

src/PhpGenerator/TraitUse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class TraitUse
1818
use Traits\NameAware;
1919
use Traits\CommentAware;
2020

21-
/** @var string[] */
21+
/** @var list<string> */
2222
private array $resolutions = [];
2323

2424

@@ -39,7 +39,7 @@ public function addResolution(string $resolution): static
3939
}
4040

4141

42-
/** @return string[] */
42+
/** @return list<string> */
4343
public function getResolutions(): array
4444
{
4545
return $this->resolutions;

src/PhpGenerator/Traits/PropertyLike.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ trait PropertyLike
2828
private array $hooks = ['set' => null, 'get' => null];
2929

3030

31+
/**
32+
* @param Visibility|'public'|'protected'|'private'|null $get
33+
* @param Visibility|'public'|'protected'|'private'|null $set
34+
*/
3135
public function setVisibility(Visibility|string|null $get, Visibility|string|null $set = null): static
3236
{
3337
$this->visibility = [
@@ -38,13 +42,15 @@ public function setVisibility(Visibility|string|null $get, Visibility|string|nul
3842
}
3943

4044

45+
/** @return 'public'|'protected'|'private'|null */
4146
public function getVisibility(PropertyAccessMode|string $mode = PropertyAccessMode::Get): ?string
4247
{
4348
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
4449
return $this->visibility[$mode->value]?->value;
4550
}
4651

4752

53+
/** @param PropertyAccessMode|'set'|'get' $mode */
4854
public function setPublic(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
4955
{
5056
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -53,13 +59,15 @@ public function setPublic(PropertyAccessMode|string $mode = PropertyAccessMode::
5359
}
5460

5561

62+
/** @param PropertyAccessMode|'set'|'get' $mode */
5663
public function isPublic(PropertyAccessMode|string $mode = PropertyAccessMode::Get): bool
5764
{
5865
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
5966
return in_array($this->visibility[$mode->value], [Visibility::Public, null], strict: true);
6067
}
6168

6269

70+
/** @param PropertyAccessMode|'set'|'get' $mode */
6371
public function setProtected(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
6472
{
6573
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -68,13 +76,15 @@ public function setProtected(PropertyAccessMode|string $mode = PropertyAccessMod
6876
}
6977

7078

79+
/** @param PropertyAccessMode|'set'|'get' $mode */
7180
public function isProtected(PropertyAccessMode|string $mode = PropertyAccessMode::Get): bool
7281
{
7382
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
7483
return $this->visibility[$mode->value] === Visibility::Protected;
7584
}
7685

7786

87+
/** @param PropertyAccessMode|'set'|'get' $mode */
7888
public function setPrivate(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
7989
{
8090
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -83,6 +93,7 @@ public function setPrivate(PropertyAccessMode|string $mode = PropertyAccessMode:
8393
}
8494

8595

96+
/** @param PropertyAccessMode|'set'|'get' $mode */
8697
public function isPrivate(PropertyAccessMode|string $mode = PropertyAccessMode::Get): bool
8798
{
8899
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -118,7 +129,7 @@ public function isReadOnly(): bool
118129

119130
/**
120131
* Replaces all hooks.
121-
* @param PropertyHook[] $hooks
132+
* @param array<string, PropertyHook> $hooks
122133
*/
123134
public function setHooks(array $hooks): static
124135
{
@@ -135,6 +146,7 @@ public function getHooks(): array
135146
}
136147

137148

149+
/** @param PropertyHookType|'set'|'get' $type */
138150
public function addHook(PropertyHookType|string $type, string $shortBody = ''): PropertyHook
139151
{
140152
$type = is_string($type) ? PropertyHookType::from($type) : $type;
@@ -143,13 +155,15 @@ public function addHook(PropertyHookType|string $type, string $shortBody = ''):
143155
}
144156

145157

158+
/** @param PropertyHookType|'set'|'get' $type */
146159
public function getHook(PropertyHookType|string $type): ?PropertyHook
147160
{
148161
$type = is_string($type) ? PropertyHookType::from($type) : $type;
149162
return $this->hooks[$type->value] ?? null;
150163
}
151164

152165

166+
/** @param PropertyHookType|'set'|'get' $type */
153167
public function hasHook(PropertyHookType|string $type): bool
154168
{
155169
$type = is_string($type) ? PropertyHookType::from($type) : $type;

0 commit comments

Comments
 (0)