From 8e292e71a84e13d7e7a784b4f070c38e484aebb5 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Sun, 17 Mar 2024 17:44:53 +0200 Subject: [PATCH] Fix broken generation --- generator/composer.json | 2 +- generator/composer.lock | 27 ++++++++++--------- .../src/PhpStanFunctions/PhpStanFunction.php | 2 +- .../src/PhpStanFunctions/PhpStanParameter.php | 2 +- .../src/PhpStanFunctions/PhpStanType.php | 9 ++++++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/generator/composer.json b/generator/composer.json index cb85fae8..97e94540 100644 --- a/generator/composer.json +++ b/generator/composer.json @@ -19,7 +19,7 @@ "thecodingmachine/phpstan-strict-rules": "^1.0", "squizlabs/php_codesniffer": "^3.2", "php-coveralls/php-coveralls": "^2.1", - "phpstan/phpstan": "^1.5" + "phpstan/phpstan": "^1.10.40" }, "scripts": { "test": "vendor/bin/phpunit", diff --git a/generator/composer.lock b/generator/composer.lock index a840c7b1..5228e3ce 100644 --- a/generator/composer.lock +++ b/generator/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d6c94263becd754b8ce74fbcf96c6508", + "content-hash": "a43476896e0a54cafaec559e0b9a68f6", "packages": [ { "name": "psr/container", @@ -1596,16 +1596,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.5.0", + "version": "1.10.62", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "2be8dd6dfa09ab1a21c49956ff591979cd5ab29e" + "reference": "cd5c8a1660ed3540b211407c77abf4af193a6af9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2be8dd6dfa09ab1a21c49956ff591979cd5ab29e", - "reference": "2be8dd6dfa09ab1a21c49956ff591979cd5ab29e", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd5c8a1660ed3540b211407c77abf4af193a6af9", + "reference": "cd5c8a1660ed3540b211407c77abf4af193a6af9", "shasum": "" }, "require": { @@ -1629,9 +1629,16 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.5.0" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -1642,16 +1649,12 @@ "url": "https://github.com/phpstan", "type": "github" }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, { "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", "type": "tidelift" } ], - "time": "2022-03-24T18:18:00+00:00" + "time": "2024-03-13T12:27:20+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3962,5 +3965,5 @@ "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/generator/src/PhpStanFunctions/PhpStanFunction.php b/generator/src/PhpStanFunctions/PhpStanFunction.php index c6054de2..442f44ac 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 signoatures'); } - $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..d7cd027d 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);