Fix the errors/warnings reported by PHP_CodeSniffer

Created on 10 July 2023, 12 months ago
Updated 24 January 2024, 5 months ago

Problem/Motivation

When running the module code against Drupal coding standards based on Drupal standard, the module shows errors

Report:

FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/README.md
-------------------------------------------------------------------------
FOUND 1 ERROR AND 15 WARNINGS AFFECTING 16 LINES
-------------------------------------------------------------------------
   2 | WARNING | [ ] Line exceeds 80 characters; contains 98 characters
   4 | WARNING | [ ] Line exceeds 80 characters; contains 160 characters
   6 | WARNING | [ ] Line exceeds 80 characters; contains 128 characters
   8 | WARNING | [ ] Line exceeds 80 characters; contains 167 characters
  12 | WARNING | [ ] Line exceeds 80 characters; contains 353 characters
  14 | WARNING | [ ] Line exceeds 80 characters; contains 137 characters
  16 | WARNING | [ ] Line exceeds 80 characters; contains 193 characters
  18 | WARNING | [ ] Line exceeds 80 characters; contains 138 characters
  20 | WARNING | [ ] Line exceeds 80 characters; contains 219 characters
  22 | WARNING | [ ] Line exceeds 80 characters; contains 371 characters
  32 | WARNING | [ ] Line exceeds 80 characters; contains 161 characters
  76 | WARNING | [ ] Line exceeds 80 characters; contains 105 characters
  86 | WARNING | [ ] Line exceeds 80 characters; contains 229 characters
  95 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 100 | WARNING | [ ] Line exceeds 80 characters; contains 165 characters
 108 | ERROR   | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/ChatAI.php
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 5 WARNINGS AFFECTING 9 LINES
---------------------------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
  66 | ERROR   | [ ] Parameter $supabase is not described in comment
  79 | ERROR   | [ ] Doc comment for parameter $supabase, does not match actual variable name $config_factory
 105 | ERROR   | [ ] Description for the @return value is missing
 113 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
 126 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
 167 | WARNING | [ ] Line exceeds 80 characters; contains 108 characters
 207 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 227 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
---------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/SettingsForm.php
------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------------
  7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
 91 | WARNING | [ ] Possible useless method overriding detected
------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/EmbeddingsForm.php
-----------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 8 WARNINGS AFFECTING 12 LINES
-----------------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Form\ConfigFormBase.
 119 | WARNING | [ ] Node::load calls should be avoided in classes, use dependency injection instead
 120 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 121 | WARNING | [ ] The use of function dpm() is discouraged
 237 | WARNING | [ ] Possible useless method overriding detected
 316 | ERROR   | [ ] Description for the @return value must be on the next line
 331 | WARNING | [ ] Unused variable $langcode.
 354 | WARNING | [ ] Line exceeds 80 characters; contains 108 characters
 356 | ERROR   | [ ] Description for the @return value must be on the next line
 371 | ERROR   | [ ] Doc comment is empty
 404 | WARNING | [ ] Line exceeds 80 characters; contains 88 characters
 442 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
-----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/ChatBlockForm.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 8 WARNINGS AFFECTING 10 LINES
---------------------------------------------------------------------------------------------------------------------------
   7 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Ajax\AjaxResponse.
  19 | ERROR   | [ ] Missing member variable doc comment
 102 | WARNING | [ ] Possible useless method overriding detected
 129 | WARNING | [ ] Line exceeds 80 characters; contains 227 characters
 131 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
 132 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
 139 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 145 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 147 | WARNING | [ ] Line exceeds 80 characters; contains 88 characters
 148 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Plugin/Block/ChatAIBlock.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
 22 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Embeddings.php
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 18 ERRORS AND 19 WARNINGS AFFECTING 36 LINES
---------------------------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
  79 | ERROR   | [ ] Parameter $supabase is not described in comment
  92 | ERROR   | [ ] Doc comment for parameter $supabase, does not match actual variable name $config_factory
 116 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 123 | ERROR   | [ ] Description for the @return value must be on the next line
 129 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 138 | WARNING | [ ] Line exceeds 80 characters; contains 101 characters
 147 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
 149 | ERROR   | [ ] Description for the @return value must be on the next line
 178 | ERROR   | [ ] Description for the @return value must be on the next line
 207 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
 228 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 266 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
 281 | WARNING | [ ] Unused variable $results.
 294 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 305 | ERROR   | [ ] Parameter $value is not described in comment
 311 | ERROR   | [ ] Description for the @return value must be on the next line
 314 | WARNING | [ ] '@todo' should match the format '@todo Fix problem X here.'
 328 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 337 | ERROR   | [ ] Description for the @return value must be on the next line
 340 | WARNING | [ ] '@todo' should match the format '@todo Fix problem X here.'
 360 | ERROR   | [ ] Description for the @return value must be on the next line
 363 | WARNING | [ ] '@todo' should match the format '@todo Fix problem X here.'
 378 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 378 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 380 | ERROR   | [ ] Missing parameter comment
 391 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 409 | ERROR   | [ ] Description for the @return value must be on the next line
 421 | ERROR   | [ ] Parameter $value is not described in comment
 427 | ERROR   | [ ] Description for the @return value must be on the next line
 430 | WARNING | [ ] '@todo' should match the format '@todo Fix problem X here.'
 446 | ERROR   | [ ] Description for the @return value must be on the next line
 455 | WARNING | [ ] Line exceeds 80 characters; contains 94 characters
 476 | ERROR   | [ ] Missing parameter comment
 478 | ERROR   | [ ] Description for the @return value is missing
 485 | WARNING | [ ] '@todo' should match the format '@todo Fix problem X here.'
 520 | WARNING | [ ] Line exceeds 80 characters; contains 86 characters
---------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Supabase.php
-------------------------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 4 WARNINGS AFFECTING 8 LINES
-------------------------------------------------------------------------------------------------------------------------------------
  10 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
 110 | ERROR   | [ ] Description for the @return value is missing
 123 | WARNING | [ ] Unused variable $body.
 133 | WARNING | [ ] Line exceeds 80 characters; contains 102 characters
 142 | ERROR   | [ ] Description for the @return value must be on the next line
 183 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 219 | WARNING | [ ] Line exceeds 80 characters; contains 86 characters
 228 | ERROR   | [ ] Description for the @return value must be on the next line
-------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Http/SupabaseClientFactory.php
-----------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------
 6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
-----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/chat_ai.install
----------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------------
 11 | ERROR   | Empty installation hooks are not necessary
 12 | WARNING | '@todo' should match the format '@todo Fix problem X here.'
 19 | WARNING | '@todo' should match the format '@todo Fix problem X here.'
----------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/chat_ai.libraries.yml
----------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------
 11 | ERROR | [x] Expected 1 newline at end of file; 2 found
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------

Steps to reproduce

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

๐Ÿ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia urvashi_vora Madhya Pradesh, India

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

Merge Requests

Comments & Activities

  • Issue created by @urvashi_vora
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Ashutosh Ahirwal India

    Provided patch not get applied throwing error.

    chat_ai % git apply -v dependency-injections-added.patch
    Checking patch src/ChatAI.php...
    Checking patch src/Embeddings.php...
    Hunk #7 succeeded at 345 (offset 18 lines).
    Hunk #8 succeeded at 441 (offset 17 lines).
    Checking patch src/Form/ChatBlockForm.php...
    Checking patch src/Form/EmbeddingsForm.php...
    Hunk #1 succeeded at 88 (offset -1 lines).
    error: while searching for:
    public function buildForm(array $form, FormStateInterface $form_state) {

    // Debug.
    $entity = Node::load(1);
    $embeddings = \Drupal::service('chat_ai.embeddings');
    dpm($embeddings->shouldIndex($entity));
    // ..
    $config = json_decode($this->config('chat_ai.settings')->get('include') ?? '', TRUE);

    error: patch failed: src/Form/EmbeddingsForm.php:116
    error: src/Form/EmbeddingsForm.php: patch does not apply
    Checking patch src/Plugin/Block/ChatAIBlock.php...

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Preethy_ray

    pray_12 โ†’ made their first commit to this issueโ€™s fork.

  • Assigned to Preethy_ray
  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • Assigned to realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp

    Getting following errors in the issue's fork commit #3,

    FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/tests/src/Functional/SettingsPageTest.php
    --------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------
     35 | WARNING | Possible useless method overriding detected
    --------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/SettingsForm.php
    ----------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------
     91 | WARNING | Possible useless method overriding detected
    ----------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/EmbeddingsForm.php
    ------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------
     231 | WARNING | Possible useless method overriding detected
    ------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/chat_ai/src/Form/ChatBlockForm.php
    -----------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------
     141 | WARNING | Possible useless method overriding detected
    -----------------------------------------------------------------------------------------
    
  • Merge request !1Resolve #3373585 "Drupal calls should" โ†’ (Open) created by realsp
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp

    The possible useless methods were empty validate form methods in 'Form' files, and a separate 'setup()' method call without any definitions, hence can be removed. Please review the MR, Thank you.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp
Production build 0.69.0 2024