Problem/Motivation

FILE: ...tml/contribution/drupal10/web/modules/contrib/commerce_promo_bar/README.md
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------
14 | WARNING | Line exceeds 80 characters; contains 85 characters
36 | WARNING | Line exceeds 80 characters; contains 84 characters
--------------------------------------------------------------------------------

FILE: .../web/modules/contrib/commerce_promo_bar/src/Plugin/Block/PromoBarBlock.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
134 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

FILE: ...upal10/web/modules/contrib/commerce_promo_bar/src/Event/PromoBarEvents.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
5 | ERROR | [x] Missing class doc comment
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...rupal10/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.info.yml
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
10 | ERROR | [x] Expected 1 newline at end of file; 2 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...ion/drupal10/web/modules/contrib/commerce_promo_bar/css/promo_bar.form.css
--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
--------------------------------------------------------------------------------
22 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
23 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
57 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 2
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: .../modules/contrib/commerce_promo_bar/templates/commerce-promo-bar.html.twig
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
36 | ERROR | [x] Expected 1 newline at end of file; 2 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: .../drupal10/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.module
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------
38 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
44 | ERROR | [x] Data types in @var tags need to be fully namespaced
67 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | ]
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 1.73 secs; Memory: 14MB

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig commerce_promo_bar/

Proposed resolution

Fix the issues reported for Drupal and DrupalPractice coding standards.

Remaining tasks

Review.

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

urvashi_vora created an issue. See original summary.

urvashi_vora’s picture

StatusFileSize
new6.74 KB
kenyoowen’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new273.41 KB
new162.28 KB

Hi urvashi_vora

I applied patch Fixed-all-issues.patch to the “Commerce Promo Bar” module and confirmed that the mentioned PHPCS issues are resolved. Please see the screenshots attached.

For your review.
Thank you.

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
+/**
+ * Implements class PromoBarEvents.
+ */

Class descriptions must not start with Implements class nor repeat the class name. Instead, they should describe the class purpose.

+   * @param \Drupal\Component\Datetime\TimeInterface $time
+   *   The time service.
    */
   public function __construct(array $configuration,
   $plugin_id,
   $plugin_definition,
-    EntityTypeManagerInterface $entity_type_manager,
+  EntityTypeManagerInterface $entity_type_manager,
   CurrentStoreInterface $current_store,
-  AccountProxyInterface $current_user) {
+  AccountProxyInterface $current_user,
+  TimeInterface $time) {

Since that code is edited, it should also be edited to put the method declaration of a single line, since that is how Drupal coding standards say to format method/function declarations.

-      $container->get('current_user')
+      $container->get('current_user'),
+      $container->get('datetime.time'),
     );

The comma after the last argument is only allowed on PHP 8. If that module does not explicitly require PHP 8, that comma must be removed.

soham sengupta’s picture

Status: Needs work » Needs review
StatusFileSize
new7.01 KB

Hi, Updated the patch with the suggested changes.

avpaderno’s picture

Status: Needs review » Needs work
- *   - elements: An associative array containing the commerce promo bar information and any
- *     fields attached to the entity.
+ *   - elements: An associative array
+ *     It contains the commerce promo bar information and
+ *     any fields attached to the entity.

An associative array containing the commerce promo bar information and any fields attached to the entity. was already correct; it was just necessary to reformat the text to avoid lines longer than 80 characters.

+/**
+ * Defines events for the commerce_promo_bar module.
+ */
 final class PromoBarEvents {
 

Class descriptions do not need to contain the module machine name.
The verb should be Handles, and events should be better described as promo events.

+  /**
+   * Constructor for the Promo bar block.

Short descriptions for constructors are Constructs a new [class name] object. where [class name] is replaced by the class name (namespace included).

soham sengupta’s picture

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

Thanks, I have updated the patch with the suggested changes, however I was unable to include the namespace of the class in the block constructor short description, as it was exceeding 80characters and the short description should be in a single line.

a.aaronjake’s picture

Status: Needs review » Needs work

Hi @Soham Sengupta,

After applying the patch you provided, new errors/warnings were reported. Please see:

➜  commerce_promo_bar git:(1.0.x) curl https://www.drupal.org/files/issues/2023-05-06/3358410-7.patch | patch -p1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7142  100  7142    0     0  18387      0 --:--:-- --:--:-- --:--:-- 18794
patching file README.md
Hunk #2 FAILED at 33.
1 out of 2 hunks FAILED -- saving rejects to file README.md.rej
patching file commerce_promo_bar.info.yml
patching file commerce_promo_bar.module
Reversed (or previously applied) patch detected!  Assume -R? [n] y
Hunk #1 succeeded at 36 (offset 1 line).
Hunk #2 succeeded at 66 (offset 2 lines).
patching file css/promo_bar.form.css
patching file src/Event/PromoBarEvents.php
Hunk #1 FAILED at 2.
1 out of 1 hunk FAILED -- saving rejects to file src/Event/PromoBarEvents.php.rej
patching file src/Plugin/Block/PromoBarBlock.php
Hunk #1 succeeded at 15 (offset 3 lines).
Hunk #2 succeeded at 53 with fuzz 1.
Hunk #3 FAILED at 74.
Hunk #4 FAILED at 96.
Hunk #5 FAILED at 138.
3 out of 5 hunks FAILED -- saving rejects to file src/Plugin/Block/PromoBarBlock.php.rej
patching file templates/commerce-promo-bar.html.twig
Hunk #1 FAILED at 34.
1 out of 1 hunk FAILED -- saving rejects to file templates/commerce-promo-bar.html.twig.rej
➜  commerce_promo_bar git:(1.0.x) ✗ ..
➜  contrib git:(master) ✗ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig commerce_promo_bar

FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/README.md
--------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------------
 36 | WARNING | Line exceeds 80 characters; contains 84 characters
 37 | WARNING | Line exceeds 80 characters; contains 81 characters
--------------------------------------------------------------------------------------------------------


FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/commerce_promo_bar.module
------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------
 39 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
 45 | ERROR   | [x] Data types in @var tags need to be fully namespaced
 69 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/commerce_promo_bar/templates/commerce-promo-bar.html.twig
-------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------
 38 | ERROR | [x] Expected 1 newline at end of file; 2 found
-------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------

Time: 638ms; Memory: 14MB

Kindly check

Thanks,
Jake

avpaderno changed the visibility of the branch 3358410-fix-the-issues to hidden.

avpaderno’s picture

Issue tags: +Needs reroll

Let's create a merge request, now that patches are no longer tested.

avpaderno’s picture

Status: Needs work » Closed (outdated)
Issue tags: -Needs reroll

Actually, no PHP_CodeSniffer errors/warnings are reported before doing any change.