thecodingmachine/phpstan-safe-rule
PHPStan rule set that flags calls to “unsafe” PHP functions that can return false on failure and suggests using the thecodingmachine/safe equivalents that throw exceptions, helping enforce safer, exception-based error handling in your codebase.
false-returning functions like file_get_contents()) that could lead to silent failures, reducing production incidents tied to null/undefined behavior.thecodingmachine/safe or migrating legacy codebases to stricter type safety.strpos() without null checks) during refactoring.Safe\file_get_contents()) by default in PRs.preg_replace without PREG_SET_ORDER flags).thecodingmachine/safe or plan to migrate to it—this package automates compliance checks.false-returning functions, deprecated APIs).phpmd).Executives:
"This integrates with our existing PHPStan setup to block critical bugs before they reach production—like null pointer exceptions or unsafe file operations—without adding runtime costs. It’s a zero-effort upgrade to our quality gates, reducing incident response time and improving developer velocity. For example, it caught [X] silent failures in [Y] legacy modules during our last migration."
Engineering (Devs/Tech Leads):
"Drop-in for PHPStan: 1 line in
composer.json+ 1 line inphpstan.neonstarts flagging unsafe patterns likestrpos($null)orfile_get_contents()without checks. Works alongsidethecodingmachine/safeto enforce consistent error handling. Run it in CI to fail builds on unsafe code—no false positives if configured right. Example: [Show before/after PR diff with violations highlighted]."
Security/Quality Teams:
"Reduces attack surface by eliminating
false-returning functions (e.g.,strpos,json_decode) that can mask errors. Integrates with our existing toolchain—no new infrastructure. Example: Found [Z] vulnerabilities in [legacy module] by catching unsafe regex patterns."
How can I help you explore Laravel packages today?