Address warnings for PHP_CodeSniffer in phpcs gitlab ci job

Created on 23 August 2025, 19 days ago

Problem/Motivation

Viewing the most recent build of this codebase reveals the issue.

[0KRunning with gitlab-runner 17.6.0 (374d34fd)[0;m
[0K  on gitlab-runner-7ff84fc474-7jz5s s8ex1X2yJ, system ID: r_K8GFCFaqUvlO[0;m
[0K[36;1mResolving secrets[0;m[0;m
section_start:1733177215:prepare_executor
[0K[0K[36;1mPreparing the "kubernetes" executor[0;m[0;m
[0K"CPURequest" overwritten with "2"[0;m
[0KUsing Kubernetes namespace: gitlab-runner[0;m
[0KUsing Kubernetes executor with image drupalci/php-8.3-ubuntu-apache:production ...[0;m
[0KUsing attach strategy to execute scripts...[0;m
section_end:1733177215:prepare_executor
[0Ksection_start:1733177215:prepare_script
[0K[0K[36;1mPreparing environment[0;m[0;m
[0KUsing FF_USE_POD_ACTIVE_DEADLINE_SECONDS, the Pod activeDeadlineSeconds will be set to the job timeout: 1h0m0s...[0;m
Waiting for pod gitlab-runner/runner-s8ex1x2yj-project-59632-concurrent-1-t1o3b6d9 to be running, status is Pending
Running on runner-s8ex1x2yj-project-59632-concurrent-1-t1o3b6d9 via gitlab-runner-7ff84fc474-7jz5s...

section_end:1733177245:prepare_script
[0Ksection_start:1733177245:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m[0;m
[32;1mFetching changes...[0;m
Initialized empty Git repository in /builds/project/date_ap_style/.git/
[32;1mCreated fresh repository.[0;m
[32;1mChecking out 5cda2f4f as detached HEAD (ref is 2.x)...[0;m

[32;1mSkipping Git submodules setup[0;m

section_end:1733177245:get_sources
[0Ksection_start:1733177245:download_artifacts
[0K[0K[36;1mDownloading artifacts[0;m[0;m
[32;1mDownloading artifacts for composer (3561920)...[0;m
Downloading artifacts from coordinator... ok      [0;m  host[0;m=drupal-gitlab-job-artifacts.s3.us-west-2.amazonaws.com id[0;m=3561920 responseStatus[0;m=200 OK token[0;m=glcbt-64

section_end:1733177253:download_artifacts
[0Ksection_start:1733177253:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m[0;m
[32;1m$ test -f phpcs.xml.dist || curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/assets/phpcs.xml.dist[0;m
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   320  100   320    0     0   4687      0 --:--:-- --:--:-- --:--:--  4705
[32;1m$ vendor/bin/phpcs --version[0;m
PHP_CodeSniffer version 3.11.1 (stable) by Squiz and PHPCSStandards
[32;1m$ composer show | awk '$0 ~ /codesniffer|coder|coding-standard|variable-analysis/ {print $1 " " $2}';[0;m
dealerdirect/phpcodesniffer-composer-installer 1.0.0
drupal/coder 8.3.26
sirbrillig/phpcs-variable-analysis 2.11.21
slevomat/coding-standard 8.15.0
squizlabs/php_codesniffer 3.11.1
[32;1m$ vendor/bin/phpcs --config-show installed_paths[0;m
Using config file: /builds/project/date_ap_style/vendor/squizlabs/php_codesniffer/CodeSniffer.conf

installed_paths: ../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard
[32;1m$ vendor/bin/phpcs -i[0;m
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard
[32;1m$ vendor/bin/phpcs -s $_WEB_ROOT/modules/custom --report-junit=junit.xml --report-full --report-summary --report-source $_PHPCS_EXTRA[0;m

FILE: ...modules/custom/date_ap_style/tests/src/Kernel/ApStyleDateFormatterTest.php
--------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------------
 495 | ERROR | [x] Comments may not appear after statements
     |       |     (Drupal.Commenting.PostStatementComment.Found)
 496 | ERROR | [x] Comments may not appear after statements
     |       |     (Drupal.Commenting.PostStatementComment.Found)
 508 | ERROR | [x] Expected 1 blank line after function; 0 found
     |       |     (Squiz.WhiteSpace.FunctionSpacing.AfterLast)
 509 | ERROR | [x] Expected 1 newline at end of file; 3 found
     |       |     (Drupal.Files.EndFileNewline.TooMany)
 509 | ERROR | [x] The closing brace for the class must have an empty line
     |       |     before it
     |       |     (Drupal.Classes.ClassDeclaration.CloseBraceAfterBody)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...ate_ap_style/web/modules/custom/date_ap_style/src/ApStyleDateFormatter.php
--------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
 397 | ERROR | [x] Parameter $langcode has null default value, but is not
     |       |     marked as nullable.
     |       |     (SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing)
 443 | ERROR | [x] Parameter $fieldtype has null default value, but is not
     |       |     marked as nullable.
     |       |     (SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing)
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 288ms; Memory: 8MB


PHP CODE SNIFFER REPORT SUMMARY
--------------------------------------------------------------------------------
FILE                                                            ERRORS  WARNINGS
--------------------------------------------------------------------------------
...b/modules/custom/date_ap_style/src/ApStyleDateFormatter.php  2       0
...date_ap_style/tests/src/Kernel/ApStyleDateFormatterTest.php  5       0
--------------------------------------------------------------------------------
A TOTAL OF 7 ERRORS AND 0 WARNINGS WERE FOUND IN 9 FILES
--------------------------------------------------------------------------------
PHPCBF CAN FIX 7 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
--------------------------------------------------------------------------------
    SOURCE                                                                 COUNT
--------------------------------------------------------------------------------
[x] Drupal.Commenting.PostStatementComment.Found                           2
[x] SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.Null  2
[x] Drupal.Classes.ClassDeclaration.CloseBraceAfterBody                    1
[x] Drupal.Files.EndFileNewline.TooMany                                    1
[x] Squiz.WhiteSpace.FunctionSpacing.AfterLast                             1
--------------------------------------------------------------------------------
A TOTAL OF 7 SNIFF VIOLATIONS WERE FOUND IN 5 SOURCES
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SOURCES AUTOMATICALLY (7 VIOLATIONS IN TOTAL)
--------------------------------------------------------------------------------


section_end:1733177254:step_script
[0Ksection_start:1733177254:upload_artifacts_on_failure
[0K[0K[36;1mUploading artifacts for failed job[0;m[0;m
[32;1mUploading artifacts...[0;m
junit.xml: found 1 matching artifact files and directories[0;m 
Uploading artifacts as "archive" to coordinator... 201 Created[0;m  id[0;m=3561922 responseStatus[0;m=201 Created token[0;m=glcbt-64
[32;1mUploading artifacts...[0;m
junit.xml: found 1 matching artifact files and directories[0;m 
Uploading artifacts as "junit" to coordinator... 201 Created[0;m  id[0;m=3561922 responseStatus[0;m=201 Created token[0;m=glcbt-64

section_end:1733177255:upload_artifacts_on_failure
[0Ksection_start:1733177255:cleanup_file_variables
[0K[0K[36;1mCleaning up project directory and file based variables[0;m[0;m

section_end:1733177256:cleanup_file_variables
[0K[31;1mERROR: Job failed: command terminated with exit code 1
[0;m

Steps to reproduce

1. Push code to the 2.x branch.
2. Wait for GitLab pipeline to run.
3. Observe job failure on PHP CodeSniffer step.
Go to https://git.drupalcode.org/project/date_ap_style/-/jobs/3561922

Proposed resolution

Run the suggested `phpcbf` command to fix coding standard violations.

Remaining tasks

- Run the suggested `phpcbf` command.
- Create merge request with fixes.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024