Skip to content

Commit 879b5a6

Browse files
committed
improved phpDoc
1 parent 52aff4d commit 879b5a6

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
@@ -18,7 +18,7 @@ final class Closure
1818
use Traits\FunctionLike;
1919
use Traits\AttributeAware;
2020

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

2424

@@ -37,7 +37,7 @@ public function __toString(): string
3737

3838
/**
3939
* Replaces all uses.
40-
* @param Parameter[] $uses
40+
* @param list<Parameter> $uses
4141
*/
4242
public function setUses(array $uses): static
4343
{
@@ -47,7 +47,7 @@ public function setUses(array $uses): static
4747
}
4848

4949

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

src/PhpGenerator/EnumType.php

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

7676
/**
7777
* Sets cases to enum
78-
* @param EnumCase[] $cases
78+
* @param list<EnumCase> $cases
7979
*/
8080
public function setCases(array $cases): static
8181
{
@@ -89,7 +89,7 @@ public function setCases(array $cases): static
8989
}
9090

9191

92-
/** @return EnumCase[] */
92+
/** @return array<string, EnumCase> */
9393
public function getCases(): array
9494
{
9595
return $this->cases;

src/PhpGenerator/Extractor.php

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

29-
/** @var list<Node> */
29+
/** @var array<Node> */
3030
private array $statements;
3131
private PhpParser\PrettyPrinterAbstract $printer;
3232

src/PhpGenerator/Helpers.php

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

6464

65+
/** @param PhpNamespace::Name* $of */
6566
public static function tagName(string $name, string $of = PhpNamespace::NameNormal): string
6667
{
6768
return isset(self::Keywords[strtolower($name)])
@@ -129,6 +130,7 @@ public static function tabsToSpaces(string $s, int $count = 4): string
129130

130131

131132
/**
133+
* @param class-string $class
132134
* @param mixed[] $props
133135
* @internal
134136
*/

src/PhpGenerator/PhpFile.php

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

185185
/**
186186
* Adds a use statement to the file, to the global namespace.
187+
* @param PhpNamespace::Name* $of
187188
*/
188189
public function addUse(string $name, ?string $alias = null, string $of = PhpNamespace::NameNormal): static
189190
{

src/PhpGenerator/PhpNamespace.php

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

4444
private bool $bracketedSyntax = false;
4545

46-
/** @var string[][] */
46+
/** @var array<string, array<string, string>> */
4747
private array $aliases = [
4848
self::NameNormal => [],
4949
self::NameFunction => [],
@@ -91,6 +91,7 @@ public function hasBracketedSyntax(): bool
9191

9292
/**
9393
* Adds a use statement to the namespace for class, function or constant.
94+
* @param self::Name* $of
9495
* @throws InvalidStateException
9596
*/
9697
public function addUse(string $name, ?string $alias = null, string $of = self::NameNormal): static
@@ -133,6 +134,7 @@ public function addUse(string $name, ?string $alias = null, string $of = self::N
133134
}
134135

135136

137+
/** @param self::Name* $of */
136138
public function removeUse(string $name, string $of = self::NameNormal): void
137139
{
138140
foreach ($this->aliases[$of] as $alias => $item) {
@@ -161,7 +163,10 @@ public function addUseConstant(string $name, ?string $alias = null): static
161163
}
162164

163165

164-
/** @return array<string, string> */
166+
/**
167+
* @param self::Name* $of
168+
* @return array<string, string>
169+
*/
165170
public function getUses(string $of = self::NameNormal): array
166171
{
167172
uasort($this->aliases[$of], fn(string $a, string $b): int => strtr($a, '\\', ' ') <=> strtr($b, '\\', ' '));
@@ -175,6 +180,7 @@ public function getUses(string $of = self::NameNormal): array
175180

176181
/**
177182
* Resolves relative name to full name.
183+
* @param self::Name* $of
178184
*/
179185
public function resolveName(string $name, string $of = self::NameNormal): string
180186
{
@@ -199,6 +205,7 @@ public function resolveName(string $name, string $of = self::NameNormal): string
199205

200206
/**
201207
* Simplifies type hint with relative names.
208+
* @param self::Name* $of
202209
*/
203210
public function simplifyType(string $type, string $of = self::NameNormal): string
204211
{
@@ -208,6 +215,7 @@ public function simplifyType(string $type, string $of = self::NameNormal): strin
208215

209216
/**
210217
* Simplifies the full name of a class, function, or constant to a relative name.
218+
* @param self::Name* $of
211219
*/
212220
public function simplifyName(string $name, string $of = self::NameNormal): string
213221
{

src/PhpGenerator/Printer.php

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

291291

292+
/** @param PhpNamespace::Name* $of */
292293
protected function printUses(PhpNamespace $namespace, string $of = PhpNamespace::NameNormal): string
293294
{
294295
$prefix = [
@@ -425,6 +426,7 @@ protected function printType(?string $type, bool $nullable): string
425426
}
426427

427428

429+
/** @param PhpFile|ClassLike|GlobalFunction|Method|Property|Constant|Parameter|EnumCase|TraitUse|PropertyHook $commentable */
428430
protected function printDocComment(/*Traits\CommentAware*/ $commentable): string
429431
{
430432
$multiLine = $commentable instanceof GlobalFunction
@@ -443,7 +445,7 @@ protected function printReturnType(Closure|GlobalFunction|Method $function): str
443445
}
444446

445447

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

src/PhpGenerator/PropertyHook.php

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

23-
/** @var Parameter[] */
23+
/** @var array<string, Parameter> */
2424
private array $parameters = [];
2525
private bool $returnReference = false;
2626

@@ -80,7 +80,7 @@ public function isAbstract(): bool
8080

8181

8282
/**
83-
* @param Parameter[] $val
83+
* @param list<Parameter> $val
8484
* @internal
8585
*/
8686
public function setParameters(array $val): static
@@ -96,7 +96,7 @@ public function setParameters(array $val): static
9696

9797

9898
/**
99-
* @return Parameter[]
99+
* @return array<string, Parameter>
100100
* @internal
101101
*/
102102
public function getParameters(): array

src/PhpGenerator/TraitUse.php

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

23-
/** @var string[] */
23+
/** @var list<string> */
2424
private array $resolutions = [];
2525

2626

@@ -41,7 +41,7 @@ public function addResolution(string $resolution): static
4141
}
4242

4343

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

src/PhpGenerator/Traits/PropertyLike.php

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

3232

33+
/**
34+
* @param Visibility|'public'|'protected'|'private'|null $get
35+
* @param Visibility|'public'|'protected'|'private'|null $set
36+
*/
3337
public function setVisibility(Visibility|string|null $get, Visibility|string|null $set = null): static
3438
{
3539
$this->visibility = [
@@ -40,13 +44,15 @@ public function setVisibility(Visibility|string|null $get, Visibility|string|nul
4044
}
4145

4246

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

4954

55+
/** @param PropertyAccessMode|'set'|'get' $mode */
5056
public function setPublic(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
5157
{
5258
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -55,13 +61,15 @@ public function setPublic(PropertyAccessMode|string $mode = PropertyAccessMode::
5561
}
5662

5763

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

6471

72+
/** @param PropertyAccessMode|'set'|'get' $mode */
6573
public function setProtected(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
6674
{
6775
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -70,13 +78,15 @@ public function setProtected(PropertyAccessMode|string $mode = PropertyAccessMod
7078
}
7179

7280

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

7988

89+
/** @param PropertyAccessMode|'set'|'get' $mode */
8090
public function setPrivate(PropertyAccessMode|string $mode = PropertyAccessMode::Get): static
8191
{
8292
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -85,6 +95,7 @@ public function setPrivate(PropertyAccessMode|string $mode = PropertyAccessMode:
8595
}
8696

8797

98+
/** @param PropertyAccessMode|'set'|'get' $mode */
8899
public function isPrivate(PropertyAccessMode|string $mode = PropertyAccessMode::Get): bool
89100
{
90101
$mode = is_string($mode) ? PropertyAccessMode::from($mode) : $mode;
@@ -120,7 +131,7 @@ public function isReadOnly(): bool
120131

121132
/**
122133
* Replaces all hooks.
123-
* @param PropertyHook[] $hooks
134+
* @param array<string, PropertyHook> $hooks
124135
*/
125136
public function setHooks(array $hooks): static
126137
{
@@ -137,6 +148,7 @@ public function getHooks(): array
137148
}
138149

139150

151+
/** @param PropertyHookType|'set'|'get' $type */
140152
public function addHook(PropertyHookType|string $type, string $shortBody = ''): PropertyHook
141153
{
142154
$type = is_string($type) ? PropertyHookType::from($type) : $type;
@@ -145,13 +157,15 @@ public function addHook(PropertyHookType|string $type, string $shortBody = ''):
145157
}
146158

147159

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

154167

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

0 commit comments

Comments
 (0)