New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

cosmira/soda

Keep your PHP code clean and maintainable by enforcing quality rules based on metrics
1,083 2
Install
composer require cosmira/soda
Latest Version:v2.0.0
PHP:>=8.2
Laravel:11 · 12 · 13
License:MIT
Last Updated:Nov 16, 2026
Links: GitHub  ·  Packagist
Maintainer: tabuna

Soda

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.

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.

Related Packages

octane-doctor/octane-doctor

Octane readiness scanner for Laravel: detect long-lived worker risks, explain ea...

44 1
cline/analyzer

Configurable parallel PHP code analyzer for checking class references

29,575 0
heyosseus/sloppy

Static analysis for the debt AI coding agents leave behind, on any PHP project:...

127,959 239
sajjadhossainshohag/laravel-artican

Code Health Checker for Laravel — catch broken routes, missing views, schema mis...

2,918 16
renoki-co/laravel-exporter-contracts

Base contracts implementation for Prometheus exports in Laravel.

175,584 5

Version History

Version Released PHP Laravel License
v2.0.0 >=8.2 ^11.0||^12.0||^13.0 MIT
v1.6.0 >=8.2 ^11.0||^12.0||^13.0 MIT
v1.5.0 >=8.2 ^11.0||^12.0||^13.0 MIT
v1.4.2 >=8.2 ^11.0||^12.0||^13.0 MIT
v1.4.1 >=8.2 ^11.0||^12.0||^13.0 MIT