Fix the warnings/errors reported by PHP_CodeSniffer

Created on 2 March 2020, over 4 years ago
Updated 31 July 2023, over 1 year ago

While submitting fixes to โœจ Remove Generator meta tag from output Closed: works as designed I noticed coding standards were in a bit of a state and opened this issue to tidy things up and make changes easier to submit. There was #2894089: Fix coding standards โ†’ for 7.x but it was long.

Tasks

- Make the module code pass phpcs --standard=Drupal

๐Ÿ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Patch Failed to Apply
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom mcdruid ๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡บ

    Unfortunately these patches tend to need a lot of rerolls... and this one apparently does.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    34 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Rerolled the latest patch @mcdruid. Please review and merge.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Since the issue summary suggest to use phpcs --standard=Drupal to fix the coding standard errors, it should also show which warnings/errors PHP_CodeSniffer reports.

    The status is also for the issue summary that needs to be updated.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.0.7 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    34 pass
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom mcdruid ๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡บ

    Thanks - seems there were quite a few other Code Sniffer fixes not covered by this patch.

    I've tried to do all of them in this patch.. which I expect will now conflict with changes being made in ๐Ÿ“Œ Add phpcs and drupal-check fixes Needs work but unfortunately these issues that make a lot of small changes are always tricky to land.

    If this patch passes tests, we'll get these committed and all of the current Code Sniffer problems will be fixed.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    34 pass
    • mcdruid โ†’ committed db84d6db on 2.x
      Issue #3117054 by xurizaemon, sourabhjain, lucasbaralm, mcdruid, Deepthi...
  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom mcdruid ๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡บ

    I realise there's been quite a lot of discussion in this issue about the changes like this:

    -      $x_frame_allow_from = $form_state->getValue(['seckit_clickjacking', 'x_frame_allow_from']);
    +      $x_frame_allow_from = $form_state->getValue([
    +        'seckit_clickjacking',
    +        'x_frame_allow_from',
    +      ]);
    

    Although I agree that the change doesn't necessarily improve readability here, it's much easier overall to maintain the code if we have completely clean results from Code Sniffer, as opposed to maintaining a list of checks that we've decided to ignore.

    The current standards do mention splitting arrays onto multiple lines like this when otherwise the line length exceeds 80:

    https://www.drupal.org/docs/develop/standards/php/php-coding-standards#a... โ†’

    ... if the line declaring an array spans longer than 80 characters (often the case with form and menu declarations), each element should be broken into its own line, and indented one level ...

    Are these lines declaring arrays? We could debate that, but as mentioned I'll go back to the argument that a totally clean Code Sniffer result is desirable for ease of maintenance.

    Thank you everybody that worked on this.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024