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

Commit 4b2615c

Browse files
committed
converter: apply whitelist filtering on supported types
Only in effect on all-lowercase types. This is to filter out stuff like `mixed`, `void`, `$this`, etc.
1 parent 8673f09 commit 4b2615c

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/Converter.php

+44-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ class Converter
3737
const OBJECT_TRAIT = 2;
3838
const OBJECT_FUNCTION = 3;
3939

40+
/**
41+
* @link http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
42+
*/
43+
const TYPES = [
44+
'array',
45+
'bool',
46+
'callable',
47+
'float',
48+
'int',
49+
'self',
50+
'string',
51+
];
52+
4053
/**
4154
* Converts the given file.
4255
*
@@ -446,13 +459,43 @@ private function getReturn(Project $project, int $objectType, string $namespace
446459
}
447460

448461
/**
449-
* Gets the type of the parameter or null if it is not defined.
462+
* Gets the parameter type and applies a whitelist of PHPs supported types
463+
*
464+
* The whitelist is only applied for all-lowercase character; everything
465+
* else is considered to be a class name.
450466
*
451467
* @param Tag $tag
452468
*
453469
* @return array
454470
*/
455471
private function getType(Tag $tag): array
472+
{
473+
$type = $this->getTypeFromTag($tag);
474+
475+
if (!$type) {
476+
return $type;
477+
}
478+
479+
$typeDesc = $type[0];
480+
481+
if ($typeDesc === strtolower($typeDesc)) {
482+
// match all-lowercase types against known types
483+
if (!in_array($typeDesc, static::TYPES)) {
484+
return [];
485+
}
486+
}
487+
488+
return $type;
489+
}
490+
491+
/**
492+
* Gets the type of the parameter or an empty array if it is not defined.
493+
*
494+
* @param Tag $tag
495+
*
496+
* @return array
497+
*/
498+
private function getTypeFromTag(Tag $tag): array
456499
{
457500
$type = $tag->getType();
458501

0 commit comments

Comments
 (0)