Fix the issues reported by phpcs

Created on 10 March 2023, almost 2 years ago
Updated 22 November 2023, about 1 year ago

Problem/Motivation

Getting following error/warnings.

FILE: /var/www/html/modules/contrib/private_message_invite/private_message_invite.links.menu.yml
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
5 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/private_message_invite.links.action.yml
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
6 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/private_message_invite.permissions.yml
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
7 | ERROR | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/private_message_invite.info.yml
-------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------
1 | WARNING | Remove "project" from the info file, it will be added by drupal.org packaging automatically
1 | WARNING | Remove "datestamp" 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: /var/www/html/modules/contrib/private_message_invite/private_message_invite.routing.yml
---------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
32 | ERROR | [x] Expected 1 newline at end of file; 0 found
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/private_message_invite.services.yml
----------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
6 | ERROR | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/src/Form/ConfigForm.php
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
113 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/src/Form/PrivateMessageIniviteForm.php
-------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------
52 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
95 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
110 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
125 | WARNING | Unused variable $values.
144 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/src/Controller/PrivateMessageInviteController.php
------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
------------------------------------------------------------------------------------------------------------
24 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
40 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
50 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
55 | WARNING | Unused variable $message.
57 | WARNING | Unused variable $message.
60 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
69 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/private_message_invite/src/EventSubscriber/PrivateMessageinviteSubscriber.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------
74 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
86 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
-----------------------------------------------------------------------------------------------------------------

Time: 1.8 secs; Memory: 6MB

Steps to reproduce

Run following command

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml modules/contrib/private_message_invite/

Proposed resolution

Above error/warnings need to be fixed.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India samit.310@gmail.com

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 @samit.310@gmail.com
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India samit.310@gmail.com

    Above error/warnings has been fixed.

  • Status changed to RTBC almost 2 years ago
  • 🇮🇳India hardikpandya

    The patch fixes all phpcs issues. Marking RTBC!

  • @hardikpandya opened merge request.
  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    - $message = $this->t('You have Rejected the invitation.');
    + // $message = $this->t('You have Rejected the invitation.');

    Why is that line commented out? That is not change required to fix the issues reported by phpcs.

    +  /**
    +   * The entity type manager.
    +   *
    +   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
    +   */
    +  protected $entityTypeManager;
    +
    +  /**
    +   * The route match service.
    +   *
    +   * @var \Drupal\Core\Routing\RouteMatchInterface
    +   */
    +  protected $routeMatch;
    +
    +  /**
    +   * The current user.
    +   *
    +   * @var \Drupal\Core\Session\AccountProxyInterface
    +   */
    +  protected $currentUser;
    +
    +  /**
    +   * The email validator.
    +   *
    +   * @var \Drupal\Component\Utility\EmailValidatorInterface
    +   */
    +  protected $emailValidator;
    +

    Some of those properties are already defined from the parent class.

    +  /**
    +   * PrivateMessageIniviteForm form construct.
    +   *

    The documentation comment for a class is different and it should include the class namespace.

  • Assigned to Soham Sengupta
  • 🇮🇳India Soham Sengupta

    I will try fixing the issues. Thanks,

  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India Soham Sengupta

    I checked that, $message is an unused variable as it was not being used anywhere in the function, hence, the line is commented.
    Fixed the mentioned issues -
    - corrected the misspelled class name
    - added the namespace to class documentation comment
    - reused the parent properties

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -        $messenger = \Drupal::messenger();
    +        $messenger = $this->messenger;

    Since there is a property for the messenger, the code needs to be changed to use that property.

    -    $config = \Drupal::service('config.factory')->getEditable('private_message_invite.settings');
    +    $config = $this->configFactory->getEditable('private_message_invite.settings');

    A class that extends ConfigFormBase uses the config() method, not that code. That is the same error done by the current code, but since that line is changed, it needs to be changed correctly.

    + *
    + * @package Drupal\private_message_invite\Form
    

    @package is not used for classes, in Drupal.

    +  /**
    +   * Constructs PrivateMessageInviteForm.

    The comment is still not using the class namespace. Then, it is not a class to be constructed, but an instance of that class (or object).

    -    $values = $form_state->getValues();
    +    // $values = $form_state->getValues();

    If a variable is only initialized, but not used, the lines initializing (or changing the value of) that variable should be removed, not commented out.

  • Assigned to imustakim
  • 🇨🇦Canada imustakim Canada

    Working on this.

  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇨🇦Canada imustakim Canada

    Patch updated.
    Please review

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * Constructs PrivateMessageInviteForm object.
    +   *

    The namespace is still not used, and there is an article missing in that phrase. (Then, the usual comment says it is a new object.)

  • Status changed to Needs review almost 2 years ago
  • 🇨🇦Canada imustakim Canada

    Updated patch.
    Please review.

  • 🇨🇦Canada imustakim Canada

    Please ignore the last patch and interdiff.
    Here is the updated paatch.

  • Status changed to Needs work almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +    if ($form_state->hasValue(['custom', 'modules']) && is_array(
    +      $form_state->getValue(['custom', 'modules']))) {
    
    -          foreach ([MailsystemManager::MAILSYSTEM_TYPE_FORMATTING, MailsystemManager::MAILSYSTEM_TYPE_SENDING] as $type) {
    +          foreach ([MailsystemManager::MAILSYSTEM_TYPE_FORMATTING, MailsystemManager::MAILSYSTEM_TYPE_SENDING,
    +          ] as $type) {
    

    It is still better to leave the control statement on a single line.

  • Status changed to Needs review almost 2 years ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work almost 2 years ago
  • 🇮🇳India Meeni_Dhobale

    Hi @apaderno I test and review this patch #13, and it is applied very cleanly. But there has still one error remained. In PrivateMessageIniviteForm.php file. Adding error message below.:

    FILE: ...Source/drupal-10-1/modules/contrib/private_message_invite/src/Form/PrivateMessageIniviteForm.php
    ------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------
    36 | WARNING | Line exceeds 80 characters; contains 86 characters
    ------------------------------------------------------------------------------------------------------

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India Akram Khan Cuttack, Odisha

    added updated patch now it's remove remaining issues

  • Status changed to Fixed about 1 year ago
  • Status changed to Fixed about 1 year ago
Production build 0.71.5 2024