Search by

wyrihaximus / phpstan-react

WyriHaximus

👎 ReactPHP extension for PHPStan

Package info

github.com/WyriHaximus/phpstan-reactphp

pkg:composer/wyrihaximus/phpstan-react

Fund package maintenance!

WyriHaximus

Statistics

Installs: 735 270

Dependents: 2

Suggesters: 0

Stars: 2

Open Issues: 4

2.0.0 2025-04-26 22:37 UTC

This package is auto-updated.

Last update: 2026-09-27 20:18:38 UTC


README

Continuous Integration Latest Stable Version Total Downloads License

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require wyrihaximus/phpstan-react

Usage

The rules in this package are automatically loaded by PHPStan when phpstan/extension-installer is installed.

Include the rules file from the root of this package to have PHPStan check your code for blocking functions, event loop misuse, and react/async fiber misuse. Every rule is enabled by default; see Configuration to turn rules off.

includes:
	- vendor/wyrihaximus/phpstan-react/extension.neon

Functions

fclose

file_exists

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\AdapterInterface::detect

Documentation:

file_get_contents

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\Node\FileInterface::getContents

Documentation:

file_put_contents

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\Node\FileInterface::putContents

Documentation:

fopen

Relevant package(s):

  • react/filesystem
  • react/socket

Suggested replacement(s):

  • React\Filesystem\Node\FileInterface::getContents
  • React\Socket\Connector::connect

Documentation:

fread

Relevant package(s):

  • react/stream

Suggested replacement(s):

  • React\Stream\ReadableStreamInterface::on

Documentation:

fwrite

Relevant package(s):

  • react/stream

Suggested replacement(s):

  • React\Stream\WritableStreamInterface::write

Documentation:

gethostbyname

Relevant package(s):

  • react/dns

Suggested replacement(s):

  • React\Dns\ResolverInterface::resolve

Documentation:

is_dir

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\AdapterInterface::detect

Documentation:

is_file

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\AdapterInterface::detect

Documentation:

is_link

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\AdapterInterface::detect

Documentation:

mkdir

Relevant package(s):

  • react/filesystem

Suggested replacement(s):

  • React\Filesystem\Node\NotExistInterface::createDirectory

Documentation:

sleep

Relevant package(s):

  • react/promise-timer

Suggested replacement(s):

  • React\Promise\Timer\sleep

Documentation:

time_nanosleep

Relevant package(s):

  • react/promise-timer

Suggested replacement(s):

  • React\Promise\Timer\sleep

Documentation:

time_sleep_until

Relevant package(s):

  • react/promise-timer

Suggested replacement(s):

  • React\Promise\Timer\sleep

Documentation:

usleep

Relevant package(s):

  • react/promise-timer

Suggested replacement(s):

  • React\Promise\Timer\sleep

Documentation:

Event loop

Do not hand the loop around. Use the static proxies on React\EventLoop\Loop instead of calling API methods on Loop::get() or on any other LoopInterface instance.

See the event loop documentation and the react/event-loop package.

Loop::get() method calls

PHPStan reports when you invoke loop API methods through Loop::get(), for example Loop::get()->addTimer(...). Use the matching static proxy on Loop instead, for example Loop::addTimer(...).

Error identifiers use the prefix wyrihaximus.reactphp.eventLoop.staticProxy..

Loop instance method calls

PHPStan reports when you invoke loop API methods on a value typed as React\EventLoop\LoopInterface, for example $loop->addTimer(...) where $loop was injected or returned from a factory. Use the matching static proxy on Loop instead.

Error identifiers use the prefix wyrihaximus.reactphp.eventLoop.instance..

Passing loop instances

PHPStan reports when you pass a value typed as React\EventLoop\LoopInterface into any call, for example acceptLoop(Loop::get()) or new Service($loop). Do not inject or forward the loop; use the static proxies on Loop at the call site that needs the event loop API.

Error identifier: wyrihaximus.reactphp.eventLoop.passLoopInterface.

LoopInterface properties

PHPStan reports when a class or trait declares a property typed as React\EventLoop\LoopInterface, including constructor-promoted properties and @var annotations on untyped properties. Do not store the loop on the object; use the static proxies on Loop where the event loop API is needed.

Error identifier: wyrihaximus.reactphp.eventLoop.propertyLoopInterface.

Async

Every closure calling React\Async\await has to be wrapped in React\Async\async where that closure is defined. Wrapping a closure further up the call stack, or wrapping it after the fact, does not count: by the time the closure runs there is no guarantee it is still on the fiber the wrapping set up.

The same goes for closures reaching React\Async\await through the methods and functions they call: the entire call stack starting in the closure runs on the fiber React\Async\async sets up, so every closure leading to an await needs that wrapping.

See the async documentation and the react/async package.

Await inside a non-async closure

PHPStan reports when React\Async\await is called inside a closure that is not wrapped in React\Async\async at the point where that closure is defined.

Error identifier: wyrihaximus.reactphp.async.awaitWithoutAsync.

Await reached through the call stack

PHPStan reports when a non-async closure calls into code that eventually awaits, including through interfaces, static methods, functions, and constructors. The error tip points at the await site further down the stack.

Error identifier: wyrihaximus.reactphp.async.awaitReachedWithoutAsync.

await

Relevant package(s):

Suggested replacement(s):

  • React\Async\async

Documentation:

Configuration

All rules from this extension are on by default. Override them under parameters.wyrihaximus.reactphp.rules in your PHPStan config. Omitting the block keeps every rule enabled.

Parameter Disables
blockingFunctions Blocking function diagnostics (wyrihaximus.reactphp.blocking.function.*)
loopStaticProxies Loop::get() method calls (wyrihaximus.reactphp.eventLoop.staticProxy.*)
loopInstances Loop instance method calls (wyrihaximus.reactphp.eventLoop.instance.*)
passLoopInterface Passing LoopInterface into calls (passLoopInterface)
loopInterfaceProperties Declaring LoopInterface properties (propertyLoopInterface)
asyncAwaitInClosure Direct await in non-async closures (awaitWithoutAsync)
asyncAwaitReachableViaCallStack Transitive await via the call stack (awaitReachedWithoutAsync)

For a single diagnostic, use PHPStan ignoring errors with the identifiers documented above.

Full configuration example

parameters:
	level: max
	paths:
		- src
		- tests
	wyrihaximus:
		reactphp:
			rules:
				blockingFunctions: true
				loopStaticProxies: true
				loopInstances: true
				passLoopInterface: true
				loopInterfaceProperties: true
				asyncAwaitInClosure: true
				asyncAwaitReachableViaCallStack: false

License

The MIT License (MIT)

Copyright (c) 2026 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.