Fix the issues reported by phpcs

Created on 12 January 2023, almost 2 years ago
Updated 3 May 2023, over 1 year ago

Problem/Motivation

Getting following error/warnings

FILE: /var/www/html/modules/contrib/search_overrides/search_overrides.module
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 3 WARNINGS AFFECTING 12 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
53 | ERROR | [x] Inline comments must start with a capital letter
53 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
56 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
91 | WARNING | [x] 'TODO: prevent duplicates from being stored.' should match the format '@todo Fix problem X here.'
97 | WARNING | [x] 'TODO: make this work with more entities than nodes.' should match the format '@todo Fix problem X here.'
99 | ERROR | [x] No space found before comment text; expected "// $hash . '-base-entity:node/' . $id . ':' . $language;" but found "//$hash . '-base-entity:node/' .
| | $id . ':' . $language;"
105 | WARNING | [x] 'TODO: make this work with more entities than nodes.' should match the format '@todo Fix problem X here.'
126 | ERROR | [x] Expected newline after closing brace
197 | ERROR | [x] Calling class constructors must always include parentheses
207 | ERROR | [x] Expected 1 space after IF keyword; 0 found
211 | ERROR | [x] Calling class constructors must always include parentheses
215 | ERROR | [x] Expected 1 space after FOREACH keyword; 0 found
278 | ERROR | [x] Missing function doc comment
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 13 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/search_overrides.install
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 1 LINE
-----------------------------------------------------------------------------
39 | WARNING | [x] There must be no blank line following an inline comment
39 | WARNING | [ ] There must be no blank line following an inline comment
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/README.txt
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
99 | WARNING | Line exceeds 80 characters; contains 93 characters
----------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/Form/SearchOverrideForm.php
--------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
--------------------------------------------------------------------------------------------------
37 | ERROR | [x] Missing function doc comment
40 | WARNING | [ ] Unused variable $values.
41 | ERROR | [x] Expected 1 space after FOREACH keyword; 0 found
52 | ERROR | [x] Missing function doc comment
90 | ERROR | [x] Expected 1 space after FOREACH keyword; 0 found
111 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
130 | ERROR | [x] Expected newline after closing brace
132 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/Form/SearchOverrideSettingsForm.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 7 WARNINGS AFFECTING 9 LINES
---------------------------------------------------------------------------------------------------------------------------
50 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
78 | ERROR | [x] The first index in a multi-value array must be on a new line
79 | WARNING | [x] A comma should follow the last multiline array item. Found: 'override-previews'
80 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
98 | ERROR | [x] The first index in a multi-value array must be on a new line
99 | WARNING | [x] A comma should follow the last multiline array item. Found: 'preview-query'
107 | WARNING | [ ] Avoid backslash escaping in translatable strings when possible, use "" quotes instead
116 | WARNING | [ ] Translatable strings must not begin or end with white spaces, use placeholders with t() for variables
123 | WARNING | [ ] Translatable strings must not begin or end with white spaces, use placeholders with t() for variables
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/SearchOverridesTrait.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
-----------------------------------------------------------------------------------------------------------------------------------------
41 | WARNING | [ ] Unused variable $entity.
46 | WARNING | [ ] Unused variable $entity.
50 | WARNING | [x] 'TODO: construct an object that can provide needed methods e.g.' should match the format '@todo Fix problem X here.'
56 | ERROR | [x] Missing function doc comment
-----------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/Entity/SearchOverrideListBuilder.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
33 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/Element/AddOverride.php
-------------------------------------------------------------------------------------------------------------------------------
FOUND 12 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
-------------------------------------------------------------------------------------------------------------------------------
12 | ERROR | [x] There must be one blank line after the last USE statement; 2 found;
47 | ERROR | [x] Short array syntax must be used to define arrays
77 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
77 | ERROR | [x] Comments may not appear after statements
77 | ERROR | [x] No space found before comment text; expected "// alternative notation" but found "//alternative notation"
77 | ERROR | [x] Inline comments must start with a capital letter
77 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
78 | WARNING | [ ] Line exceeds 80 characters; contains 95 characters
78 | ERROR | [x] Comments may not appear after statements
80 | WARNING | [ ] Line exceeds 80 characters; contains 98 characters
80 | ERROR | [x] Comments may not appear after statements
97 | ERROR | [x] Data types in @param tags need to be fully namespaced
100 | ERROR | [x] Data types in @return tags need to be fully namespaced
100 | ERROR | [x] Return type must not contain variable name "$response"
176 | ERROR | [x] Calling class constructors must always include parentheses
-------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/Controller/Manager.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 7 ERRORS AND 5 WARNINGS AFFECTING 11 LINES
------------------------------------------------------------------------------------------------------------------------------------------
10 | WARNING | [x] Unused use statement
23 | ERROR | [x] Missing function doc comment
26 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
39 | ERROR | [x] Missing function doc comment
40 | WARNING | [ ] Unused variable $message.
42 | ERROR | [x] Calling class constructors must always include parentheses
45 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
54 | ERROR | [x] Missing function doc comment
67 | ERROR | [x] Expected 1 space between comma and "'exnid'"; 0 found
67 | ERROR | [x] Expected one space after the comma, 0 found
81 | ERROR | [x] Missing function doc comment
94 | WARNING | [x] '@todo: find a reliable way to create a title for content from a' should match the format '@todo Fix problem X here.'
------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/search_overrides/src/SearchOverrideReferencer.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 8 ERRORS AND 15 WARNINGS AFFECTING 21 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
6 | WARNING | [x] Unused use statement
7 | WARNING | [x] Unused use statement
8 | WARNING | [x] Unused use statement
9 | WARNING | [x] Unused use statement
10 | WARNING | [x] Unused use statement
11 | WARNING | [x] Unused use statement
13 | WARNING | [x] Unused use statement
15 | WARNING | [x] Unused use statement
24 | ERROR | [ ] Missing short description in doc comment
27 | ERROR | [ ] Class property $entity_type_id should use lowerCamel naming without underscores
29 | ERROR | [ ] Missing short description in doc comment
34 | ERROR | [ ] Missing short description in doc comment
61 | ERROR | [x] Use "elseif" in place of "else if"
91 | ERROR | [ ] Public method name "SearchOverrideReferencer::EntityOverridesTable" is not in lowerCamel format
92 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
92 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
102 | ERROR | [x] Expected one space after the comma, 0 found
127 | WARNING | [x] 'TODO: make the specifics configurable in the settings.' should match the format '@todo Fix problem X here.'
159 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
160 | ERROR | [ ] The array declaration extends to column 85 (the limit is 80). The array content should be split up over multiple lines
160 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
167 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------

Time: 3.04 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/search_overrides/

Proposed resolution

Above error/warnings need to be fixed

๐Ÿ“Œ Task
Status

Needs work

Version

2.1

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, ๐Ÿ‡ฎ๐Ÿ‡น

    It would be better if the MR is reviewed by somebody who does not work on the same organization.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines clarkssquared

    Hi samit.310@gmail.com,

    I applied your patch #2 to Search Overrides module against version 2.1.x-dev and I confirmed that the PHPCS issues were fixed.

    Please look at the screenshots attached for your reference

    Thank you

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -    // Only load one entity per term, to reduce complexity
    -    // TODO: prevent duplicates from being stored.
    +    // Only load one entity per term, to reduce complexity.
    +    // @todo prevent duplicates from being stored.

    What follows @todo is a sentence: It starts with a capitalized word and it ends with a period (preferable), a question mark, or an exclamation point.

    +/**
    + * Function search_overrides_get_indexes.
    + */
     function search_overrides_get_indexes() {

    Assuming that is not a hook implementation, its documentation comment must:

    • Describe the function purpose, not start with Function and repeat the function name
    • Describe any parameter it gets and their type
    • Describe the return value
    +  /**
    +   * Constructs a new Manager instance.
    +   *
    +   * @param \Drupal\Core\Render\RendererInterface $renderer
    +   *   The renderer.
    +   * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
    +   *   The redirect destination service.
    +   */
    +  public function __construct(RendererInterface $renderer, RedirectDestinationInterface $redirect_destination) {

    The short description is missing the class namespace.

    +  /**
    +   * Function remove Entity.
    +   */
       public function removeEntity($override, $entity, $field) {

    It is not correct for the same reasons reported for the other change.

           '#ajax' => [
    -        'callback' => [get_called_class(), 'processInput'], //alternative notation
    -        'disable-refocus' => TRUE, // Or TRUE to prevent re-focusing on the triggering element.
    +      // Alternative notation.
    +        'callback' => [get_called_class(), 'processInput'],
    +      // Or TRUE to prevent re-focusing on the triggering element.
    +        'disable-refocus' => TRUE,
             'event' => 'click',
    -        'wrapper' => 'search-overrides--data', // This element is updated with this AJAX callback.
    +      // This element is updated with this AJAX callback.

    Those comments are wrongly indented.

    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(ConfigFactoryInterface $config_factory) {

    {@inheritdoc} is not used for constructors.

     class SearchOverrideReferencer {
    -  use StringTranslationTrait;
    -
    -  /**
    -   * @var string
    -   */
    -  protected $entity_type_id;
    -
    -  /**
    -   * @var int
    -   */
    -  protected $eid;
     
    -  /**
    -   * @var string
    -   */
    -  protected $keyword;
    +  use StringTranslationTrait;

    Why are those properties removed?

  • bindu r โ†’ made their first commit to this issueโ€™s fork.

  • First commit to issue fork.
Production build 0.71.5 2024