Magento coding standard checks with PHP_CodeSniffer

Running the Magento coding standard with PHP_CodeSniffer in CI shows whether custom code and agency deliverables follow Magento conventions before they are accepted. This page covers the options, setup, limits and how to use the findings in contracts.

On this page

Why a Magento coding standard check belongs in acceptance

If you are receiving custom modules or themes from an in-house team or an agency, a Magento coding standard run through PHP_CodeSniffer gives you an objective, repeatable check on whether the code follows the conventions Magento Open Source expects. Teams need it when the code will be merged, deployed or paid for, because a reviewer's opinion is hard to enforce and a failing check is not. Run the check in the same pipeline that builds the deliverable, so a result is attached to each handover rather than discovered during a later review.

The check matters most because of upgrade effort. Adobe's upgrade guide names customizations, extension count, third-party integrations and coding practices as drivers of how much work each upgrade will take, and it recommends upgrading every patch cycle to stay secure and PCI compliant. Code that bypasses framework conventions, relies on deprecated internals or places logic in the wrong layer tends to break at the next upgrade. A standards run will not prove that code is upgrade-safe, but it catches many of the patterns that make upgrades expensive, which is why it belongs in acceptance criteria next to functional tests.

Keep claims about the rule set general. Rule names, sniff groups and the versions that match each Magento release change over time, so confirm the current rule set, its compatible PHP_CodeSniffer version and the standard's installation steps with the coding standard project before you write them into a contract. Ask each delivery team to state which rule set and version they ran, and agree in writing that a failing run blocks acceptance unless each exception is documented and approved.

Which ruleset, scope and severity settings fit each codebase

This table compares the main PHP_CodeSniffer configuration choices for Magento code: ruleset depth, PHP compatibility target, file scope, failure severity and vendor code. Read each row as a decision to make before the first run, since these settings decide which findings appear and which ones block a merge.

DecisionOptionTrade-offWhen to choose it
RulesetFull Magento coding standardCatches the most issues but produces the largest first-run backlogGreenfield custom modules or code that will be reviewed by an agency against the full standard
RulesetSubset of sniffs (for example, security and compatibility only)Fast to adopt, but style drift and some deprecated patterns pass uncheckedInherited codebases with heavy existing debt that need a gate now and cleanup later
PHP compatibility targetSingle PHP version matching the production runtimeMatches what runs live; misses issues if the platform upgrades laterStores with a fixed PHP version and no upgrade planned in the near term
PHP compatibility targetRange covering current and next planned PHP versionFlags syntax and function changes early, but adds findings that may not matter yetTeams planning a platform upgrade, where code must run on both versions during the transition
File scopeCustom modules and themes onlyKeeps findings on code the team owns; ignores custom code placed in unusual pathsMost builds, provided the custom code lives in directories the team controls
File scopeCustom code plus agency deliverables in a separate repositoryCovers all handover code, but requires agreed paths and a consistent layout from the agencyProjects where an agency delivers modules that must pass before acceptance
Severity thresholdBlock the build on errors onlyFew false blockers, but warnings accumulate without a deadlineEarly adoption, when the team needs a working gate within the first sprint
Severity thresholdBlock on errors and warnings in new or changed filesStops new debt without forcing a fix of legacy filesMature teams that want steady improvement without a large cleanup project
Vendor and third-party codeExclude vendor and purchased extensions from the scanKeeps the report focused; hides risky code you did not write and cannot easily changeDefault for most teams, paired with a separate review of purchased extensions
Vendor and third-party codeInclude purchased extensions in a report-only runShows the true state of the codebase without blocking builds on code you cannot fixBuyers assessing extensions before purchase or during a security review

How findings move from a commit to an acceptance decision

The flow starts when a developer or agency pushes a commit that touches custom code. The CI job runs PHP_CodeSniffer with the Magento coding standard on the changed files only, writes a report, and applies a pass or fail gate. A failing run returns to the author for rework, while a passing run goes to a reviewer who decides on acceptance. The report is archived with the build as evidence, so the team can show what was checked and which findings were waived. Check that the gate and the human decision are separate steps in your own pipeline.

Automated checks feed a human acceptance decision, with the report stored as evidence.

Wiring PHP_CodeSniffer into CI for agency deliverables

This sequence turns the Magento coding standard from a suggestion into a gate: every agency commit is scanned on custom paths, violations above an agreed severity fail the build, and the report stays with the pipeline run as evidence. It finishes with proof that the gate actually blocks non-compliant code.

  1. Prepare the build image with the tool and standard

    The platform team adds PHP_CodeSniffer and the Magento coding standard package to the CI build image, pinned to versions that match the PHP version used by the target Magento Open Source release. Install them through Composer in a dev-only dependency set so the production artifact stays clean. Confirm the exact package names, the standard name and the PHP compatibility range against the magento/magento2 repository and the coding standard project documentation before pinning. Done means the image runs the phpcs binary with the Magento standard listed in its installed standards, and the version is recorded in the image build log.

  2. Commit a ruleset file to the repository

    Create a ruleset XML file in the root of the custom code repository that references the Magento standard and names the custom module paths the gate should cover. Keep the ruleset under version control so the agency and the client review the same rules. Confirm the exact reference syntax and the standard identifier in the project documentation, since they differ between tool versions. Done means that running phpcs with the ruleset file, and no other flags, produces the same result on two developer machines and in CI.

  3. Scope the scan to custom paths only

    Limit the scan to the directories the agency wrote, such as app/code vendor namespaces for custom modules and custom theme folders, and exclude core, vendor and generated code. Scanning core or vendor directories produces noise that teams learn to ignore, which weakens the gate. Use the exclude-pattern setting in the ruleset and confirm the path matching behaves as expected on your CI runner. Done means a deliberate violation placed in an excluded path is ignored, and the same violation placed in a custom module path is reported.

  4. Set the severity that fails the build

    Decide which severity levels fail the pipeline and which only appear in the report. Many teams fail on errors and surface warnings without blocking, but the threshold is a contract decision that the client and agency should sign off on in writing. Set the failing severity through the command-line option or the ruleset's report configuration, and confirm the option names in the current PHP_CodeSniffer documentation. Done means the pipeline exit code is non-zero for a planted error and zero for a planted warning, if you chose that threshold.

  5. Publish the report as a pipeline artifact

    Configure the scan to write a machine-readable report, such as an XML or JSON file, and to keep a human-readable copy, then save both as pipeline artifacts with the commit reference in the file name. The report is the evidence that acceptance criteria were checked, so it must survive the build log's retention limits. Confirm the report formats the tool supports and how your CI system names and retains artifacts. Done means each pipeline run exposes a downloadable report, and a reviewer can open it from the merge request without rerunning the scan.

  6. Test the gate with a planted violation

    Add a small, clearly labeled sample file that breaks a rule at the failing severity, push it on a branch, and confirm the pipeline fails at the scan step with the violation listed in the report. Then remove the sample and confirm the pipeline passes. This is illustrative: use a violation that matches your ruleset, such as a code style rule you have enabled. Done means the failing run and the passing run both appear in the pipeline history, and the failing report points to the planted file and line.

  7. Write findings into acceptance criteria

    Add a line to the statement of work or the ticket template that the deliverable passes the committed ruleset at the agreed severity, with the pipeline report attached at handover. Ask the agency to state how it handles waivers, such as who approves a suppression comment and where it is logged. Done means the acceptance checklist names the ruleset version, the failing severity and the artifact location, so both parties can verify the same result without a manual review of every line.

Turning sniffer findings into acceptance criteria

The internal engineering lead owns the pipeline that produces the reports, so acceptance criteria should name the exact ruleset, tool version, branch and report artifact each decision reads from. A clean run should mean the PHP_CodeSniffer job exits without errors on the agreed ruleset, against the commit being delivered, with the report archived as a build artifact. Warnings need a policy set in advance, not case-by-case judgment at merge time.

  • Pin the ruleset: Record the coding standard package and PHP_CodeSniffer versions in the repository, so a rerun later produces the same findings.
  • Gate on errors, track warnings: Fail the build on errors. Compare the warning count with the baseline agreed at kickoff and fail only when it grows.
  • Keep the exception file in version control: Store each accepted exception with its reason, owner and review date in the repository, not in a ticket or email.
  • Define the scan scope: List the custom modules and themes that are checked, and the vendor or generated paths that are excluded, then write that scope into the statement of work.

Confirm that a deliberately introduced error fails the pipeline, so the team knows the gate works before it relies on it.

Suppressions and exemptions that weaken the gate

A coding standard check only protects the code it actually scans, and only as strictly as its ruleset allows. The risks below share one pattern: exemptions added quietly, usually under deadline pressure, that shrink what the gate sees until a green build no longer means much. Each card names the exemption and the control that keeps it visible.

Broad inline suppression comments

A single phpcs:disable comment placed above a class can hide every rule for the whole file, including findings that have nothing to do with the original complaint. Require that each suppression names specific sniff codes and carries a short reason. Review every new suppression line in merge requests, and flag any that cover an entire class or file. Ask agencies to list the suppressions they added in each deliverable.

Magento source repository

Excluding whole directories from the scan

Adding a custom module path or a vendor subfolder to the exclude list removes it from every future run, and the change rarely draws attention because the build stays green. Keep the exclude list in the ruleset file under version control so each addition appears in a diff. Treat new exclude paths as a decision that needs a named owner and a removal date, and confirm the scan still covers every custom module directory after each change.

Severity lowered to pass the build

When a rule fails repeatedly, the fastest fix is often to downgrade it from error to warning, which lets the pipeline pass without any code change. Compare the ruleset against the agreed baseline on every merge request and require sign-off for any severity change. Check that the CI job fails on errors and that warnings are counted in a report someone reads, not discarded.

Skipped payment and customer-data paths

Scans often run only on the modules that were easy to target, leaving out the custom payment method, checkout extensions and customer-data handling code. Map where that logic lives in your repository and confirm it appears in the scan output. Coding standard checks review conventions, not security, so these paths still need separate security testing. Do not let a passing scan on the storefront theme stand in for coverage of those modules.

Reports nobody reviews

A report generated on every build becomes background noise after the first sprint, and findings accumulate until the team stops reading them. Assign an owner for the report, set a rule for how many new warnings a merge request may add, and include open findings in the acceptance criteria for each deliverable. Ask for the report history during a review so you can see whether the count is falling or growing.

Questions buyers ask before adding these checks

What does it cost to add Magento coding standard checks to our pipeline?

The cost is mostly the time of the people doing the work: someone to install and configure the ruleset, wire it into CI, triage the first run and agree exceptions. Costs rise with codebase size, the number of custom modules, how mature your pipeline already is and how many findings need a documented decision. Tooling itself is open source, so the recurring cost is maintenance: updating the ruleset when you upgrade Magento Open Source and reviewing new findings. Ask any partner for a fixed-scope quote that lists the modules in scope, the CI platform, the number of exception decisions expected and the retest included. DeployOpen issues quotes from a written scope rather than a price list.

How long does it take to set up coding standard checks in CI?

Setup time depends on what is already in place. A pipeline with containerized builds and clear module boundaries needs less work than one where custom code sits in a single shared repository with no build stage. The main drivers are the number of custom modules and themes to scan, how many existing findings you must triage before enforcing the check, and how many exceptions need a written reason. Ask for the sequence in the proposal: install the ruleset, run a baseline on current code, agree on enforced severities, then turn on blocking checks for new changes. Duration figures should come from that written plan, not from general estimates.

What must our team provide before a partner starts the work?

A partner needs read access to the repositories that hold custom modules, themes and any agency deliverables, plus access to the CI system where the check will run. You also need one named decision owner who can approve the ruleset, the severity level for each finding type and the exception process. Without that owner, findings pile up and agencies argue about them. Provide the Magento Open Source version you run, your PHP version, and a list of which code is in-house and which comes from agencies or vendors. Confirm the access model with your security team before granting pipeline credentials.

Can our in-house team set up these checks without a partner?

Yes, if you have a developer who knows Magento module structure, your CI system and PHP tooling. The Magento coding standard is an open-source ruleset, so the install and first run are within reach of an internal team. Where internal teams usually struggle is the ruleset policy: deciding which findings block a merge, how to record exceptions and how to keep the configuration consistent across agencies. Plan for someone to own those decisions and review the ruleset after each Magento Open Source upgrade. A partner adds value when you need that work done quickly, across several codebases, or with a documented acceptance process.

Do coding standard checks replace code review or security testing?

No. The checks enforce a consistent set of coding rules, such as style, deprecated calls and certain Magento conventions. They do not understand your business logic, judge whether a change is correct, or find most authorization flaws and injection paths. Code review still catches design problems and context-specific mistakes, and security testing is needed to find exploitable weaknesses in the running store. Treat the checks as an automated first gate that makes human review faster and more focused. Any claim that a ruleset covers security should be tested against your own code before you rely on it.

How should we handle an agency that disputes a finding?

Set the rule before the dispute starts. Put the process in the contract or statement of work: the agency may dispute a finding in writing, the decision owner rules on it, and the outcome is either a fix, a documented exception with a reason and an expiry date, or a ruleset change that applies to all code. Do not let agencies silence rules by editing the ruleset in their own branch. Keep exceptions in version control so they are reviewable. A written process reduces friction because each finding gets the same treatment regardless of which agency wrote the code.

Which findings should block a merge and which should only be reported?

Start with a small set of blocking rules that are clearly wrong in your environment, such as syntax errors, deprecated APIs that your Magento Open Source version no longer supports and direct use of the object manager in code paths where you require dependency injection. Report style issues without blocking until the team agrees on them. Confirm the rule list against the Magento Open Source version you run, because supported PHP and framework versions change with each release. Review the severity map at every upgrade, since a rule that matters on one release line may not on the next.

Limits to confirm in your environment

The sniffer only reports what its ruleset and runtime can see, so several inputs decide whether a clean run means anything. Confirm the release line, rules, code scope, runner, output and upgrade behavior before you write acceptance criteria that depend on the results.

Target release line and PHP version

Start by fixing the Magento Open Source release line and PHP version your custom code must run on. Adobe's 2.4.9 requirements list PHP 8.5, while 2.4.8-p5 accepts PHP 8.4 or 8.3, so a ruleset tuned to one line can give misleading results on another. Ask your agency which line and PHP version their code was written and tested against, and record it in the acceptance criteria.

System requirements

Ruleset version match

Confirm that the coding standard package version in your composer.json matches the release line you target, and that its PHP compatibility sniffs cover the PHP version in use. Ask the coding standard maintainers which versions they support for each Magento line and how they document breaking rule changes. Test one known-bad sample file on a branch to confirm the expected rules fire.

Generated and third-party code scope

Decide whether the scan covers app/code only or also generated classes, vendor packages and purchased extensions. Scanning vendor code usually produces findings the team cannot fix, while excluding it can hide problems in extensions you installed. Confirm the exclude paths with your agency, write them into the sniffer configuration, and test that an excluded path does not appear in the report.

CI runner PHP extensions

The sniffer and its standards need specific PHP extensions and a matching Composer version. Adobe's 2.4.9 requirements list Composer 2.10 alongside PHP 8.5, so confirm that the CI runner image provides that PHP version, the extensions Magento itself needs, and Composer. Run the check on a sample branch in the same runner image used for production builds, and fail the job if the tool exits with a setup error instead of a clean result.

Report format for your tools

Check whether the output format the sniffer writes fits the tools that consume it, such as the CI dashboard, the ticket system and your security evidence folder. Choose a format your pipeline can parse, and confirm that line numbers and file paths resolve correctly in the code review tool. Ask the agency to deliver the report in the same format for each agency handover, so findings can be compared across releases.

Rule updates during upgrades

Rulesets change when Magento moves to a new release line or when the standard adds rules, so a branch that passed last quarter may fail after an upgrade. Ask the maintainers how they publish rule changes and whether they mark deprecated sniffs. Agree in writing who updates the ruleset during each upgrade, how new findings are triaged, and whether a rule change needs its own change record before the build is accepted.

How coding standard results carry through upgrades

Sniffer results matter most when an upgrade is being scoped, so keep a baseline report for each release of your custom code. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, and it names customizations, extension count, third-party integrations and coding practices as the drivers of upgrade effort. A stored baseline, generated from the same ruleset and PHP_CodeSniffer version each time, lets you see which findings are new since the last cycle, which were fixed, and which modules concentrate the work. Store the report as a build artifact alongside the commit it was run against, and record the ruleset version in the file header or in a phpcs.xml file committed to the repository. Confirm with your own team how long old artifacts must be retained for audit purposes.

Run the Upgrade Compatibility Tool alongside the sniffer, not instead of it. The two answer different questions: the sniffer checks whether your code follows the coding standard, while the Upgrade Compatibility Tool, which Adobe's upgrade guide references, is aimed at compatibility problems in customizations and extensions when moving between releases. A clean sniffer baseline does not show that a module still works against a new core version, and a passing compatibility scan does not show that code meets the standard. Put both outputs in the upgrade acceptance criteria, and treat any new finding from either tool as a scoped work item before the upgrade branch is merged.

Decide when to adopt a new ruleset version deliberately rather than on every update. Upgrading the ruleset in the same change as a core upgrade makes it hard to tell whether a new finding comes from your code or from the rule change, so schedule ruleset upgrades as their own change with a before-and-after report. Agree on a policy in writing: for example, new rules apply to new code immediately, while existing code is grandfathered through a documented exception list that shrinks over time. Ask your agency or DeployOpen-style implementation partner to state in the statement of work which ruleset version and configuration will be used at handover, and to deliver the baseline report with the code.

How DeployOpen works on this

DeployOpen plans and builds self-hosted Magento Open Source stores, so coding standard checks run on your custom modules and themes as part of the same delivery you already commission. We set the scope in writing, wire the checks into your pipeline in infrastructure you control, and hand over the rules, reports and fix records your team needs to keep the code clean.

How we scope

  • We list which custom modules, themes and agency deliverables the check covers, and which vendor code it excludes.
  • We agree the coding standard rule set and the Magento version the code must target before any build work starts.
  • We define which findings block a merge, which are tracked as warnings, and who approves any exceptions, in writing.

How we build

  • We add PHP_CodeSniffer with the Magento coding standard to your CI pipeline, running on your own runners or build servers.
  • We configure the ruleset file and ignore patterns in version control so every developer and every pipeline run applies the same rules.
  • We test the pipeline against sample code with known violations, then confirm failures block the build as the agreed scope requires.

How we hand over

  • You receive the ruleset configuration, pipeline definition and a short runbook explaining how to run the checks locally and in CI.
  • You receive a findings baseline for the existing code, with each open issue mapped to a module and an owner.
  • Acceptance criteria reference specific standard checks and report output, so agency deliverables can be accepted or returned against written rules.

How we support

  • Engagements are fixed-scope, so changes to rules, pipeline or covered code are agreed in writing before work starts.
  • Ongoing support, rule updates when Magento releases change, and continuous checking are available as a retainer.
  • Ask us to confirm the standard and tooling versions that match your target Magento release line before the pipeline is accepted.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.