Skip to content

Conversation

@clue
Copy link
Member

@clueclue commented Jun 20, 2023

This changeset adds PHPStan on max level to the test environment for all supported PHP versions. Unlike previous attempts, it runs the maximum level supported with all errors addressed without having to resort to a baseline. The changeset size seems reasonable and this does not other affect our public API, so this should be safe to apply.

If this PR is merged, we could backport most of the changes from v3 to v2 and v1. The changes are somewhat similar across all versions, but v2 and v1 still supports legacy PHP, so we would have to resort to type definitions in docblocks instead of native PHP types. Let's continue this discussion outside of this PR.

Builds on top of clue/framework-x#200, clue/framework-x#201, clue/framework-x#221, reactphp/async#76 and reactphp/async#77
See also https://github.com/orgs/reactphp/discussions/469

@clueclue added this to the v3.0.0 milestone Jun 20, 2023
SimonFrings
SimonFrings approved these changes Jun 21, 2023
@WyriHaximusWyriHaximus merged commit d66fa66 into reactphp:3.xJun 21, 2023
@WyriHaximus
Copy link
Member

@clue Awesome! Will get the 3.x PR with template types ready 👍

@clueclue deleted the phpstan-v3 branch June 21, 2023 15:19
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jun 28, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 2, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 4, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 4, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 4, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 4, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 5, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 5, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 5, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 7, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 8, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 9, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 10, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 10, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 10, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
WyriHaximus pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 11, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
clue pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 11, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
clue pushed a commit to WyriHaximus-secret-labs/promise that referenced this pull request Jul 11, 2023
Adds template annotations turning the `PromiseInterface` into a generic. Variables `$p1` and `$p2` in the following code example both are `PromiseInterface<int|string>`. ```php $f = function (): int|string{return time() % 2 ? 'string' : time()}; /** * @return PromiseInterface<int|string> */ $fp = function (): PromiseInterface{return resolve(time() % 2 ? 'string' : time())}; $p1 = resolve($f()); $p2 = $fp(); ``` When calling `then` on `$p1` or `$p2`, PHPStan understand that function `$f1` is type hinting its parameter fine, but `$f2` will throw during runtime: ```php $p2->then(static function (int|string $a){}); $p2->then(static function (bool $a){}); ``` Builds on top of reactphp#246 and reactphp#188 and is a requirement for reactphp/async#40
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@clue@WyriHaximus@SimonFrings