From 22779a05ce684bd58f82e7f1d0225f2f877e14b8 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 28 Nov 2024 11:05:00 +0100 Subject: [PATCH 1/5] Debug generator action --- .github/workflows/auto-regenerate.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/auto-regenerate.yml b/.github/workflows/auto-regenerate.yml index b128e6cb..10510d44 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: From 9cd9f9b84f13b7df5920725dc4eb2c4040fd01f7 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 28 Nov 2024 11:14:09 +0100 Subject: [PATCH 2/5] Improve error message --- generator/src/PhpStanFunctions/PhpStanType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/PhpStanFunctions/PhpStanType.php b/generator/src/PhpStanFunctions/PhpStanType.php index bf0e8fdb..1a9f3dfb 100644 --- a/generator/src/PhpStanFunctions/PhpStanType.php +++ b/generator/src/PhpStanFunctions/PhpStanType.php @@ -61,7 +61,7 @@ public function __construct(string $data, bool $writeOnly = false) /** @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, '?'); From d41c519de4c44db8c5f237b74d229e30131b6b42 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 28 Nov 2024 11:16:45 +0100 Subject: [PATCH 3/5] run generate very verbose --- .github/workflows/auto-regenerate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-regenerate.yml b/.github/workflows/auto-regenerate.yml index 10510d44..dc890754 100644 --- a/.github/workflows/auto-regenerate.yml +++ b/.github/workflows/auto-regenerate.yml @@ -43,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" From 5b86a97218322479f7f82c6d86fbbfd07a701971 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Sun, 17 Mar 2024 17:44:53 +0200 Subject: [PATCH 4/5] Fix broken generation --- generator/src/PhpStanFunctions/PhpStanFunction.php | 2 +- generator/src/PhpStanFunctions/PhpStanParameter.php | 2 +- generator/src/PhpStanFunctions/PhpStanType.php | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) 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); From 53750af3e73382d6b153bddb83ecd09c310e8e40 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 28 Nov 2024 11:38:41 +0100 Subject: [PATCH 5/5] disable assignees for now --- .github/workflows/auto-regenerate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-regenerate.yml b/.github/workflows/auto-regenerate.yml index dc890754..9adeebfe 100644 --- a/.github/workflows/auto-regenerate.yml +++ b/.github/workflows/auto-regenerate.yml @@ -54,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"