\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 11 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
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pray_12
  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia pray_12
  • 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
  • Status changed to Needs work 4 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.

Production build 0.71.5 2024