Skip to content

Commit 8e292e7

Browse files
Fix broken generation
1 parent 3a6e43b commit 8e292e7

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

generator/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"thecodingmachine/phpstan-strict-rules": "^1.0",
2020
"squizlabs/php_codesniffer": "^3.2",
2121
"php-coveralls/php-coveralls": "^2.1",
22-
"phpstan/phpstan": "^1.5"
22+
"phpstan/phpstan": "^1.10.40"
2323
},
2424
"scripts": {
2525
"test": "vendor/bin/phpunit",

generator/composer.lock

+15-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/src/PhpStanFunctions/PhpStanFunction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(array $signature)
2323
if (count($signature) < 1) {
2424
throw new \RuntimeException('Invalid signoatures');
2525
}
26-
$this->returnType = new PhpStanType(\array_shift($signature));
26+
$this->returnType = new PhpStanType(\array_shift($signature), false, true);
2727
foreach ($signature as $name => $type) {
2828
$param = new PhpStanParameter($name, $type);
2929
$this->parameters[$param->getName()] = $param;

generator/src/PhpStanFunctions/PhpStanParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(string $name, string $type)
2626
$name = trim($name, '=.&');
2727

2828
$this->name = $name;
29-
$this->type = new PhpStanType($type, $writeOnly);
29+
$this->type = new PhpStanType($type, $writeOnly, false);
3030
}
3131

3232
/**

generator/src/PhpStanFunctions/PhpStanType.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PhpStanType
3030
*/
3131
private $types;
3232

33-
public function __construct(string $data, bool $writeOnly = false)
33+
public function __construct(string $data, bool $writeOnly = false, bool $isReturnType = false)
3434
{
3535
//weird case: null|false => null
3636
if ($data === 'null|false') {
@@ -57,6 +57,9 @@ public function __construct(string $data, bool $writeOnly = false)
5757
if (($falsablePosition = \array_search('false', $returnTypes)) !== false) {
5858
$falsable = true;
5959
\array_splice($returnTypes, (int) $falsablePosition, 1);
60+
if ($isReturnType === false) {
61+
$returnTypes[] = 'bool';
62+
}
6063
}
6164
/** @var int $count */
6265
$count = \count($returnTypes);
@@ -76,10 +79,14 @@ public function __construct(string $data, bool $writeOnly = false)
7679
//here we deal with some weird phpstan typings
7780
if ($returnType === 'non-empty-string') {
7881
$returnType = 'string';
82+
} elseif ($returnType === 'non-falsy-string') {
83+
$returnType = 'string';
7984
} elseif ($returnType === 'positive-int') {
8085
$returnType = 'int';
8186
} elseif (is_numeric($returnType)) {
8287
$returnType = 'int';
88+
} elseif (\strpos($returnType, 'int<') !== false) {
89+
$returnType = 'int';
8390
}
8491
if (\strpos($returnType, 'list<') !== false) {
8592
$returnType = \str_replace('list', 'array', $returnType);

0 commit comments

Comments
 (0)