ShopX

Menu

24/7 Support
Back to Blog
OpenCart technical support
PHPStan for OpenCart: static analysis of legacy PHP

PHPStan for OpenCart: static analysis of legacy PHP

Static analysis finds defects such as an undefined array key or a possible null value before a shop scenario executes. Start with one OpenCart module and a PHPStan level that the maintainers can review. Run PHP syntax checks against the target version as well. Syntax, type analysis and storefront smoke tests answer different questions about a release.

Practical check. Put PHPStan configuration and a reviewed baseline in the same repository as the module. New diagnostics should lead to a fix or a narrowly documented exception.

Start with one module

Choose the module's owned directories in phpstan.neon and run vendor/bin/phpstan analyse -c phpstan.neon. Configure symbol discovery for the classes your module actually uses. For OpenCart registry properties, use accurate annotations or a small typed adapter. A stub that declares every property as present can hide the missing registration you needed to find.

CheckWhat it showsWhere to verify
PHP lintParse errorsBefore each build
PHPStanType and flow defectsOn the module's CI path
Fixture testsLegacy data shapes and custom rulesDuring CI
Staging smoke testRoutes, permissions, Twig and installed modificationsBefore deployment

Make diagnostics useful in CI

Start typing at the boundary. Validate request fields, configuration, database rows and JSON responses before passing them to business logic. For example, a decoded response can be null, an empty list or a map missing status. A small normalizer can reject invalid shapes and return a well-defined type to the rest of the module. Add fixture tests to cover the accepted and rejected cases.

Generate a baseline only after reviewing configuration and the highest-impact findings. Keep it in version control and enforce no new unreviewed findings for the selected scope. Remove exceptions as legacy issues are fixed. Review changes that broaden suppressions before accepting them. Extend coverage by directory or raise the level once the previous scope produces a stable signal.

Frequently asked questions

Which PHPStan level should we choose?

Use a manageable level for the first module, then increase strictness as your configuration and types improve.

How do we handle registry properties?

Use precise PHPDoc, an adapter or narrow stubs that match the OpenCart build under analysis.

Does a green report cover the checkout flow?

Exercise checkout, database queries and dynamic module hooks in integration or staging tests.

Share:
← Previous
crm prom: a practical guide to connecting and processing orders

Related Posts

Instant deliveryFiles immediately after payment
Regular updatesLatest module versions
Secure paymentProtected purchase
Technical supportWe will help with the setup