orklah/psalm-insane-comparison
Psalm plugin that flags “insane” string-to-number loose comparisons that change behavior in PHP 8 (RFC: Saner string to number comparisons). Helps you find risky == checks like non-empty string vs 0 before upgrading, and suggests safer typing/casts.
php artisan test) and other static analyzers (PHPStan, Pest).info initially) and whitelist known-safe comparisons.composer psalm runs. For large codebases, this could slow down CI.psalm --init-cache) and run in parallel where possible.error vs. info)?is_numeric() checks) that should be excluded?--fail-on-error) or run as a pre-commit check?phpstan/extension-installer + custom rules achieve similar goals with less Psalm dependency?phpunit.xml or composer.json scripts).// app/Console/Commands/RunPsalm.php
public function handle() {
$this->call('vendor:publish', ['--provider' => 'PsalmPluginServiceProvider']);
$this->call('psalm', ['--plugin' => 'orklah/psalm-insane-comparison']);
}
pre-commit (e.g., with husky).composer psalm and review flagged issues. Prioritize high-impact comparisons (e.g., in auth, validation, or payment logic).@var annotations).--fail-on-error (e.g., GitHub Actions):
- name: Psalm Insane Comparisons
run: vendor/bin/psalm --plugin=orklah/psalm-insane-comparison --fail-on-error
psalm.xml includes:
<plugin_class>Orklah\PsalmInsaneComparison\Plugin</plugin_class>
<error_level>3</error_level> <!-- or lower for non-blocking -->
laravel/framework, spatie/laravel-permission).app/Http/Controllers).psalm --stats to track progress.composer update orklah/psalm-insane-comparison).psalm.xml to suppress false positives (e.g., for legacy code).<ignore_errors>
<error>InsaneComparison</error>
<pattern>app/OldLegacyClass.php</pattern>
</ignore_errors>
=== vs. == tradeoffs).--no-cache to rule out stale analysis.find app -name "*.php" | xargs -P 4 vendor/bin/psalm --plugin=orklah/psalm-insane-comparison
--init-cache to speed up repeated runs.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Plugin fails to detect issues | False sense of security | Manually audit critical paths. |
| Psalm crashes on large codebase | CI pipeline failures | Run locally first; split analysis. |
| Over-aggressive flagging |
How can I help you explore Laravel packages today?