Fix PHPCS coding standard violations in CI pipeline

Created on 27 October 2025, 3 months ago
Updated 29 November 2025, 2 months ago

Problem/Motivation

The GitLab CI pipeline is currently failing due to phpcs (PHP CodeSniffer) errors detected when validating against Drupal and Slevomat coding standards.

Excerpt from latest CI job

PHP CODE SNIFFER REPORT SUMMARY
-----------------------------------------------------------------------------
FILE                                                         ERRORS  WARNINGS
-----------------------------------------------------------------------------
src/PrintfulSyncBatch.php                                    4       0
src/Commands/CommercePrintfulCommands.php                    1       0
src/Exception/PrintfulException.php                          1       0
src/Form/PrintfulStoreForm.php                               2       0
src/Form/PrintfulSynchronizationForm.php                     6       0
src/Plugin/Commerce/ShippingMethod/PrintfulShipping.php      1       0
src/Plugin/Field/FieldWidget/PrintfulReferenceWidget.php     1       0
src/Service/OrderIntegrator.php                              1       0
src/Service/Printful.php                                     2       0
src/Service/ProductIntegrator.php                            1       0
-----------------------------------------------------------------------------
A TOTAL OF 20 ERRORS AND 0 WARNINGS WERE FOUND IN 26 FILES
-----------------------------------------------------------------------------
PHPCBF CAN FIX 20 OF THESE SNIFF VIOLATIONS AUTOMATICALLY

Violation summary by sniff source

Drupal.Functions.MultiLineFunctionDeclaration.MissingTrailingComma                 (6)
Drupal.Commenting.FunctionComment.ReturnCommentIndentation                         (3)
SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator.NullCoalesceOperatorNotUsed  (3)
Drupal.Commenting.FunctionComment.ParamCommentIndentation                          (2)
Drupal.ControlStructures.ControlSignature.NewlineAfterCloseBrace                    (2)
Drupal.Commenting.DocComment.TagGroupSpacing                                        (1)
Drupal.WhiteSpace.ScopeIndent.IncorrectExact                                        (1)
SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing (1)
Squiz.WhiteSpace.SuperfluousWhitespace.EndLine                                      (1)

Steps to reproduce

  1. Run the GitLab CI pipeline on the 3516944-add-gitlab-ci branch.
  2. Observe the phpcs job fails with exit code 2.
  3. Open the job log or download the junit.xml artifact for details.

Expected result

phpcs passes with no coding standard violations.

Actual result

phpcs reports 20 errors across 10 files, all of which can be automatically fixed.

Proposed resolution

  • Run the PHP Code Beautifier and Fixer (PHPCBF) to automatically correct violations:
vendor/bin/phpcbf web/modules/custom/commerce_printful
  • Verify all changes maintain functionality.
  • Commit and push the fixed code to rerun the pipeline.

Key fixes include

  • Adding trailing commas to multi-line function declarations.
  • Correcting docblock @param and @return indentation.
  • Adding blank line between @param and @return tags.
  • Replacing ternary operators with null coalesce operators (??).
  • Ensuring nullable type hints for parameters with null defaults.
  • Fixing whitespace and indentation issues.
📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom c_archer Cumbria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024