diff --git a/generator/src/PhpStanFunctions/PhpStanFunction.php b/generator/src/PhpStanFunctions/PhpStanFunction.php index 7381f17a..c842e3fc 100644 --- a/generator/src/PhpStanFunctions/PhpStanFunction.php +++ b/generator/src/PhpStanFunctions/PhpStanFunction.php @@ -23,7 +23,7 @@ public function __construct(array $signature) if (count($signature) < 1) { throw new \RuntimeException('Invalid signatures'); } - $this->returnType = new PhpStanType(\array_shift($signature)); + $this->returnType = new PhpStanType(\array_shift($signature), false, true); foreach ($signature as $name => $type) { $param = new PhpStanParameter($name, $type); $this->parameters[$param->getName()] = $param; diff --git a/generator/src/PhpStanFunctions/PhpStanParameter.php b/generator/src/PhpStanFunctions/PhpStanParameter.php index 16deedaf..d0a7d030 100644 --- a/generator/src/PhpStanFunctions/PhpStanParameter.php +++ b/generator/src/PhpStanFunctions/PhpStanParameter.php @@ -26,7 +26,7 @@ public function __construct(string $name, string $type) $name = trim($name, '=.&'); $this->name = $name; - $this->type = new PhpStanType($type, $writeOnly); + $this->type = new PhpStanType($type, $writeOnly, false); } /** diff --git a/generator/src/PhpStanFunctions/PhpStanType.php b/generator/src/PhpStanFunctions/PhpStanType.php index 1a9f3dfb..314458b7 100644 --- a/generator/src/PhpStanFunctions/PhpStanType.php +++ b/generator/src/PhpStanFunctions/PhpStanType.php @@ -30,7 +30,7 @@ class PhpStanType */ private $types; - public function __construct(string $data, bool $writeOnly = false) + public function __construct(string $data, bool $writeOnly = false, bool $isReturnType = false) { //weird case: null|false => null if ($data === 'null|false') { @@ -57,6 +57,9 @@ public function __construct(string $data, bool $writeOnly = false) if (($falsablePosition = \array_search('false', $returnTypes)) !== false) { $falsable = true; \array_splice($returnTypes, (int) $falsablePosition, 1); + if ($isReturnType === false) { + $returnTypes[] = 'bool'; + } } /** @var int $count */ $count = \count($returnTypes); @@ -76,10 +79,14 @@ public function __construct(string $data, bool $writeOnly = false) //here we deal with some weird phpstan typings if ($returnType === 'non-empty-string') { $returnType = 'string'; + } elseif ($returnType === 'non-falsy-string') { + $returnType = 'string'; } elseif ($returnType === 'positive-int') { $returnType = 'int'; } elseif (is_numeric($returnType)) { $returnType = 'int'; + } elseif (\strpos($returnType, 'int<') !== false) { + $returnType = 'int'; } if (\strpos($returnType, 'list<') !== false) { $returnType = \str_replace('list', 'array', $returnType);