diff --git a/.gitattributes b/.gitattributes index 21be40ca..94a1c394 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,8 @@ /.gitattributes export-ignore /.github/ export-ignore /.gitignore export-ignore +/phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore /phpunit.xml.legacy export-ignore /tests/ export-ignore +/types/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 987c25ef..016d6d5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,3 +44,18 @@ jobs: - run: composer self-update --2.2 # downgrade Composer for HHVM - run: hhvm $(which composer) install - run: hhvm vendor/bin/phpunit + + PHPStan: + name: PHPStan + runs-on: ubuntu-20.04 + strategy: + matrix: + php: + - 8.1 + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + - run: composer require phpstan/phpstan + - run: vendor/bin/phpstan diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..609d438c --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + paths: + - types + level: max diff --git a/src/React/Promise/PromiseInterface.php b/src/React/Promise/PromiseInterface.php index 9d23be2e..cfee86bf 100644 --- a/src/React/Promise/PromiseInterface.php +++ b/src/React/Promise/PromiseInterface.php @@ -2,7 +2,13 @@ namespace React\Promise; +/** @template T */ interface PromiseInterface { + /** + * @template TReturn of mixed + * @param callable(T): TReturn $fulfilledHandler + * @return (TReturn is PromiseInterface ? TReturn : PromiseInterface) + */ public function then($fulfilledHandler = null, $errorHandler = null, $progressHandler = null); } diff --git a/types/PromiseInterface.php b/types/PromiseInterface.php new file mode 100644 index 00000000..5fd5e8d8 --- /dev/null +++ b/types/PromiseInterface.php @@ -0,0 +1,9 @@ + $bool; + +assertType('React\Promise\PromiseInterface', resolve(true)); +assertType('React\Promise\PromiseInterface', resolve(true)->then($passThroughBoolFn));