Fix the issues reported by phpcs

Created on 19 January 2023, almost 2 years ago
Updated 22 July 2023, over 1 year ago

Problem/Motivation

FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/w3c_validator.permissions.yml
--------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------
 3 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/w3c_validator.module
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 12 | WARNING | Unused variable $context.
-----------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/src/W3CTokenManager.php
--------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------
 103 | WARNING | User::load calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/src/Form/W3cValidatorSettingsForm.php
-------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
-------------------------------------------------------------------------------------------------------------------------------------------
 81 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t()
    |         |     instead
 82 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t()
    |         |     instead
 84 | WARNING | [x] A comma should follow the last multiline array item. Found: )
 87 | WARNING | [x] A comma should follow the last multiline array item. Found: )
-------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/src/W3CProcessor.php
-----------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------
 119 | ERROR | [x] Separate the @return and @todo sections by a blank line.
 206 | ERROR | [x] Use null coalesce operator instead of ternary operator.
-----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------


FILE: /Users/studenttrainees/Drupal.org/drupalorg-site/docroot/modules/contrib/w3c_validator/src/Controller/W3CLogController.php
-------------------------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
-------------------------------------------------------------------------------------------------------------------------------------------
 275 | ERROR | unserialize() is insecure unless allowed classes are limited. Use a safe format like JSON or use the allowed_classes
     |       | option.
 312 | ERROR | unserialize() is insecure unless allowed classes are limited. Use a safe format like JSON or use the allowed_classes
     |       | option.
 349 | ERROR | unserialize() is insecure unless allowed classes are limited. Use a safe format like JSON or use the allowed_classes
     |       | option.
-------------------------------------------------------------------------------------------------------------------------------------------

Time: 456ms; Memory: 12MB

Steps to reproduce

Run following command: phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml /Applications/MAMP/htdocs/9.4.x/drupal/modules/contrib/w3c_validator

Proposed resolution

Needs to resolve/fixed the issues.

Remaining tasks

📌 Task
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇮🇳India sahil.goyal

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.

  • Status changed to Needs review over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +   * The user Entity.
    +   *
    +   * @var \Drupal\user\Entity\User
    +   */
    +  protected $user;
    +

    Entity is misspelled.

    +  /**
    +   * Create dependency injection for class.
    +   */
    +  public static function create(ContainerInterface $container) {

    It is sufficient to use {@inheritDoc}.

  • Assigned to himanshu_jhaloya
  • 🇮🇳India himanshu_jhaloya Indore

    I will work on this issue

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India himanshu_jhaloya Indore

    Created a patch for the commented issue. please review

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +   * @param \Drupal\user\Entity\User $user
    +   *   The user Entity.

    Only the first word in a sentence is capitalized.

    +  /**
    +   * {@inheritdoc}
    +   */
    +
    +  public static function create(ContainerInterface $container) {

    There must not be empty lines between a method declaration and the documentation comment.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India himanshu_jhaloya Indore

    create a patch to fix the above issue. please review

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

    The patch must include all the changes, not just the ones reported in the last comment.

  • Assigned to sourabhjain
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India chaitanyadessai Goa

    Patch added please review.

  • Status changed to RTBC over 1 year ago
  • 🇵🇭Philippines paraderojether

    I update the summary since I'm getting different phpcs issues results after running this command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig w3c_validator.

    I also reviewed patch #17, applied against W3C Validator 8.x-1.x-dev, and confirmed it fixes the issues reported by phpcs.

    I added screenshots for reference.
    Thank You.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -  public function __construct(Connection $database, AccountInterface $current_user) {
    +  public function __construct(Connection $database, AccountInterface $current_user, User $user) {
         $this->database = $database;
         $this->currentUser = $current_user;
    +    $this->user = $user;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static function create(ContainerInterface $container) {
    +
    +    return new static(
    +      $container->get('current_user')
    +    );
    +

    create() must pass three arguments to the constructor, not one.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India bharath-kondeti Hyderabad

    Addressed #19 and updated the patch. Please review.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -    return User::load($result->uid);
    +    return $this->currentUser->load($result->uid);

    That is not how a user account is loaded from the database. The current_user service is only for the currently logged-in user account; the class implementing that service does not even have a load() method.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India AkashKumar07

    The patch addresses #21. Please review.

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

    The last patch does not fix the User::load calls should be avoided in classes, use dependency injection instead warning for the W3CTokenManager class.

  • Assigned to imustakim
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India imustakim Ahmedabad

    Patch updated.
    Please review.

  • 🇮🇳India sourabhjain

    @imustakin could you please add interdiff file.

  • Status changed to Closed: outdated over 1 year ago
Production build 0.71.5 2024