cosmira / soda
Keep your PHP code clean and maintainable by enforcing quality rules based on metrics
Requires
- php: >=8.2
- illuminate/console: ^11.0||^12.0||^13.0
- illuminate/container: ^11.0||^12.0||^13.0
- illuminate/events: ^11.0||^12.0||^13.0
- illuminate/support: ^11.0||^12.0||^13.0
- laravel/prompts: ^0.1.15||^0.2.0||^0.3.0
- nikic/php-parser: ^5.0
- phplrt/parser: ^4.2.4
- phplrt/source: ^4.2.4
- phpunit/php-file-iterator: ^5.1||^6.0||^7.0
- sebastian/complexity: ^4.0||^5.0||^6.0
Requires (Dev)
- driftingly/rector-laravel: ^2.1
- infection/infection: ^0.32.6||^0.35.8
- laravel/pint: ^1.28
- phplrt/compiler: ^4.2.4
- phplrt/lexer-builder: ^4.2.4
- phplrt/parser-builder: ^4.2.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5||^12.0||^13.0
- rector/rector: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master / 1.2.x-dev
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-codex/quiet-research
- dev-codex/release-1.2.0
- dev-codex/trust-internal-control-facts
- dev-codex/project-method-usage
- dev-codex/readable-control-conditions
- dev-codex/research-design-metrics
- dev-codex/exception-rule-checks
- dev-codex/practical-rule-guidance
This package is auto-updated.
Last update: 2026-10-30 14:42:28 UTC
README
Soda checks how your PHP code is organized. It reports oversized methods, nested workflows, repeated decisions, and naming problems with source locations and refactoring advice. Use it alongside your formatter and PHPStan or Psalm.
Get started
Requires PHP 8.2 or later and Composer.
composer require --dev cosmira/soda vendor/bin/soda quality src/
Replace src/ with your source directory. Without a soda.php configuration,
Soda runs its standard rules. Vendor directories are excluded automatically.
A passing check exits with 0; quality violations or input and configuration
errors exit with 1.
Understand a finding
A shipping workflow can be valid PHP and still make the reader follow four nested decisions:
final class ShipOrders { public function ship(array $orders): void { foreach ($orders as $order) { if ($order->isPaid()) { if ($order->isReady()) { if ($order->hasAddress()) { $order->ship(); } } } } } }
Soda's nesting rule reports this method at its standard limit:
src/ShipOrders.php
× Line 10 (ShipOrders::ship)
Control structure nesting: 4 (max 3)
↳ Return early for exceptional paths and extract the nested happy-path behavior into a named method.
A guard keeps the same order of checks and shipping behavior with less nesting:
final class ShipOrders { public function ship(array $orders): void { foreach ($orders as $order) { if (! $order->isPaid() || ! $order->isReady() || ! $order->hasAddress()) { continue; } $order->ship(); } } }
A finding identifies a violation of a selected policy, not necessarily a behavior bug. Review your first findings before deciding how to change your code or rule selection.
Make it part of your project
Choose a configuration: keep the standard bundle in a
short soda.php, or generate editable rule objects with vendor/bin/soda init.
Then use vendor/bin/soda for the same check locally and in CI.
- Installation covers your first check and its results.
- Configuration covers paths, exclusions, and rules.
- Continuous integration covers exit status and JSON reports.
- Documentation has the guides and rule reference.
Contribute
Clone the repository and run composer install. Use php soda in place of
vendor/bin/soda inside this repository. Run composer test for behavioral tests
and composer ci for all project checks.
See Adding a quality rule to contribute a check. For documentation changes, follow the writing template and run its Vale checks.
Soda is available under the MIT license.