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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sahil.goyal created an issue. See original summary.

sahil.goyal’s picture

StatusFileSize
new16.61 KB

Fixes the issue.

hardikpandya’s picture

StatusFileSize
new590.56 KB

Can not apply the patch against 8.x-1.x

_pratik_ made their first commit to this issue’s fork.

sahil.goyal’s picture

Status: Needs work » Needs review
StatusFileSize
new6.67 KB

there was some issue with my setup before, so updating the patch again against 8.x-1.x

avpaderno’s picture

Title: Drupal Coding Standards Issues | phpcs » Fix the issues reported by phpcs
Version: 8.x-1.4 » 8.x-1.x-dev
Priority: Normal » Minor
Issue tags: -
avpaderno’s picture

Status: Needs review » Needs work
+   * 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}.

himanshu_jhaloya’s picture

Assigned: Unassigned » himanshu_jhaloya

I will work on this issue

himanshu_jhaloya’s picture

Assigned: himanshu_jhaloya » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.64 KB

Created a patch for the commented issue. please review

avpaderno’s picture

Status: Needs review » Needs work
+   * @param \Drupal\user\Entity\User $user
+   *   The user Entity.

Only the first word in the description is capitalized.

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

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

himanshu_jhaloya’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB

create a patch to fix the above issue. please review

avpaderno’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

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

sourabhjain’s picture

Assigned: Unassigned » sourabhjain
sourabhjain’s picture

Assigned: sourabhjain » Unassigned
chaitanyadessai’s picture

Status: Needs work » Needs review
StatusFileSize
new4.71 KB
new6.64 KB

Patch added please review.

paraderojether’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new169.04 KB
new204.71 KB

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.

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
-  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.

bharath-kondeti’s picture

Status: Needs work » Needs review
StatusFileSize
new6.04 KB

Addressed #19 and updated the patch. Please review.

avpaderno’s picture

Status: Needs review » Needs work
-    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.

akashkumar07’s picture

Status: Needs work » Needs review
StatusFileSize
new5.86 KB
new342 bytes

The patch addresses #21. Please review.

avpaderno’s picture

Status: Needs review » Needs work

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

imustakim’s picture

Assigned: Unassigned » imustakim
imustakim’s picture

Assigned: imustakim » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.36 KB

Patch updated.
Please review.

sourabhjain’s picture

@imustakin could you please add interdiff file.

dom.’s picture

Status: Needs review » Closed (outdated)