Fix the issues reported by phpcs

Created on 5 January 2018, almost 7 years ago
Updated 12 July 2023, over 1 year ago

Problem/Motivation

FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/social_auth_wechat.install
-----------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
-----------------------------------------------------------------------------------------------
 17 | ERROR | [x] Short array syntax must be used to define arrays
 37 | ERROR | [x] Doc comment long description must start with a capital letter
 54 | ERROR | [x] Doc comment long description must start with a capital letter
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------


FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/social_auth_wechat.module
-----------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 1 WARNING AFFECTING 8 LINES
-----------------------------------------------------------------------------------------------
  1 | ERROR   | [x] Missing file doc comment
  3 | ERROR   | [x] When importing a class with "use", do not include a leading \
  5 | ERROR   | [ ] Missing short description in doc comment
  6 | ERROR   | [ ] Missing parameter comment
  6 | ERROR   | [ ] Missing parameter type
  7 | ERROR   | [ ] Missing parameter comment
  8 | ERROR   | [ ] Missing parameter type
  9 | WARNING | [ ] Line exceeds 80 characters; contains 88 characters
  9 | ERROR   | [x] Parameter comment indentation must be 3 spaces, found 1 spaces
 13 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
 13 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "false"
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------


FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Settings/WeChatAuthSettings.php
--------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------
 13 | ERROR | [x] There must be exactly one blank line before the tags in a doc comment
--------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------


FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Controller/WeChatAuthController.php
------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 1 WARNING AFFECTING 6 LINES
------------------------------------------------------------------------------------------------------------
  42 | ERROR   | [ ] Parameter $messenger is not described in comment
  85 | ERROR   | [ ] Unnecessarily gendered language in a comment
  87 | ERROR   | [ ] Unnecessarily gendered language in a comment
 107 | ERROR   | [ ] Namespaced classes/interfaces/traits should be referenced with use statements
 133 | ERROR   | [ ] Description for the @return value is missing
 137 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------


FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Form/WeChatAuthSettingsForm.php
--------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
--------------------------------------------------------------------------------------------------------
 17 | ERROR | [x] Short array syntax must be used to define arrays
 33 | ERROR | [x] Short array syntax must be used to define arrays
 39 | ERROR | [x] Short array syntax must be used to define arrays
 47 | ERROR | [x] Short array syntax must be used to define arrays
 55 | ERROR | [x] Short array syntax must be used to define arrays
--------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------


FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Plugin/Network/WeChatAuth.php
------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 2 WARNINGS AFFECTING 7 LINES
------------------------------------------------------------------------------------------------------
  39 | ERROR   | [x] There must be exactly one blank line before the tags in a doc comment
  65 | ERROR   | [x] You must use "/**" style comments for a member variable comment
  93 | ERROR   | [x] Data types in @param tags need to be fully namespaced
  97 | ERROR   | [ ] Missing parameter comment
 113 | ERROR   | [x] There must be exactly one blank line before the tags in a doc comment
 116 | WARNING | [ ] Line exceeds 80 characters; contains 96 characters
 122 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------

FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Controller/WeChatAuthController.php
------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------
 105 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
------------------------------------------------------------------------------------------------------------

FILE: /home/system/Documents/contribution/social_auth_wechat-2934703/src/Form/WeChatAuthSettingsForm.php
--------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------------------------------
 62 | WARNING | #options values usually have to run through t() for translation
 63 | WARNING | #options values usually have to run through t() for translation
 64 | WARNING | #options values usually have to run through t() for translation
--------------------------------------------------------------------------------------------------------

Time: 38ms; Memory: 6MB

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

RTBC

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia sarguna raj M

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.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Removing a branch is not something can be done with a patch. If a branch needs to be removed, an issue must be created only for that task.

    The issue summary should always describe what the issue is trying to fix and, in the case, of coding standards issues, show which command and arguments have been used, and which report that command shown.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chaitanyadessai Goa

    Please review Patch, checked with below phpcs commands, --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig

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

    The issue summary still does not show which command and which arguments have been used. The status is for the issue summary that needs to be updated.

  • Assigned to nitin_lama
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Issue summary updated.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -core: 8.x
     type: module
    +core_version_requirement: '^8'

    The report does not say that core: 8.x must be removed. Furthermore, core: 8.x and core_version_requirement: '^8' are not equivalent. core_version_requirement is not even recognized before Drupal 8.7.7.

    - * setLoginButtonSettings() method sets up the settings for the login button.
    + * SetLoginButtonSettings() method sets up the settings for the login button.

    Function and method names are not changed in a comment just to make it start with a capitalized word.
    The correct comment is The setLoginButtonSettings() method sets up the settings for the login button.

     /**
      * Implements hook_uninstall().
      *
    - * deleteLoginButtonSettings() method deletes the settings for the login button.
    + * DeleteLoginButtonSettings() method deletes the settings for the login button.
    

    Similar change must be done here.

    +/**
    + * @file
    + * The module file.
    + */
    

    The usual module description is Hook implementations for the [module name] module. where [module name] is replaced by the module name shown in the .info.yml file.

     /**
    - * @param $form
    + * Altering the wechat user form.
    + *
    + * @param aray $form
    + *   The form.
      * @param \Drupal\Core\Form\FormStateInterface $form_state
    - * @param $form_id
    - * Hide email and password field if the current user doesn't have admin users permission
    + *   The current form state.
    + * @param string $form_id
    + *   Hide email and password field if the current user doesn't have admin users
    + *   permission.
      */
     function social_auth_wechat_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    

    Documentation comments for hook implementations are different.

    +  /**
    +   * The configuration factory service.
    +   *
    +   * @var \Drupal\Core\Config\ConfigFactory
    +   */
    +  protected $configFactory;
    

    The configuration factory. is sufficient.

    +   * @param \Drupal\Core\Config\ConfigFactory $configFactory
    +   *   Configuration object.
    

    A definite article is missing in the description.

    -  public function __construct(NetworkManager $network_manager,
    -                              SocialAuthUserManager $user_manager,
    -                              MessengerInterface $messenger) {
    +  public function __construct(
    +    NetworkManager $network_manager,
    +    SocialAuthUserManager $user_manager,
    +    MessengerInterface $messenger,
    +    ConfigFactory $configFactory
    +  ) {

    Method/function declarations are written in a single line.

        * It later sets the permissions that should be asked for, and redirects the
    -   * user to WeChat Accounts to allow him to grant those permissions.
    +   * user to WeChat Accounts to allow it to grant those permissions.
    -   * After the user grants permission, WeChat redirects him to a url specified
    +   * After the user grants permission, WeChat redirects it to a url specified
        * in the WeChat project settings. In this case, it should redirects to
    

    it is not the pronoun used with user. It is better to replace user with users and it with them.
    url is misspelled, since it is an acronym.

    -    /** @var \Drupal\Core\Session\AccountInterface $current_user */
    +    /**
    +     * @var \Drupal\Core\Session\AccountInterface $current_user
    +     */
    +      /**
    +       * @var \Overtrue\Socialite\Providers\WeChatProvider $client
    +       */

    The existing comments are already correct.

    +  /**
        * The request object.
    +   *
        * @var \Symfony\Component\HttpFoundation\Request
        */

    The request. is sufficient.

    -    // Checks if the dependency, the \Overtrue\Socialite\SocialiteManager library, is available.
    +    // Checks if the dependency, the \Overtrue\Socialite\SocialiteManager
    +    // library, is available.

    Checks if \Overtrue\Socialite\SocialiteManager is available. would be sufficient, but it is not necessary to explain what a line containing class_exists($class_name)) after a

    $class_name = '\Overtrue\Socialite\SocialiteManager';
    

    line does.

  • Assigned to sourabhjain
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Let me work on #39 changes.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Fixed the issues mentioned in #39. Please review.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi @sourabhjain,

    I reviewed the changes and after applying your patch #4, confirmed all PHPCS errors have been fixed.

    I ran the following commands:
    1. phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml
    2. phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js

    Attaching screenshots.

    I'm moving this now to RTBC.

    Thanks!

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
     /**
    - * @param $form
    + * Implements hook_form_FORM_ID_alter().
    + *
    + * @param aray $form
    + *   The form.
      * @param \Drupal\Core\Form\FormStateInterface $form_state
    - * @param $form_id
    - * Hide email and password field if the current user doesn't have admin users permission
    + *   The current form state.
    + * @param string $form_id
    + *   Hide email and password field if the current user doesn't have admin users
    + *   permission.
      */
     function social_auth_wechat_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {

    With hook implementations, the documentation comment contains only the description, not also the parameter descriptions.

    +   * @param \Drupal\Core\Config\ConfigFactory $configFactory
    +   *   The Configuration object.

    Configuration must not be capitalized, since it is not the first word in the description.

    -   * After the user grants permission, WeChat redirects him to a url specified
    +   * After the users grants permission, WeChat redirects them to a url specified

    It is After users are granted permission since users receive a new permission; they do not give a new permission.
    Since that comment is changed, it is also specified URL.

       * @return \Symfony\Component\HttpFoundation\RedirectResponse
    +   *   A redirect response returned by controller.

    A definite article is missing before controller.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Fixed the issue mentioned in #44. Please review.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi @sourabhjain,

    I reviewed your changes and all good for me.
    And after applying your patch #44, confirmed no PHPCS errors were found.

    I reran the following commands:
    1. phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml
    2. phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js

    Applied to Social Auth WeChat module with 8.x-2.x-dev version and with the Drupal core version of 9.5.x.

    Attaching screenshots.

    I'm moving this again to RTBC for review.

    Thanks!

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -  $is_wechat_account = substr($form['account']['mail']['#default_value'], -strlen('wechat')) == 'wechat' ? true : false;
    +  $is_wechat_account = substr($form['account']['mail']['#default_value'], -strlen('wechat')) == 'wechat' ? TRUE : FALSE;

    There must be a space between - and strlen.

        * It later sets the permissions that should be asked for, and redirects the
    -   * user to WeChat Accounts to allow him to grant those permissions.
    +   * users to WeChat Accounts to allow it to grant those permissions.
    

    The pronoun for users is them, not it.
    Also, to allow them to grant those permissions is probably not correct, since users receive permissions; they do not grant permissions. In this case, the correct sentence is It later sets the permissions that should be asked for, and redirects users to WeChat Accounts to give them those permissions.

    -    // Checks if the dependency, the \Overtrue\Socialite\SocialiteManager library, is available.
    +    // Checks if \Overtrue\Socialite\SocialiteManager is available.

    Inside functions and methods, verbs are declined on the second person singular (check, not checks).

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bharath-kondeti Hyderabad

    Addressed #46 and updated the patch. Please review

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -  $is_wechat_account = substr($form['account']['mail']['#default_value'], -strlen('wechat')) == 'wechat' ? true : false;
    +  $is_wechat_account = substr($form['account']['mail']['#default_value'], - strlen('wechat')) == 'wechat' ? TRUE : FALSE;

    I apologize: I missed the comma before strlen('wechat'). The code is not subtracting a value from another one; it is making a number negative. The space after - is not necessary.

        * It later sets the permissions that should be asked for, and redirects the
    -   * user to WeChat Accounts to allow him to grant those permissions.
    +   * users to WeChat Accounts to allow them to grant those permissions.

    Apart from changing the used pronoun, the sentence has not been changed as per my previous comment.

    -    // Checks if the dependency, the \Overtrue\Socialite\SocialiteManager library, is available.
    +    // Check if \Overtrue\Socialite\SocialiteManager is available.
         $class_name = '\Overtrue\Socialite\SocialiteManager';
         if (!class_exists($class_name)) {
           throw new SocialApiException(sprintf('The PHP SDK for WeChat OAuth could not be found. Class: %s.', $class_name));
         }

    The change is correct, but that comment can be removed, as there is no need to document what the code that calls class_exists() does.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mrinalini9 New Delhi

    Updated patch #47 by addressing #48, please review it.

    Thanks & Regards,
    Mrinalini

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi,

    I reviewed the changes of @mrinalini9 and confirmed her patch was applied cleanly.

    Checking patch social_auth_wechat.info.yml...
    Checking patch social_auth_wechat.install...
    Checking patch social_auth_wechat.module...
    Checking patch social_auth_wechat.routing.yml...
    Checking patch src/Controller/WeChatAuthController.php...
    Checking patch src/Form/WeChatAuthSettingsForm.php...
    Checking patch src/Plugin/Network/WeChatAuth.php...
    Checking patch src/Settings/WeChatAuthSettings.php...
    Applied patch social_auth_wechat.info.yml cleanly.
    Applied patch social_auth_wechat.install cleanly.
    Applied patch social_auth_wechat.module cleanly.
    Applied patch social_auth_wechat.routing.yml cleanly.
    Applied patch src/Controller/WeChatAuthController.php cleanly.
    Applied patch src/Form/WeChatAuthSettingsForm.php cleanly.
    Applied patch src/Plugin/Network/WeChatAuth.php cleanly.
    Applied patch src/Settings/WeChatAuthSettings.php cleanly.

    After running the phpcs command, there are no PHPCS errors anymore.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig social_auth_wechat

    Please see attached file for reference and moving this now to RTBC.

    Thank you!

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    - * setLoginButtonSettings() method sets up the settings for the login button.
    + * The setLoginButtonSettings() method sets up the settings for login button.

    Since that comment is changed, for login button should be changed to for the login button.

    - * deleteLoginButtonSettings() method deletes the settings for the login button.
    + * The deleteLoginButtonSettings() method deletes the settings for login button.

    The same change should be done there.
    Truly, I would remove the full sentence in both the case, since it is not necessary to explain what the setLoginButtonSettings() method or the deleteLoginButtonSettings() method does because that is already clear from the method name.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    Updated the changes suggested in #51. Please review.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi,

    I applied the patch provided by @sourabhjain and confirmed the Patch applied cleanly without affecting the other coding standards.

    Checking patch social_auth_wechat.info.yml...
    Checking patch social_auth_wechat.install...
    Checking patch social_auth_wechat.module...
    Checking patch social_auth_wechat.routing.yml...
    Checking patch src/Controller/WeChatAuthController.php...
    Checking patch src/Form/WeChatAuthSettingsForm.php...
    Checking patch src/Plugin/Network/WeChatAuth.php...
    Checking patch src/Settings/WeChatAuthSettings.php...
    Applied patch social_auth_wechat.info.yml cleanly.
    Applied patch social_auth_wechat.install cleanly.
    Applied patch social_auth_wechat.module cleanly.
    Applied patch social_auth_wechat.routing.yml cleanly.
    Applied patch src/Controller/WeChatAuthController.php cleanly.
    Applied patch src/Form/WeChatAuthSettingsForm.php cleanly.
    Applied patch src/Plugin/Network/WeChatAuth.php cleanly.
    Applied patch src/Settings/WeChatAuthSettings.php cleanly.

    I attached a screenshot for reference.

    Moving this again to RTBC.
    Thank you!

Production build 0.71.5 2024