wyrihaximus/phpstan-react
PHPStan extension for ReactPHP projects that flags blocking PHP functions (e.g., file_get_contents, fopen, fread) and suggests async React alternatives from react/filesystem, react/socket, and react/stream. Include the provided ruleset to enforce non-blocking code.
Install the package as a dev dependency and configure PHPStan to include its rules. Begin by identifying blocking synchronous functions in your ReactPHP codebase that should be replaced with async equivalents. The default configuration highlights functions like file_get_contents, sleep, and fopen — flagging them as violations.
composer require wyrihaximus/phpstan-react --dev
Then in phpstan.neon:
includes:
- vendor/wyrihaximus/phpstan-react/phpstan-reactphp-rules.neon
Run vendor/bin/phpstan analyse — the output will list offending synchronous calls with suggested ReactPHP replacements.
file_get_contents() is flagged, refactor to use React\Filesystem\Node\FileInterface::getContents(), ensuring the callback/promise-based signature is handled correctly.phpstan.neon’s ignoreErrors or errorLevel to gradually tighten checks — start at level 1 (errorLevel: 1) to catch only critical blocking calls, then elevate.gethostbyname() → ResolverInterface::resolve() from react/dns) as quick reference cheat-sheets during pair programming or code reviews.--fix support. Be prepared to manually refactor, ideally with tests in place first.file_exists() may be unavoidable in initial setup logic (e.g., before spawning reactor), but still flagged. Add them to ignoreRules with comments justifying their use.react/filesystem v1 vs v2). A mismatch may yield incorrect suggestions or miss cases.-c and --debug: Use phpstan analyse -c phpstan.neon --debug to trace why a function was flagged, especially if the NEON config includes other extensions.How can I help you explore Laravel packages today?