\Drupal calls should be avoided in classes, use dependency injection instead

Created on 10 July 2023, over 1 year ago

Problem/Motivation

FILE: /var/www/html/vb/d_cont/chat_ai/src/ChatAI.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNINGS AFFECTING 1 LINES
--------------------------------------------------------------------------------
207 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

FILE: /var/www/html/vb/d_cont/chat_ai/src/Form/EmbeddingsForm.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNINGS AFFECTING 1 LINES
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------

FILE: /var/www/html/vb/d_cont/chat_ai/src/Form/ChatBlockForm.php
--------------------------------------------------------------------------------
FOUND 0 ERROR AND 3 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------
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
148 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

FILE: /var/www/html/vb/d_cont/chat_ai/src/Embeddings.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------
129 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
294 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
391 | WARNING | \Drupal calls should be avoided in classes, use dependency
| | injection instead
--------------------------------------------------------------------------------

FILE: /var/www/html/vb/d_cont/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
--------------------------------------------------------------------------------

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/

Remaining tasks

Patch review

📌 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.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @urvashi_vora
  • Status changed to Needs work 12 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...

  • First commit to issue fork.
  • Assigned to pray_12
  • Issue was unassigned.
  • Status changed to Needs review 11 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.

  • Status changed to Needs work 5 months ago
  • 🇵🇭Philippines roberttabigue

    Hi @realsp,

    After reviewing and applied the MR!1 to the Chat AI module against 1.0.0-alpha on Drupal 10, not all of the PHPCS errors were resolved.
    See below:

    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/SettingsForm.php
    ------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------
     46 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
    ------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/ChatBlockForm.php
    -------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------
     70 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
    -------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/EmbeddingsForm.php
    --------------------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------------------
     90 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     91 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
    --------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Embeddings.php
    -----------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------
     137 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     138 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
    -----------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Supabase.php
    ---------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------
      97 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
     246 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
    ---------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/ChatAI.php
    ---------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ---------------------------------------------------------------------------------------------------------
     102 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     103 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
    ---------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------

    I ran this command on the module:
    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js chat_ai/

    I'm moving this to ‘Needs work’ for now.

    Thank you!

  • Assigned to kulpratap2002
  • 🇮🇳India kulpratap2002

    Fixed all remaining phpcs errors, Please review.

  • 🇵🇭Philippines roberttabigue

    Hi @kul.pratap,

    After reviewing and applied the latest MR!1 to the Chat AI module against 1.0.0-alpha1 on Drupal 10, not all of the PHPCS errors were resolved.
    See below:

    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/tests/src/Kernel/ChatAIKernelTestBase.php
    ----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------------
     10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Supabase.
    ----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/SettingsForm.php
    ---------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------------------------
     7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
    ---------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ---------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/ChatBlockForm.php
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------
     11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\ChatAIService.
    -----------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Form/EmbeddingsForm.php
    --------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------
     14 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Embeddings.
    --------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Embeddings.php
    ----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------------
     14 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
    ----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/Supabase.php
    ----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------------
     11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
    ----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/chat_ai/src/ChatAI.php
    ----------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------------
     11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\chat_ai\Http\OpenAiClientFactory.
    ----------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------------

    I ran this command on the module:
    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js chat_ai/

    I'm moving this to ‘Needs work’ again.

    Thank you!

  • Pipeline finished with Failed
    7 days ago
    Total: 170s
    #370675
  • 🇮🇳India kulpratap2002

    "Hi @roberttabigue,
    I have resolved all the errors in the latest MR commit. It seems you may not have reviewed the most recent changes. I have verified everything locally, and there are no errors after the latest commit. The PHPCS errors have already been fixed, which you can confirm by reviewing the updated files.
    Since GitLab CI is used to check PHPCS errors, I have enabled GitLab CI.
    But the pipeline is failing for composer, i am attaching screenshot for reference.

Production build 0.71.5 2024