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

Commit f0270cd

Browse files
committed
converter: normalize commonly used aliases
1 parent 4b2615c commit f0270cd

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/Converter.php

+35-3
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ private function getReturn(Project $project, int $objectType, string $namespace
459459
}
460460

461461
/**
462-
* Gets the parameter type and applies a whitelist of PHPs supported types
462+
* Gets the parameter type and tries to find best-matching PHP type
463463
*
464-
* The whitelist is only applied for all-lowercase character; everything
465-
* else is considered to be a class name.
464+
* Commonly used type aliases are normalized and a whitelist for
465+
* all-lowercase types is applied.
466466
*
467467
* @param Tag $tag
468468
*
@@ -479,6 +479,7 @@ private function getType(Tag $tag): array
479479
$typeDesc = $type[0];
480480

481481
if ($typeDesc === strtolower($typeDesc)) {
482+
$typeDesc = $this->normalizeType($typeDesc);
482483
// match all-lowercase types against known types
483484
if (!in_array($typeDesc, static::TYPES)) {
484485
return [];
@@ -560,4 +561,35 @@ private function endsInNewLine(string $output): string
560561

561562
return $matches[1];
562563
}
564+
565+
/**
566+
* Normalizes the type.
567+
*
568+
* @link https://github.com/symfony/symfony/blob/d2d8d17a8068d76f42c42c7791f45ca68f4f98a4/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php#L317-L346
569+
* @license https://github.com/symfony/symfony/blob/d2d8d17a8068d76f42c42c7791f45ca68f4f98a4/src/Symfony/Component/PropertyInfo/LICENSE
570+
*
571+
* @param string $docType
572+
*
573+
* @return string
574+
*/
575+
private function normalizeType($docType)
576+
{
577+
switch ($docType) {
578+
case 'integer':
579+
return 'int';
580+
581+
case 'boolean':
582+
return 'bool';
583+
584+
// real is not part of the PHPDoc standard, so we ignore it
585+
case 'double':
586+
return 'float';
587+
588+
case 'callback':
589+
return 'callable';
590+
591+
default:
592+
return $docType;
593+
}
594+
}
563595
}

0 commit comments

Comments
 (0)