Fix the issues reported by phpcs

Created on 23 December 2022, almost 2 years ago
Updated 17 May 2023, over 1 year ago

Problem/Motivation

Getting following error/warnings

FILE: /app/modules/contrib/content_moderation_notifications/README.txt
----------------------------------------------------------------------
FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
50 | WARNING | Line exceeds 80 characters; contains 85 characters
75 | WARNING | Line exceeds 80 characters; contains 100 characters
84 | WARNING | Line exceeds 80 characters; contains 104 characters
85 | WARNING | Line exceeds 80 characters; contains 87 characters
87 | WARNING | Line exceeds 80 characters; contains 105 characters
93 | WARNING | Line exceeds 80 characters; contains 99 characters
94 | WARNING | Line exceeds 80 characters; contains 94 characters
----------------------------------------------------------------------

FILE: /app/modules/contrib/content_moderation_notifications/src/ContentModerationNotificationsAccessController.php
------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------
24 | WARNING | Possible useless method overriding detected
------------------------------------------------------------------------------------------------------------------

FILE: /app/modules/contrib/content_moderation_notifications/src/Form/ContentModerationNotificationsFormBase.php
---------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------
150 | ERROR | [x] Use null coalesce operator instead of ternary operator.
---------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------

FILE: /app/modules/contrib/content_moderation_notifications/src/Notification.php
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------------------------------
129 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
141 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
159 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
184 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
206 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------

FILE: /app/modules/contrib/content_moderation_notifications/tests/src/Functional/Form/CrudFormTest.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 16 WARNINGS AFFECTING 16 LINES
------------------------------------------------------------------------------------------------------------------------------------------
73 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
86 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
91 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
124 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
126 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
141 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
148 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
152 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
159 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
163 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
164 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
165 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
178 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
180 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
181 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
182 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------------------------------------------------------------------------------------------------

FILE: /app/modules/contrib/content_moderation_notifications/tests/src/Kernel/TokenNotificationsTest.php
-------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------
110 | WARNING | Unused variable $notification.
-------------------------------------------------------------------------------------------------------

Time: 1.5 secs; Memory: 12MB

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/content_moderation_notifications/

Proposed resolution

Above error/warnings need to be fixed

Note:

I have removed following line of code as it only called it's parent checkAccess function nothing else from src/ContentModerationNotificationsAccessController.php file. We can add this later if there is any specific code for the same.

/**
 * {@inheritdoc}
 */
public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
  // No special access handling. Defer to the entity system which will only
  // allow admin access by default.
  return parent::checkAccess($entity, $operation, $account);
}
📌 Task
Status

Needs work

Version

3.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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -Message:  (Can support all the same Twig options, but will run template output through the selected
    -           Text Format's (Basic HTML, Full HTML, etc) Input Filters  before it will be mailed)
    +Message:  (Can support all the same Twig options, but will run template output
    + through the selected
    +           Text Format's (Basic HTML, Full HTML, etc) Input Filters  before
    +            it will be mailed)

    hrough the selected is much shorter than 80 characters.
    The last two lines are wrongly indented.

    -    arguments: ['@current_user', '@entity_type.manager', '@plugin.manager.mail', '@module_handler', '@content_moderation_notifications.notification_information', '@?token.entity_mapper']
    +    arguments: ['@current_user',
    +                '@entity_type.manager',
    +                '@plugin.manager.mail',
    +                '@module_handler',
    +                '@content_moderation_notifications.notification_information',
    +                '@renderer',
    +                '@config.factory',
    +                '@?token.entity_mapper']

    Those lines are wrongly indented. Either arguments value is kept on a single line, or the single values are each placed on a single line.

    arguments:
      - '@container.namespaces'
      - '@module_handler'
      - '@cache.discovery'
      - '@string_translation'
      - '@class_resolver'
      - '@entity.last_installed_schema.repository'
    
    -  public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, MailManagerInterface $mail_manager, ModuleHandlerInterface $module_handler, NotificationInformationInterface $notification_information, TokenEntityMapperInterface $token_entity_mappper = NULL) {
    +  public function __construct(AccountInterface $current_user,
    +                              EntityTypeManagerInterface $entity_type_manager,
    +                              MailManagerInterface $mail_manager,
    +                              ModuleHandlerInterface $module_handler,
    +                              NotificationInformationInterface $notification_information,
    +                              RendererInterface $renderer,
    +                              ConfigFactoryInterface $config_factory,
    +                              TokenEntityMapperInterface $token_entity_mappper = NULL) {

    As per Drupal coding standards, method declarations can be on a single line, if they are more readable. The existing code is already correct.

  • Assigned to nitin_lama
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    14 pass
  • @nitin_lama opened merge request.
  • 🇮🇳India nitin_lama India

    Please review.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • 🇵🇭Philippines roberttabigue

    Hi,

    Confirmed no PHPCS errors after applying the latest MR to the Content Moderation Notifications module with version 8.x-3.x-dev and with Drupal core version 9.5.8.

    Marking this now as RTBC.
    Kindly refer to the attached screenshots, please.

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

    The report shows errors/warnings for six files, but the MR changes seven files. The number of reported files and the number of changed files must match.

Production build 0.71.5 2024