Unused variables are found

Created on 4 July 2023, about 1 year ago
Updated 7 June 2024, 4 months ago

Problem/Motivation

Unused variables are found in the module.
As we run the command it gives us the following warning error:

FOUND 0 ERRORS AND 8 WARNINGS AFFECTING 8 LINES
------------------------------------------------------------------------------------------------------------------------------------------
 116 | WARNING | Unused variable $response.
 162 | WARNING | Unused variable $response.
 177 | WARNING | Unused variable $response.
 190 | WARNING | Unused variable $response.
 246 | WARNING | Unused variable $response.
 267 | WARNING | Unused variable $response.
 281 | WARNING | Unused variable $response.

FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
--------------------------------------------------------------------------------------------
 17 | WARNING | Unused variable $server.

Steps to reproduce

1) Install the module.

2) Run this php code standard command to detect the errors reporeted by the php code sniffer.
phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml /path/to/drupal/example_module

3) Mention the proper path of the file in which you want to detect the error.

4) once you run the command you will get the list of errors along with the file name.

Proposed resolution

Need to edit the code as per php coding standard.

šŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India Prachi6824

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

  • Issue created by @Prachi6824
  • Assigned to Prachi6824
  • šŸ‡®šŸ‡³India Prachi6824

    I will create a patch to solve the issue .

  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • šŸ‡®šŸ‡³India Prachi6824

    Hello,

    I have created a patch to solve the issue.

    Please review and apply it .

  • Status changed to Needs work 4 months ago
  • Hi @prachi6824,

    Applied your patch successfully, however it threw multiple errors. Please see below:

    search_api_pinecone-search_api_pinecone git:(1.0.x) curl https://www.drupal.org/files/issues/2023-07-04/unused-variable-issue-3372283-%233.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4244  100  4244    0     0  14403      0 --:--:-- --:--:-- --:--:-- 15157
    patching file search_api_pinecone.module
    patching file src/Plugin/search_api/backend/SearchApiPineconeBackend.php
    āžœ  search_api_pinecone-search_api_pinecone git:(1.0.x) āœ— cd ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig search_api_pinecone-search_api_pinecone
    
    FILE: ...rupal-orgissue/web/modules/contrib/search_api_pinecone-search_api_pinecone/search_api_pinecone.module
    -----------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------
     65 | WARNING | #options values usually have to run through t() for translation
     66 | WARNING | #options values usually have to run through t() for translation
     67 | WARNING | #options values usually have to run through t() for translation
    -----------------------------------------------------------------------------------------------------------
    
    
    FILE: ...ib/search_api_pinecone-search_api_pinecone/src/Plugin/search_api/backend/SearchApiPineconeBackend.php
    -----------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------
       9 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is
         |         |     Drupal\Component\Serialization\Json.
     266 | WARNING | [ ] Unused variable $pinecode_client.
     280 | WARNING | [ ] Unused variable $pinecode_client.
     318 | WARNING | [ ] t() calls should be avoided in classes, use
         |         |     \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------
    
    Time: 347ms; Memory: 12MB

    Kindly check.

    Thanks,
    Jake

Production build 0.71.5 2024