diff --git a/.github/workflows/auto-regenerate.yml b/.github/workflows/auto-regenerate.yml index b128e6cb..9adeebfe 100644 --- a/.github/workflows/auto-regenerate.yml +++ b/.github/workflows/auto-regenerate.yml @@ -2,9 +2,7 @@ name: "Auto Regenerate" on: - schedule: - - cron: '0 3 * * *' - workflow_dispatch: + push: jobs: @@ -45,7 +43,7 @@ jobs: - name: "Regenerate files" id: regen - run: "./safe.php generate && git diff --exit-code && (echo regen=no-diff >> $GITHUB_OUTPUT) || (echo regen=diff >> $GITHUB_OUTPUT)" + run: "./safe.php generate -vvv && git diff --exit-code && (echo regen=no-diff >> $GITHUB_OUTPUT) || (echo regen=diff >> $GITHUB_OUTPUT)" working-directory: "generator" - name: "Create a pr if the files are different" @@ -56,7 +54,7 @@ jobs: branch: create-pull-request/regenerate-files title: "Automatically regenerate the files" labels: "regenerate, auto" - assignees: "shish, OskarStark, silasjoisten, moufmouf" + # assignees: "shish, OskarStark, silasjoisten, moufmouf" 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 bf0e8fdb..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,11 +57,14 @@ 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); if ($count === 0) { - throw new \RuntimeException('Error when trying to extract parameter type'); + throw new \RuntimeException('Error when trying to extract parameter type: '.$data); } foreach ($returnTypes as &$returnType) { $pos = \strpos($returnType, '?'); @@ -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);