Drupal Coding Standards Issues | phpcs

Created on 6 February 2023, over 1 year ago

Problem/Motivation

Get the following phpcs error/warnings

arisen.fernandes@C02FD2HPML7H redoc_field_formatter % phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml .

FILE: /Users/arisen.fernandes/Sites/dten/dten/web/modules/contrib/redoc_field_formatter/redoc_field_formatter.info.yml
----------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------
 1 | WARNING | Remove "project" from the info file, it will be added by drupal.org packaging automatically
 1 | WARNING | Remove "version" from the info file, it will be added by drupal.org packaging automatically
----------------------------------------------------------------------------------------------------------------------


FILE: /Users/arisen.fernandes/Sites/dten/dten/web/modules/contrib/redoc_field_formatter/src/Plugin/Field/FieldFormatter/RedocUIFormatter.php
--------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------
 61 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------------------------------------------------

Time: 140ms; Memory: 10MB

Steps to reproduce

  1. Clone the Redoc Field Formatter project in your drupal installation
  2. Switch to branch 3.0.x
  3. From the module folder execute phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml .
  4. Observe the coding standard errors.

Proposed resolution

Fix the phpcs errors and implement dependency injection as required.

Remaining tasks

  1. Test the patch on 3.0.x branch
  2. Install the module on drupal 10 site and test the Redoc UI functionality

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇳India arisen Goa

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

Comments & Activities

  • Issue created by @arisen
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India arisen Goa

    Added the patch. Please review.

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India mrinalini9 New Delhi

    Hi,

    I have reviewed patch #2 (on the 3.0.x branch) with drupal version: 10.0.0, it applied cleanly and fixed all coding standards issues as mentioned above.

    Checking patch redoc_field_formatter.info.yml...
    Checking patch src/Plugin/Field/FieldFormatter/RedocUIFormatter.php...
    Applied patch redoc_field_formatter.info.yml cleanly.
    Applied patch src/Plugin/Field/FieldFormatter/RedocUIFormatter.php cleanly.

    Also, tested the Redoc UI functionality, and it's working fine.

    I have followed below mentioned testing steps:
    1. Install and set up the drupal 10 site.
    2. Go to the modules folder and clone the Redoc Field Formatter project.
    3. Switch to branch 3.0.x.
    4. Execute: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml .
    5. Observe the coding standard errors.
    6. Now, apply patch #2.
    7. Again repeat step 4, you can see that the coding standards errors are fixed.
    8. Now, install the module and clear all cache.
    9. Then, create any content type and add a field of type as "File" in "Manage Fields". Make sure to add "json", "yml" in "Allowed file extensions" while using "File" type.
    10. Now, go to the manage display tab of this content type.
    11. Under File fields, select as "Redoc UI" formatter in the dropdown.
    12. Then, create any content by using this content type.
    13. Now, go to the page you have created now and check the Redoc UI formatter. Refer to this screenshot:

    Thanks & Regards,
    Mrinalini

    • arisen authored eccf748e on 3.0.x
      Issue #3339502 by arisen, mrinalini9: Drupal Coding Standards Issues |...
  • Status changed to Fixed over 1 year ago
  • 🇮🇳India arisen Goa

    Thank you Mrinalini for the review. Committed the fixes to the Drupal 10 dev branch.

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

Production build 0.69.0 2024