Fix the errors/warnings reported by Php_CodeSniffer

Created on 26 June 2023, over 1 year ago
Updated 3 January 2024, 11 months ago

Problem/Motivation

FILE: /Users/specbee/Sites/Projects/analytics/analytics_google/src/Plugin/AnalyticsService/GoogleAnalyticsGa.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 34 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/analytics_amp/src/Plugin/AnalyticsService/AmpAnalytics.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 6 WARNINGS AFFECTING 8 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
 36 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 41 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 42 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 47 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 55 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 58 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 76 | ERROR   | [x] Missing function doc comment
 90 | ERROR   | [x] Missing function doc comment
---------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/analytics_amp/src/Plugin/AnalyticsService/AmpTrackingPixel.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 34 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/analytics.module
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | ERROR | [x] Missing file doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/analytics_piwik/src/Plugin/AnalyticsService/Piwik.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 5 WARNINGS AFFECTING 7 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 34 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 35 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 38 | ERROR   | [x] No space found before comment text; expected "// '#element_validate' => [$this->validateUrl]," but found "//'#element_validate' => [$this->validateUrl],"
 43 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 52 | ERROR   | [x] Visibility must be declared on method "validateUrl"
 52 | ERROR   | [x] Missing function doc comment
 60 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 63 | WARNING | [ ] Unused variable $request.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Form/AnalyticsServiceForm.php
-------------------------------------------------------------------------------
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
-------------------------------------------------------------------------------
   7 | WARNING | [x] Unused use statement
   8 | WARNING | [x] Unused use statement
  15 | ERROR   | [x] Missing class doc comment
 136 | ERROR   | [x] Missing function doc comment
-------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Entity/AnalyticsService.php
-----------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------
 168 | ERROR | [ ] Description for the @return value is missing
 174 | ERROR | [x] Expected 1 newline at end of file; 3 found
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServiceDataTrait.php
-----------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
-----------------------------------------------------------------------------
  5 | ERROR | [x] Missing trait doc comment
  7 | ERROR | [ ] Missing short description in doc comment
  8 | ERROR | [ ] Description for the @return value is missing
 12 | ERROR | [ ] Missing short description in doc comment
 13 | ERROR | [ ] Description for the @return value is missing
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServicePluginCollection.php
------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
------------------------------------------------------------------------------------
  8 | ERROR   | [x] Missing class doc comment
 37 | ERROR   | [ ] Description for the @return value is missing
 39 | WARNING | [ ] Possible useless method overriding detected
------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServicePluginBase.php
-----------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
-----------------------------------------------------------------------------------------------------
  22 | ERROR   | [ ] Missing member variable doc comment
  74 | ERROR   | [x] Missing function doc comment
 156 | ERROR   | [x] Parameter comment must end with a full stop
 167 | WARNING | [x] A comma should follow the last multiline array item. Found: 'amp/amp.analytics'
 212 | WARNING | [ ] Unused variable $json.
-----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServicePluginInterface.php
-----------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------
 55 | ERROR | Missing short description in doc comment
 56 | ERROR | Description for the @return value is missing
-----------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/Render/AnalyticsJsMarkup.php
------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
------------------------------------------------------------------------------
 18 | ERROR | Missing short description in doc comment
 21 | ERROR | Visibility must be declared on property "$isDntEnforced"
 23 | ERROR | Missing short description in doc comment
 47 | ERROR | Description for the @return value is missing
------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/AnalyticsServiceListBuilder.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
  5 | WARNING | [x] Unused use statement
  8 | WARNING | [x] Unused use statement
  9 | WARNING | [x] Unused use statement
 10 | WARNING | [x] Unused use statement
 68 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 75 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
---------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/specbee/Sites/Projects/analytics/src/EventSubscriber/ConfigSubscriber.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 12 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------

Time: 366ms; Memory: 10MB

Steps to reproduce

Run following command
phpcs --standard=โ€œDrupal,DrupalPracticeโ€ --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js .

๐Ÿ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

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 @sonam_sharma
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    Raveen Thakur โ†’ made their first commit to this issueโ€™s fork.

  • Open on Drupal.org โ†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • @raveen-thakur opened merge request.
  • Issue was unassigned.
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    The issue summary should always describe what should be fixed/changed. Neither the title nor screenshots are sufficient to describe what the issue is, even in the case a patch is provided.
    In the case of a bug, the description should also list the steps necessary to reproduce the issue, starting from when the module/theme is installed.

    Also, since that would be reported by PHP_CodeSniffer, why is not this issue about fixing the warnings/errors reported by PHP_CodeSniffer?

  • Assigned to imustakim
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Issue summary updated.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Patch re-rolled with updated changes, only these errors are remaining now.

    FILE: /Users/specbee/Sites/Projects/analytics/analytics.module
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     3 | ERROR | Missing short description in doc comment
    ----------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/analytics_piwik/src/Plugin/AnalyticsService/Piwik.php
    ---------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------
     52 | ERROR   | Doc comment is empty
     66 | WARNING | Unused variable $request.
    ---------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/src/Form/AnalyticsServiceForm.php
    -------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    -------------------------------------------------------------------------------
      13 | ERROR | Doc comment is empty
     137 | ERROR | Doc comment is empty
    -------------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/src/Entity/AnalyticsService.php
    -----------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------
     168 | ERROR | Description for the @return value is missing
    -----------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServiceDataTrait.php
    -----------------------------------------------------------------------------
    FOUND 5 ERRORS AFFECTING 5 LINES
    -----------------------------------------------------------------------------
      5 | ERROR | Doc comment is empty
     10 | ERROR | Missing short description in doc comment
     11 | ERROR | Description for the @return value is missing
     15 | ERROR | Missing short description in doc comment
     16 | ERROR | Description for the @return value is missing
    -----------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/src/Plugin/ServicePluginCollection.php
    ------------------------------------------------------------------------------------
    FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
    ------------------------------------------------------------------------------------
      8 | ERROR   | Doc comment is empty
     40 | ERROR   | Description for the @return value is missing
     42 | WARNING | Possible useless method overriding detected
    ------------------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/analytics/src/Render/AnalyticsJsMarkup.php
    ------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------
     25 | ERROR | Missing short description in doc comment
    ------------------------------------------------------------------------------
    
    Time: 340ms; Memory: 10MB
    
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org โ†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Bhupesh_upadhyay

    I have fixed most of the issue mentioned above
    kindly review.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +/**
    + * @file
    + * Contains implementation of analytics functionality for Drupal.
    + */
    +

    A .module description is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

    +  /**
    +   * Validates the config URL.
    +   *
    +   * @param array $element
    +   *   elements form URL.
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   Drupal\Core\Form\FormStateInterface.
    +   */
       protected function elementValidateConfigUrl(array &$element, FormStateInterface $form_state) {
         $value = $element['#value'];
         if ($value == '') {
    @@ -87,6 +95,14 @@ class AmpAnalytics extends ServicePluginBase {
         }
       }
     
    +  /**
    +   * Validates the config JSON.
    +   *
    +   * @param array $element
    +   *   elements form Json.
    +   * @param \Drupal\Core\Form\FormStateInterface $form_state
    +   *   Drupal\Core\Form\FormStateInterface.
    +   */
       protected function elementValidateConfigJson(array &$element, FormStateInterface $form_state) 

    For form validation and submission handlers, only the short description is given, and that is Form validation handler for [form ID]. or Form submission handler for [form ID].

        * @return \Drupal\analytics\AnalyticsServiceManager
    +   *   analytics service.

    A definite article is missing in that description.

     /**
    - * Analytics ConfigSubscriber.
    + * Analytics Config Subscriber class.
      */

    That description is still merely repeating the class name, like the existing documentation comment.

    +/**
    + * Analytics Form.
    + */
     class AnalyticsServiceForm extends EntityForm {
    

    That does not describe the class purpose. Form is also misspelled, since it is not the first word in the description, it is not an acronym, or a proper noun.

    +/**
    + * Service Data.
    + */

    That description is not sufficient.

       /**
    -   * @return array
    +   * Default Data.
        */
       abstract public function defaultData();

    That description does not say much about what that method does.
    Removing the @return line is also not correct, since parameters and return value must be described too.

    +  /**
    +   * The has multiple check.
    +   *
    +   * @var bool
    +   *  Returns true if there are are multiple config entity.

    The description does not make sense.

    true, as PHP value, is misspelled.
    are is repeated.
    there are needs a plural direct object, but config entity is singular.

    +/**
    + * Analytics Service Plugin collection.
    + */

    Service and Plugin are misspelled, since they are not the first word.

        * @return \Drupal\analytics\Plugin\ServicePluginInterface
    +   *   service Instance id

    Instance and id are misspelled.
    Since it returns a \Drupal\analytics\Plugin\ServicePluginInterface instance, the return value cannot be an ID.

       /**
    +   * Do not track protection static variable.
    +   *
        * @var bool
        */
    -  static $isDntEnforced;
    +  protected static $isDntEnforced;

    That is not the description for that property.
    There is not need to say that a property is a variable. None of the property used in Drupal core classes is described as variable.

        * @return bool
    +   *   True if Do Not Track protection is enabled.

    As PHP value, True is misspelled.

  • First commit to issue fork.
Production build 0.71.5 2024