Skip to content

[2.x] Add basic template annotations#227

Closed
WyriHaximus wants to merge 1 commit intoreactphp:2.xfrom
WyriHaximus-secret-labs:2.x-add-basic-template-annotations
Closed

[2.x] Add basic template annotations#227
WyriHaximus wants to merge 1 commit intoreactphp:2.xfrom
WyriHaximus-secret-labs:2.x-add-basic-template-annotations

Conversation

@WyriHaximus
Copy link
Member

@WyriHaximus WyriHaximus commented Jun 21, 2022

This adds basic type safety annotations for static analyzers like PHPStan and Psalm. This will cover around 80% of the use cases and a follow-up PR for all supported versions will be proposed later to get it to a 100% of close to a 100%.

By adding these annotations methods returning a promise can hint their resolving type by adding @return PromiseInterface<bool> when they for example resolve to a boolean. By doing that Psalm and PHPStan will understand that the following bit of code will not become an issue because the method's contract promised a boolean through the promise:

$promise->then(static function (bool $isEnabled) {});

However, the following will yield errors:

$promise->then(static function (string $isEnabled) {});

This PR is a requirement for reactphp/async#40

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants