Fix the issues reported by phpcs

Created on 24 May 2023, over 1 year ago
Updated 25 May 2023, over 1 year ago

Problem/Motivation

FILE: ...ontrib/image_field_360/src/Plugin/Field/FieldFormatter/Image_field_360.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------
23 | ERROR | Class name must use UpperCamel naming without underscores
295 | WARNING | t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and
| | $this->t() instead
295 | WARNING | Only string literals should be passed to t() where possible
--------------------------------------------------------------------------------

FILE: ...ution/drupal10/web/modules/contrib/image_field_360/image_field_360.install
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
24 | ERROR | [x] Expected newline after closing brace
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 453ms; Memory: 10MB

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig image_field_360/

Proposed resolution

Fix all the issues and warnings for Drupal and DrupalPractice coding standards.

Remaining tasks

Patch review.

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India urvashi_vora Madhya Pradesh, India

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

  • Issue created by @urvashi_vora
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The src/Plugin/Field/FieldFormatter/Image_field_360.php file has been deleted, but no other file has been added. The error shown in the report does not say that file must be removed; it says the class name must be changed.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India urvashi_vora Madhya Pradesh, India

    Hi @apaderno,

    For the feedback:

    The src/Plugin/Field/FieldFormatter/Image_field_360.php file has been deleted, but no other file has been added. The error shown in the report does not say that file must be removed; it says the class name must be changed.

    I appreciate your efforts in addressing the error regarding the class name and file naming convention. As per the error message, it was necessary to change the class name and subsequently rename the file to ensure that they match. I understand that during this process, the renamed file ended up being untracked in Git, while the deleted file remained tracked. Consequently, when checking the Git diff, only the deleted file was captured, excluding the changes made to the renamed file.

    I have now updated the patch to include both changes. I kindly request you to verify the updated patch to ensure that both modifications are properly reflected. Thank you for your attention to detail and your cooperation in resolving this issue.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    - *   id = "Image_field_360",
    + *   id = "ImageField360",
    

    It is not necessary to change the plugin ID. It is not required to match the class name; furthermore, plugin IDs use snail case. See AggregatorTitleFormatter.php, for example.

    /**
     * Plugin implementation of the 'aggregator_title' formatter.
     *
     * @FieldFormatter(
     *   id = "aggregator_title",
     *   label = @Translation("Aggregator title"),
     *   description = @Translation("Formats an aggregator item or feed title with an optional link."),
     *   field_types = {
     *     "string"
     *   }
     * )
     */
    class AggregatorTitleFormatter extends FormatterBase {
      // …
    }
    
       /**
    -   * Construct a Image_field_360 object.
    +   * Construct a ImageField360 object.
    

    Since that documentation comment is changed, also the description must be changed. The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India urvashi_vora Madhya Pradesh, India

    Reverted plugin ID and added the word "new" in constructor comment.

    Please review.

    Thanks

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The class namespace is still missing, which is what the previous review reported as change too.

    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India urvashi_vora Madhya Pradesh, India

    Please review.

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India Raveen Kumar

    @urvashi, after applying the #patch8, all the phpcs issues seem to be resolved.
    As you can see in my attached screenshot.
    Please & Thank You.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024