Skip to content

Commit 48c7cdf

Browse files
committed
added phpDoc comments
1 parent 8a9c407 commit 48c7cdf

13 files changed

+126
-15
lines changed

src/PhpGenerator/Closure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __toString(): string
3535

3636

3737
/**
38+
* Replaces all uses.
3839
* @param Parameter[] $uses
3940
*/
4041
public function setUses(array $uses): static

src/PhpGenerator/EnumType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public function removeCase(string $name): static
116116
}
117117

118118

119+
/**
120+
* Adds a member. If it already exists, throws an exception or overwrites it if $overwrite is true.
121+
*/
119122
public function addMember(Method|Constant|EnumCase|TraitUse $member, bool $overwrite = false): static
120123
{
121124
$name = $member->getName();

src/PhpGenerator/InterfaceType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function addExtend(string $name): static
5151
}
5252

5353

54+
/**
55+
* Adds a member. If it already exists, throws an exception or overwrites it if $overwrite is true.
56+
*/
5457
public function addMember(Method|Constant $member, bool $overwrite = false): static
5558
{
5659
$name = $member->getName();

src/PhpGenerator/PhpFile.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public static function fromCode(string $code): self
3333
}
3434

3535

36+
/**
37+
* Adds a class to the file. If it already exists, throws an exception.
38+
* As a parameter, pass the full name with namespace.
39+
*/
3640
public function addClass(string $name): ClassType
3741
{
3842
return $this
@@ -41,6 +45,10 @@ public function addClass(string $name): ClassType
4145
}
4246

4347

48+
/**
49+
* Adds an interface to the file. If it already exists, throws an exception.
50+
* As a parameter, pass the full name with namespace.
51+
*/
4452
public function addInterface(string $name): InterfaceType
4553
{
4654
return $this
@@ -49,6 +57,10 @@ public function addInterface(string $name): InterfaceType
4957
}
5058

5159

60+
/**
61+
* Adds a trait to the file. If it already exists, throws an exception.
62+
* As a parameter, pass the full name with namespace.
63+
*/
5264
public function addTrait(string $name): TraitType
5365
{
5466
return $this
@@ -57,6 +69,10 @@ public function addTrait(string $name): TraitType
5769
}
5870

5971

72+
/**
73+
* Adds an enum to the file. If it already exists, throws an exception.
74+
* As a parameter, pass the full name with namespace.
75+
*/
6076
public function addEnum(string $name): EnumType
6177
{
6278
return $this
@@ -65,6 +81,21 @@ public function addEnum(string $name): EnumType
6581
}
6682

6783

84+
/**
85+
* Adds a function to the file. If it already exists, throws an exception.
86+
* As a parameter, pass the full name with namespace.
87+
*/
88+
public function addFunction(string $name): GlobalFunction
89+
{
90+
return $this
91+
->addNamespace(Helpers::extractNamespace($name))
92+
->addFunction(Helpers::extractShortName($name));
93+
}
94+
95+
96+
/**
97+
* Adds a namespace to the file. If it already exists, it returns the existing one.
98+
*/
6899
public function addNamespace(string|PhpNamespace $namespace): PhpNamespace
69100
{
70101
$res = $namespace instanceof PhpNamespace
@@ -79,14 +110,6 @@ public function addNamespace(string|PhpNamespace $namespace): PhpNamespace
79110
}
80111

81112

82-
public function addFunction(string $name): GlobalFunction
83-
{
84-
return $this
85-
->addNamespace(Helpers::extractNamespace($name))
86-
->addFunction(Helpers::extractShortName($name));
87-
}
88-
89-
90113
/** @return PhpNamespace[] */
91114
public function getNamespaces(): array
92115
{
@@ -124,6 +147,9 @@ public function getFunctions(): array
124147
}
125148

126149

150+
/**
151+
* Adds a use statement to the file, to the global namespace.
152+
*/
127153
public function addUse(string $name, ?string $alias = null, string $of = PhpNamespace::NameNormal): static
128154
{
129155
$this->addNamespace('')->addUse($name, $alias, $of);

src/PhpGenerator/PhpNamespace.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function hasBracketedSyntax(): bool
8888

8989

9090
/**
91+
* Adds a use statement to the namespace for class, function or constant.
9192
* @throws InvalidStateException
9293
*/
9394
public function addUse(string $name, ?string $alias = null, string $of = self::NameNormal): static
@@ -140,12 +141,18 @@ public function removeUse(string $name, string $of = self::NameNormal): void
140141
}
141142

142143

144+
/**
145+
* Adds a use statement to the namespace for function.
146+
*/
143147
public function addUseFunction(string $name, ?string $alias = null): static
144148
{
145149
return $this->addUse($name, $alias, self::NameFunction);
146150
}
147151

148152

153+
/**
154+
* Adds a use statement to the namespace for constant.
155+
*/
149156
public function addUseConstant(string $name, ?string $alias = null): static
150157
{
151158
return $this->addUse($name, $alias, self::NameConstant);
@@ -164,6 +171,9 @@ public function getUses(string $of = self::NameNormal): array
164171
}
165172

166173

174+
/**
175+
* Resolves relative name to full name.
176+
*/
167177
public function resolveName(string $name, string $of = self::NameNormal): string
168178
{
169179
if (isset(Helpers::Keywords[strtolower($name)]) || $name === '') {
@@ -185,12 +195,18 @@ public function resolveName(string $name, string $of = self::NameNormal): string
185195
}
186196

187197

198+
/**
199+
* Simplifies type hint with relative names.
200+
*/
188201
public function simplifyType(string $type, string $of = self::NameNormal): string
189202
{
190203
return preg_replace_callback('~[\w\x7f-\xff\\\\]+~', fn($m) => $this->simplifyName($m[0], $of), $type);
191204
}
192205

193206

207+
/**
208+
* Simplifies the full name of a class, function, or constant to a relative name.
209+
*/
194210
public function simplifyName(string $name, string $of = self::NameNormal): string
195211
{
196212
if (isset(Helpers::Keywords[strtolower($name)]) || $name === '') {
@@ -235,6 +251,9 @@ public function simplifyName(string $name, string $of = self::NameNormal): strin
235251
}
236252

237253

254+
/**
255+
* Adds a class-like type to the namespace. If it already exists, throws an exception.
256+
*/
238257
public function add(ClassType|InterfaceType|TraitType|EnumType $class): static
239258
{
240259
$name = $class->getName();
@@ -254,41 +273,59 @@ public function add(ClassType|InterfaceType|TraitType|EnumType $class): static
254273
}
255274

256275

276+
/**
277+
* Adds a class to the namespace. If it already exists, throws an exception.
278+
*/
257279
public function addClass(string $name): ClassType
258280
{
259281
$this->add($class = new ClassType($name, $this));
260282
return $class;
261283
}
262284

263285

286+
/**
287+
* Adds an interface to the namespace. If it already exists, throws an exception.
288+
*/
264289
public function addInterface(string $name): InterfaceType
265290
{
266291
$this->add($iface = new InterfaceType($name, $this));
267292
return $iface;
268293
}
269294

270295

296+
/**
297+
* Adds a trait to the namespace. If it already exists, throws an exception.
298+
*/
271299
public function addTrait(string $name): TraitType
272300
{
273301
$this->add($trait = new TraitType($name, $this));
274302
return $trait;
275303
}
276304

277305

306+
/**
307+
* Adds an enum to the namespace. If it already exists, throws an exception.
308+
*/
278309
public function addEnum(string $name): EnumType
279310
{
280311
$this->add($enum = new EnumType($name, $this));
281312
return $enum;
282313
}
283314

284315

316+
/**
317+
* Removes a class-like type from namespace.
318+
*/
285319
public function removeClass(string $name): static
286320
{
287321
unset($this->classes[strtolower($name)]);
288322
return $this;
289323
}
290324

291325

326+
/**
327+
* Adds a function to the namespace. If it already exists, throws an exception.
328+
*/
292329
public function addFunction(string $name): GlobalFunction
293330
{
294331
$lower = strtolower($name);
@@ -302,14 +339,20 @@ public function addFunction(string $name): GlobalFunction
302339
}
303340

304341

342+
/**
343+
* Removes a function type from namespace.
344+
*/
305345
public function removeFunction(string $name): static
306346
{
307347
unset($this->functions[strtolower($name)]);
308348
return $this;
309349
}
310350

311351

312-
/** @return (ClassType|InterfaceType|TraitType|EnumType)[] */
352+
/**
353+
* Returns all class-like types in the namespace.
354+
* @return (ClassType|InterfaceType|TraitType|EnumType)[]
355+
*/
313356
public function getClasses(): array
314357
{
315358
$res = [];
@@ -321,7 +364,10 @@ public function getClasses(): array
321364
}
322365

323366

324-
/** @return GlobalFunction[] */
367+
/**
368+
* Returns all functions in the namespace.
369+
* @return GlobalFunction[]
370+
*/
325371
public function getFunctions(): array
326372
{
327373
$res = [];

src/PhpGenerator/TraitType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ final class TraitType extends ClassLike
2222
use Traits\PropertiesAware;
2323
use Traits\TraitsAware;
2424

25+
/**
26+
* Adds a member. If it already exists, throws an exception or overwrites it if $overwrite is true.
27+
*/
2528
public function addMember(Method|Property|Constant|TraitUse $member, bool $overwrite = false): static
2629
{
2730
$name = $member->getName();

src/PhpGenerator/Traits/AttributeAware.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function addAttribute(string $name, array $args = []): static
3030

3131

3232
/**
33+
* Replaces all attributes.
3334
* @param Attribute[] $attrs
3435
*/
3536
public function setAttributes(array $attrs): static

src/PhpGenerator/Traits/CommentAware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public function getComment(): ?string
3131
}
3232

3333

34+
/**
35+
* Adds a new line to the comment.
36+
*/
3437
public function addComment(string $val): static
3538
{
3639
$this->comment .= $this->comment ? "\n$val" : $val;

src/PhpGenerator/Traits/ConstantsAware.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ trait ConstantsAware
2222
private array $consts = [];
2323

2424

25-
/** @param Constant[] $consts */
25+
/**
26+
* Replaces all constants.
27+
* @param Constant[] $consts
28+
*/
2629
public function setConstants(array $consts): static
2730
{
2831
(function (Constant ...$consts) {})(...$consts);
@@ -48,6 +51,9 @@ public function getConstant(string $name): Constant
4851
}
4952

5053

54+
/**
55+
* Adds a constant. If it already exists, throws an exception or overwrites it if $overwrite is true.
56+
*/
5157
public function addConstant(string $name, mixed $value, bool $overwrite = false): Constant
5258
{
5359
if (!$overwrite && isset($this->consts[$name])) {

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function getParameter(string $name): Parameter
9292

9393

9494
/**
95+
* Adds a parameter. If it already exists, it overwrites it.
9596
* @param string $name without $
9697
*/
9798
public function addParameter(string $name, mixed $defaultValue = null): Parameter

0 commit comments

Comments
 (0)