Standardizing Code Quality Across WebRT PHP and Laravel Projects
A software project is not just about writing code that works.
As an application grows, new features are added, existing code is refactored, integrations are introduced, and more and more changes are made over time. Without a consistent verification process, projects can gradually accumulate style issues, incorrect types, architectural problems, and code that becomes increasingly difficult to maintain.
That is why, within the WebRT ecosystem, we are standardizing how we validate the quality of PHP and Laravel projects.
The idea is simple:
Every project should be able to automatically verify its code quality, with the main checks available through a single command:
composer test.
The standard is designed for both plain PHP projects and Laravel applications. Laravel projects can additionally use checks that are specific to the framework.
Why have a common standard?
When you have multiple projects, it is inefficient for every project to have its own testing and quality process.
One project uses Pest.
Another uses PHPStan.
Another only has PHPUnit.
Another has custom Composer scripts that were written years ago and nobody remembers exactly what they check.
There is nothing necessarily wrong with having different configurations.
The problem appears when you need to work quickly across multiple projects and every project behaves differently.
Within the WebRT ecosystem, we want the basic workflow to be predictable.
That is why we established a common set of Composer scripts:
setuplinttest:linttest:spellingtest:type-coveragetest:typestest:archtest:unittest:unit:sequentialtest
The test script aggregates these checks and runs them in sequence.
This means that, regardless of the project, the main entry point is the same:
composer test
What does composer test check?
The standard combines several different types of validation.
We do not rely on a single tool to tell us that a project is "OK".
Each tool checks a different category of potential problems.
1. Code style and refactoring
For code formatting and refactoring we use Laravel Pint and Rector.
Pint handles PHP code formatting and consistency.
Rector is used for automated transformations and refactoring.
Within test:lint, these tools are used in verification mode so we can detect whether the project follows the established rules.
The goal is not simply to make the code look nice.
Consistent code means that when you open a project again after several months, the code remains familiar and predictable.
2. Static analysis with PHPStan and Larastan
Unit tests cannot identify every possible problem.
Code can pass all existing tests and still contain issues that can be detected through static analysis.
This is where PHPStan comes in.
For Laravel projects we use Larastan, which adds Laravel-specific understanding and rules.
The standard configuration includes the Larastan extension so that the analysis can understand concepts such as Eloquent, facades, and the Laravel container.
For a plain PHP project without Laravel, the Laravel-specific part is not required, but the principle remains the same:
static analysis should help us find problems before they reach production.
It can identify issues such as:
- incompatible types;
- potentially
nullvalues; - non-existent methods;
- incorrect return types;
- properties that do not exist;
- problems between classes and their dependencies.
3. Type coverage
Another level of verification is type coverage.
The standard uses Pest for this:
pest --type-coverage --min=100
The goal is 100% type coverage for what is being checked by the suite.
Why is this important?
Explicit types make code easier to understand for both developers and automated tools.
Well-typed code is easier to:
- analyze;
- refactor;
- test;
- maintain;
- hand over to another developer.
4. Unit testing with Pest
For the actual tests, we use Pest.
The standard runs unit tests with coverage and, by default, in parallel:
XDEBUG_MODE=coverage pest --parallel --coverage --exactly=100.0
The standard targets 100% coverage for unit tests.
There is an important distinction here:
100% coverage does not automatically mean 100% bug-free software.
Coverage tells us that the relevant lines have been executed by tests.
It does not tell us whether the tests themselves are good enough.
That is why coverage should be treated as a quality control tool, not as the only measure of software quality.
5. Architecture testing
A project can have good tests and still end up with an architecture that becomes increasingly difficult to maintain.
That is why the standard also includes test:arch.
We use Pest Architecture to enforce rules related to the structure of the project.
For example, we can verify that:
dd(),dump(),ray()orvar_dump()are not used in production code;- certain classes extend the appropriate base classes;
- certain components do not directly depend on other components;
- project-specific architectural rules are respected.
The initial architecture setup includes examples of these types of rules.
The important part is that architecture is no longer just a rule written in a document.
It becomes an executable rule.
6. Spelling
One small but useful detail: spelling is checked as well.
For this we use Peck:
composer test:spelling
The script is included directly in the Composer standard.
Real projects contain a lot of text:
- messages;
- documentation;
- interface text;
- comments;
- identifiers;
- other user-facing content.
It is not the most important check in the suite, but it is inexpensive to run and can eliminate unnecessary mistakes.
Everything through a single command
The main advantage of the standard is that we do not need to remember every individual command.
We have:
composer test
│
├── lint
├── spelling
├── type coverage
├── static analysis
├── architecture
└── unit tests + coverage
Composer allows scripts to call other scripts from the same composer.json using the @script-name syntax.
The result is a very simple interface:
composer test
If it passes, we know that the standard verification suite has passed.
If it fails, we have a clear starting point for investigation.
What happens with a new project?
For a new PHP or Laravel project, the standard can be introduced immediately after the project is created.
The required development packages are installed in require-dev:
composer require --dev rector/rector laravel/pint larastan/larastan pestphp/pest pestphp/pest-plugin-type-coverage peckphp/peck
For a plain PHP project, the configuration needs to be adapted so that Laravel-specific dependencies or commands are not introduced unnecessarily.
For example, Larastan is relevant to Laravel, while the broader quality philosophy applies to PHP projects in general.
Likewise, if a project has no frontend and no npm or package.json, Node-related commands should not be included in the Composer scripts.
What about existing projects?
This is where we take a different approach.
We do not want to blindly replace the configuration of an existing project.
An older project may already have:
- custom Composer scripts;
- PHPStan configuration;
- project-specific rules;
- special build steps;
- deployment requirements.
That is why existing projects use a separate retrofit process.
The first step is to run composer test, if it already exists, and record the result as a baseline.
Then we inspect each standard key.
The rules are:
The key does not exist → add it.
The key already matches the standard → leave it unchanged.
The key exists but is different → do not overwrite it automatically. Review the difference and decide which version should remain.
This is particularly important for older projects.
Standardization should not break an existing configuration simply because we want every composer.json to look the same.
Baseline before modification
For an existing project, comparing the state before and after the change is extremely important.
For example:
Before: composer test → OK
Change
After: composer test → OK
We have:
OK → OK
and we know that the retrofit did not introduce a regression.
If we have:
FAIL → FAIL
and the errors are the same, the problems already existed.
But:
OK → FAIL
means that our modification introduced a problem and it needs to be investigated before the project can be considered updated.
This is much safer than modifying composer.json and simply hoping everything will continue to work.
Standardization without rigidity
A standard does not mean that every project has to be identical.
PHP is a broad ecosystem.
Some projects are Laravel applications.
Others are plain PHP.
Some have a frontend and npm.
Others are backend applications or APIs with no JavaScript build step.
Some older projects have their own configuration that needs to be preserved.
The standard should provide a common foundation, not ignore the reality of each project.
That is why we distinguish between initializing a new project and retrofitting an existing one.
New projects can adopt the standard immediately, while existing projects are updated gradually and safely.
Why is this worth doing?
Because software is not finished when it "works".
It is simply at a point where it works.
After that come:
- changes;
- bug fixes;
- new features;
- refactoring;
- framework upgrades;
- PHP upgrades;
- integrations;
- new developers;
- and increasingly, code generated or modified with AI.
The more a project evolves, the more we need automated verification.
A standard like this creates guardrails around the codebase.
It does not replace developer experience.
It does not replace code review.
It does not guarantee that the application has no bugs.
But it significantly reduces the number of problems that can go unnoticed.
And then there is AI
There is another reason why this becomes increasingly important.
Today, we do not necessarily write every line of code manually.
We increasingly use AI for:
- code generation;
- refactoring;
- feature implementation;
- test generation;
- documentation;
- debugging.
This can dramatically increase development speed.
But speed without verification can also mean accumulating problems faster.
An automated standard covering linting, static analysis, type coverage, architecture testing, and unit testing provides an additional level of control.
Regardless of who — or what — generated the change, the final question remains the same:
composer test
Does it pass or not?
Conclusion
Within the WebRT ecosystem, the goal is to establish a common quality standard for PHP and Laravel projects, built around:
- Pint;
- Rector;
- PHPStan/Larastan;
- Pest;
- Pest Type Coverage;
- Pest Architecture;
- Peck;
- Composer scripts.
New projects start with the standard.
Existing projects are migrated gradually, using a baseline and verification before and after changes.
And the central interface remains extremely simple:
composer test
One command for an entire suite of quality checks.
For us, this is the difference between:
"The code works right now."
and:
"We have an automated process that helps keep the codebase healthy as the project evolves."
The standard is inspired, among other things, by the setup presented by Nuno Maduro and adapted to the way we work within the WebRT ecosystem.
Tribute: @nunomaduro
Github: WebRT Testing Skills