Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug generator action #470

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/auto-regenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name: "Auto Regenerate"

on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
push:

jobs:

Expand Down Expand Up @@ -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"
Expand All @@ -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"



2 changes: 1 addition & 1 deletion generator/src/PhpStanFunctions/PhpStanFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion generator/src/PhpStanFunctions/PhpStanParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions generator/src/PhpStanFunctions/PhpStanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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, '?');
Expand All @@ -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);
Expand Down
Loading