From 163c5e9e8dc3cc5eedc4887b5e0198fcfb41354b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 29 Aug 2023 20:58:03 +0200 Subject: [PATCH] improved phpDoc --- src/PhpGenerator/Extractor.php | 5 ++++- src/PhpGenerator/Parameter.php | 1 + src/PhpGenerator/PhpFile.php | 2 +- src/PhpGenerator/PhpNamespace.php | 6 +++--- src/PhpGenerator/Property.php | 1 + src/PhpGenerator/Traits/FunctionLike.php | 1 + 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index c38c9207..83f65e07 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -357,7 +357,10 @@ private function addEnumCaseToClass(EnumType $class, Node\Stmt\EnumCase $node): } - private function addCommentAndAttributes($element, Node $node): void + private function addCommentAndAttributes( + PhpFile|ClassLike|Constant|Property|GlobalFunction|Method|Parameter|EnumCase|TraitUse $element, + Node $node, + ): void { if ($node->getDocComment()) { $comment = $node->getDocComment()->getReformattedText(); diff --git a/src/PhpGenerator/Parameter.php b/src/PhpGenerator/Parameter.php index 94cd6710..975d0449 100644 --- a/src/PhpGenerator/Parameter.php +++ b/src/PhpGenerator/Parameter.php @@ -52,6 +52,7 @@ public function setType(?string $type): static } + /** @return ($asObject is true ? ?Type : ?string) */ public function getType(bool $asObject = false): Type|string|null { return $asObject && $this->type diff --git a/src/PhpGenerator/PhpFile.php b/src/PhpGenerator/PhpFile.php index 68fd89bc..34142f5a 100644 --- a/src/PhpGenerator/PhpFile.php +++ b/src/PhpGenerator/PhpFile.php @@ -97,7 +97,7 @@ public function getNamespaces(): array } - /** @return ClassLike[] */ + /** @return (ClassType|InterfaceType|TraitType|EnumType)[] */ public function getClasses(): array { $classes = []; diff --git a/src/PhpGenerator/PhpNamespace.php b/src/PhpGenerator/PhpNamespace.php index 0303d2dd..ef9b324e 100644 --- a/src/PhpGenerator/PhpNamespace.php +++ b/src/PhpGenerator/PhpNamespace.php @@ -50,7 +50,7 @@ final class PhpNamespace self::NameConstant => [], ]; - /** @var ClassLike[] */ + /** @var (ClassType|InterfaceType|TraitType|EnumType)[] */ private array $classes = []; /** @var GlobalFunction[] */ @@ -253,7 +253,7 @@ public function simplifyName(string $name, string $of = self::NameNormal): strin } - public function add(ClassLike $class): static + public function add(ClassType|InterfaceType|TraitType|EnumType $class): static { $name = $class->getName(); if ($name === null) { @@ -327,7 +327,7 @@ public function removeFunction(string $name): static } - /** @return ClassLike[] */ + /** @return (ClassType|InterfaceType|TraitType|EnumType)[] */ public function getClasses(): array { $res = []; diff --git a/src/PhpGenerator/Property.php b/src/PhpGenerator/Property.php index d1ffbafa..01529a0e 100644 --- a/src/PhpGenerator/Property.php +++ b/src/PhpGenerator/Property.php @@ -68,6 +68,7 @@ public function setType(?string $type): static } + /** @return ($asObject is true ? ?Type : ?string) */ public function getType(bool $asObject = false): Type|string|null { return $asObject && $this->type diff --git a/src/PhpGenerator/Traits/FunctionLike.php b/src/PhpGenerator/Traits/FunctionLike.php index 7a92a8db..df0a6814 100644 --- a/src/PhpGenerator/Traits/FunctionLike.php +++ b/src/PhpGenerator/Traits/FunctionLike.php @@ -141,6 +141,7 @@ public function setReturnType(?string $type): static } + /** @return ($asObject is true ? ?Type : ?string) */ public function getReturnType(bool $asObject = false): Type|string|null { return $asObject && $this->returnType