Fix the issues reported by phpcs

Created on 10 April 2023, about 1 year ago
Updated 29 February 2024, 4 months ago

Problem/Motivation

Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules
$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml field_config_cardinality.

FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\field_config_cardinality\field_config_cardinality.module
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
155 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
| | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
156 | WARNING | Line exceeds 80 characters; contains 89 characters
156 | ERROR | Doc comment short description must be on a single line, further text should be a separate paragraph
215 | WARNING | Hook implementations should not duplicate @param documentation
215 | ERROR | Missing parameter comment
215 | ERROR | Missing parameter type
236 | WARNING | Line exceeds 80 characters; contains 81 characters
258 | WARNING | Line exceeds 80 characters; contains 84 characters
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\field_config_cardinality\src\Plugin\Field\FieldWidget\CardinalityEntityReferenceAutocompleteWidget.php
---------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------------------
10 | WARNING | Line exceeds 80 characters; contains 96 characters
11 | ERROR | Doc comment short description must be on a single line, further text should be a separate paragraph
21 | WARNING | Line exceeds 80 characters; contains 99 characters
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 284ms; Memory: 10MB

Steps to reproduce

Run the phpcs command on the module.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia sidharth_soman Bangalore

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

Merge Requests

Comments & Activities

  • Issue created by @sidharth_soman
  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sidharth_soman Bangalore

    Finding coding standard issues as detailed in the issue summary. I will work on fixing them.

  • Merge request !7Fixed phpcs issues. โ†’ (Open) created by sidharth_soman
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sidharth_soman Bangalore

    I have fixed all of the issues except for those relating to documentation. I have issued the MR against the 8.x-1.x branch.
    Please review.

  • Issue was unassigned.
  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines kenyoOwen

    Hi sidharth_soman

    I applied your MR and confirmed that it resolved the issues except for those related to documentation. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
      * @param $form
    - * @param FormStateInterface $form_state
    + * @param \Drupal\Core\Form\FormStateInterface $form_state
      * @param $form_id
      */
     function field_config_cardinality_form_alter(&$form, FormStateInterface $form_state, $form_id) {

    What the report says is that for hook implementation, parameters are not described. In fact, the short description for a hook implementation and sole part of its documentation comment is totally different.

    - * @param FormStateInterface $form_state
    + * @param \Drupal\Core\Form\FormStateInterface $form_state
      */
    -function field_config_cardinality_form_builder($entity_type, \Drupal\field\Entity\FieldConfig $config, &$form, FormStateInterface $form_state) {
    +function field_config_cardinality_form_builder($entity_type, FieldConfig $config, &$form, FormStateInterface $form_state) {
       if ($form_state->getValue('cardinality') === 'number' && $form_state->getValue('cardinality_number')) {
         $cardinality_config = $form_state->getValue('cardinality_number');
       }

    The same holds true here.

     /**
    - * Implements hook_form_alter().
    + * Implements hook_form_FORM_ID_alter().
      *
      * @param $elements
    - * @param FormStateInterface $form_state
    + * @param \Drupal\Core\Form\FormStateInterface $form_state
      * @param $context
      */
     function field_config_cardinality_field_widget_multivalue_form_alter(&$elements, FormStateInterface $form_state, $context) {

    Those @param tags are not necessary.

    -  // Implementation for multi managed_file
    +  // Implementation for multi managed_file.
       if (!empty($elements['#type']) && $elements['#type'] == 'managed_file') {
         if (!empty($cardinality_config) && $cardinality_config >= 1) {
           if ($elements['#delta'] > $cardinality_config - 1) {
    @@ -215,7 +216,7 @@ function field_config_cardinality_field_widget_multivalue_form_alter(&$elements,
         }
       }
     
    -  // Implementation for multi select type
    +  // Implementation for multi select type.
       if (!empty($elements['#type']) && $elements['#type'] == 'select') {

    I would rather remove those comments, since they describe something that is already clear from the code.

    +/**
    + *
    + */
     class CardinalityMediaLibraryWidget extends MediaLibraryWidget {

    Either the documentation comment is not empty or it is not added.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia zkhan.aamir

    zkhan.aamir โ†’ made their first commit to this issueโ€™s fork.

  • Shruu_rao โ†’ made their first commit to this issueโ€™s fork.

  • First commit to issue fork.
  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sakthi_dev

    Addressed the comment in #8. Please review.

Production build 0.69.0 2024