Skip to content
This repository was archived by the owner on Dec 29, 2020. It is now read-only.

Commit dede655

Browse files
committed
converter: handle params in phpdoc without type declaration
Otherwise it would crash when calling __toString() on `null`
1 parent 3d8879b commit dede655

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Converter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ private function getType(Tag $tag): array
447447
{
448448
$type = $tag->getType();
449449

450+
if (null === $type) {
451+
// No type specified
452+
return [];
453+
}
454+
450455
if ($type instanceof Compound) {
451456
if ($type->has(2)) {
452457
// Several types, cannot guess

tests/Fixtures/param_no_type.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* @param $noType
4+
*/
5+
function param_no_type($noType)
6+
{
7+
}

tests/test.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,21 @@ public function baz(array $a, int $b)
220220
}
221221
}
222222

223+
$projectFactory = ProjectFactory::createInstance();
224+
$project = $projectFactory->create('paramNoType', [__DIR__.'/Fixtures/param_no_type.php']);
225+
226+
foreach ($project->getFiles() as $path => $file) {
227+
same(<<<'PHP'
228+
<?php
229+
/**
230+
* @param $noType
231+
*/
232+
function param_no_type($noType)
233+
{
234+
}
235+
236+
PHP
237+
, $converter->convert($project, $file));
238+
}
239+
223240
echo 'Good job! Everything is fine.'.PHP_EOL;

0 commit comments

Comments
 (0)