From 801ac17657059b42b63db2b6af9c85c831fc668d Mon Sep 17 00:00:00 2001 From: Evgeniy Tkachenko Date: Wed, 7 Oct 2020 01:12:10 +0300 Subject: [PATCH] Fix #16077: Improved phpdoc generation for class properties (#18319) When generating documentation, the `@property-read` and `@property-write` tags are set to the magic properties of classes --- build/controllers/PhpDocController.php | 64 +++++++++++++------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/build/controllers/PhpDocController.php b/build/controllers/PhpDocController.php index bcf2731ea08..21f7ff8c2a4 100644 --- a/build/controllers/PhpDocController.php +++ b/build/controllers/PhpDocController.php @@ -722,43 +722,45 @@ protected function generateClassPropertyDocs($fileName) ]; } + if (\count($props) === 0) { + continue; + } + ksort($props); - if (\count($props) > 0) { - $phpdoc .= " *\n"; - foreach ($props as $propName => &$prop) { - $docline = ' * @'; - $docline .= 'property'; // Do not use property-read and property-write as few IDEs support complex syntax. - $note = ''; - if (isset($prop['get'], $prop['set'])) { - if ($prop['get']['type'] != $prop['set']['type']) { - $note = ' Note that the type of this property differs in getter and setter.' - . ' See [[get' . ucfirst($propName) . '()]] and [[set' . ucfirst($propName) . '()]] for details.'; - } - } elseif (isset($prop['get'])) { - if (!$this->hasSetterInParents($className, $propName)) { - $note = ' This property is read-only.'; - //$docline .= '-read'; - } - } elseif (isset($prop['set'])) { - if (!$this->hasGetterInParents($className, $propName)) { - $note = ' This property is write-only.'; - //$docline .= '-write'; - } - } else { - continue; + $phpdoc .= " *\n"; + foreach ($props as $propName => &$prop) { + $docLine = ' * @property'; + $note = ''; + if (isset($prop['get'], $prop['set'])) { + if ($prop['get']['type'] != $prop['set']['type']) { + $note = ' Note that the type of this property differs in getter and setter.' + . ' See [[get' . ucfirst($propName) . '()]] ' + . ' and [[set' . ucfirst($propName) . '()]] for details.'; } - $docline .= ' ' . $this->getPropParam($prop, 'type') . " $$propName "; - $comment = explode("\n", $this->getPropParam($prop, 'comment') . $note); - foreach ($comment as &$cline) { - $cline = ltrim($cline, '* '); + } elseif (isset($prop['get'])) { + if (!$this->hasSetterInParents($className, $propName)) { + $note = ' This property is read-only.'; + $docLine .= '-read'; } - $docline = wordwrap($docline . implode(' ', $comment), 110, "\n * ") . "\n"; - - $phpdoc .= $docline; + } elseif (isset($prop['set'])) { + if (!$this->hasGetterInParents($className, $propName)) { + $note = ' This property is write-only.'; + $docLine .= '-write'; + } + } else { + continue; + } + $docLine .= ' ' . $this->getPropParam($prop, 'type') . " $$propName "; + $comment = explode("\n", $this->getPropParam($prop, 'comment') . $note); + foreach ($comment as &$cline) { + $cline = ltrim($cline, '* '); } - $phpdoc .= " *\n"; + $docLine = wordwrap($docLine . implode(' ', $comment), 110, "\n * ") . "\n"; + + $phpdoc .= $docLine; } + $phpdoc .= " *\n"; } return [$className, $phpdoc];