Skip to content

Commit b9550d8

Browse files
authored
Fix #313: Fix deprecation error Method deprecated, use ::getParameters()
1 parent 59ad069 commit b9550d8

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 apidoc extension Change Log
44
3.0.8 under development
55
-----------------------
66

7-
- Bug #314: Fix deprecation error `Method deprecated, use ::getParameters()` (mspirkov)
7+
- Bug #313: Fix deprecation error `Method deprecated, use ::getParameters()` (mspirkov)
88

99

1010
3.0.7 February 13, 2025

models/TypeDoc.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,33 @@ public function __construct($reflector = null, $context = null, $config = [])
223223
if ($tag instanceof Method) {
224224
$params = [];
225225

226-
foreach ($tag->getParameters() as $parameter) {
227-
$argumentType = (string) $parameter->getType();
228-
229-
$params[] = new ParamDoc(null, $context, [
230-
'sourceFile' => $this->sourceFile,
231-
'name' => $parameter->getName(),
232-
'typeHint' => $argumentType,
233-
'type' => $argumentType,
234-
'types' => [],
235-
]);
226+
if (PHP_VERSION_ID >= 70400) {
227+
foreach ($tag->getParameters() as $parameter) {
228+
$argumentType = (string) $parameter->getType();
229+
230+
$params[] = new ParamDoc(null, $context, [
231+
'sourceFile' => $this->sourceFile,
232+
'name' => $parameter->getName(),
233+
'typeHint' => $argumentType,
234+
'type' => $argumentType,
235+
'types' => [],
236+
]);
237+
}
238+
} else {
239+
foreach ($tag->getArguments() as $parameter) {
240+
$argumentType = (string) $parameter['type'];
241+
242+
$params[] = new ParamDoc(null, $context, [
243+
'sourceFile' => $this->sourceFile,
244+
'name' => $parameter['name'],
245+
'typeHint' => $argumentType,
246+
'type' => $argumentType,
247+
'types' => [],
248+
]);
249+
}
236250
}
237251

238-
$shortDescription = $tag->getDescription() ? BaseDoc::extractFirstSentence($tag->getDescription()): '';
252+
$shortDescription = $tag->getDescription() ? BaseDoc::extractFirstSentence($tag->getDescription()) : '';
239253
$description = $shortDescription ? substr($tag->getDescription(), strlen($shortDescription)) : '';
240254

241255
$method = new MethodDoc(null, $context, [

tests/commands/ApiControllerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ public function testGenerateBootstrap()
7777
$this->assertStringContainsString('Animal is a base class for animals.', $animalContent);
7878
$this->assertContainsWithoutIndent(
7979
<<<HTML
80+
<td colspan="3" class="signature">
81+
<span class="signature-defs">public</span> <span class="signature-type"><a href="https://www.php.net/language.types.integer">integer</a></span> <strong><a href="yiiunit-apidoc-data-api-animal-animal.html#getSomething()-detail">getSomething</a></strong> ( <span style="color: #0000BB">\$test</span> )
82+
</td>
83+
</tr>
84+
<tr>
85+
<td class="param-name-col"><span style="color: #0000BB">\$test</span></td>
86+
<td class="param-type-col"></td>
87+
<td class="param-desc-col"> </td>
88+
</tr>
89+
<tr>
90+
<th class="param-name-col">return</th>
91+
<td class="param-type-col"><a href="https://www.php.net/language.types.integer">integer</a></td>
92+
<td class="param-desc-col"></td>
93+
</tr>
94+
HTML
95+
, $animalContent
96+
);
97+
$this->assertContainsWithoutIndent(
98+
<<<HTML
8099
<tr id="\$name" class="">
81100
<td><a href="yiiunit-apidoc-data-api-animal-animal.html#\$name-detail">\$name</a></td>
82101
<td><a href="https://www.php.net/language.types.string">string</a></td>

tests/data/api/animal/Animal.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*
1515
* @property int $age animal age in seconds.
1616
*
17+
* @method int getSomething($test)
18+
*
1719
* @author Paul Klimov <[email protected]>
1820
* @since 1.0
1921
*/

0 commit comments

Comments
 (0)