Fix the errors/warnings reported by PHP_CodeSniffer

Created on 11 February 2024, 11 months ago
Updated 18 July 2024, 5 months ago

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig shows the following warnings/errors, which should be fixed.

FILE: ./countries_field.info.yml
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 1 | WARNING | "core_version_requirement" property is missing in the
   |         | info.yml file
----------------------------------------------------------------------


FILE: ./src/Continents.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 5 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------
   9 | WARNING | The class short comment should describe what the
     |         | class does and not simply repeat the class name
  23 | WARNING | \Drupal calls should be avoided in classes, use
     |         | dependency injection instead
  51 | WARNING | t() calls should be avoided in classes, use
     |         | \Drupal\Core\StringTranslation\StringTranslationTrait
     |         | and $this->t() instead
  51 | WARNING | Only string literals should be passed to t() where
     |         | possible
  96 | WARNING | \Drupal calls should be avoided in classes, use
     |         | dependency injection instead
 105 | ERROR   | Public method name "Continents::getDBStructure" is
     |         | not in lowerCamel format
----------------------------------------------------------------------


FILE: ./src/Controller/CountryController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 11 | WARNING | The class short comment should describe what the
    |         | class does and not simply repeat the class name
----------------------------------------------------------------------


FILE: ./src/Countries.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 7 WARNINGS AFFECTING 6 LINES
----------------------------------------------------------------------
    9 | WARNING | The class short comment should describe what the
      |         | class does and not simply repeat the class name
   23 | WARNING | \Drupal calls should be avoided in classes, use
      |         | dependency injection instead
 2042 | WARNING | t() calls should be avoided in classes, use
      |         | \Drupal\Core\StringTranslation\StringTranslationTrait
      |         | and $this->t() instead
 2042 | WARNING | Only string literals should be passed to t() where
      |         | possible
 2130 | WARNING | \Drupal calls should be avoided in classes, use
      |         | dependency injection instead
 2131 | WARNING | t() calls should be avoided in classes, use
      |         | \Drupal\Core\StringTranslation\StringTranslationTrait
      |         | and $this->t() instead
 2131 | WARNING | Translatable strings must not begin or end with
      |         | white spaces, use placeholders with t() for
      |         | variables
 2131 | ERROR   | Concatenating translatable strings is not allowed,
      |         | use placeholders instead and only one string
      |         | literal
 2139 | ERROR   | Public method name "Countries::getDBStructure" is
      |         | not in lowerCamel format
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldFormatter/ContinentDefaultFormatter.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 27 | WARNING | \Drupal calls should be avoided in classes, use
    |         | dependency injection instead
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldFormatter/CountryDefaultFormatter.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 27 | WARNING | \Drupal calls should be avoided in classes, use
    |         | dependency injection instead
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldType/ContinentField.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\Core\Field\FieldStorageDefinitionInterface.
 71 | 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
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldType/CountryField.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\Core\Field\FieldStorageDefinitionInterface.
 71 | 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
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldWidget/ContinentAjaxWidget.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 23 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
 26 | WARNING | [ ] \Drupal calls should be avoided in classes, use
    |         |     dependency injection instead
 34 | 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
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldWidget/ContinentDefaultWidget.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 23 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
 26 | WARNING | [ ] \Drupal calls should be avoided in classes, use
    |         |     dependency injection instead
 33 | 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
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldWidget/CountryContinentWidget.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 5 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------
  34 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
  46 | ERROR   | [x] @inheritDoc found. Did you mean {@inheritDoc}?
  59 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
  71 | WARNING | [ ] t() calls should be avoided in classes, use
     |         |     \Drupal\Core\StringTranslation\StringTranslationTrait
     |         |     and $this->t() instead
  84 | WARNING | [ ] \Drupal calls should be avoided in classes, use
     |         |     dependency injection instead
  93 | WARNING | [ ] \Drupal calls should be avoided in classes, use
     |         |     dependency injection instead
 100 | WARNING | [ ] Unused private method getFieldName()
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ./src/Plugin/Field/FieldWidget/CountryDefaultWidget.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 39 | WARNING | t() calls should be avoided in classes, use
    |         | \Drupal\Core\StringTranslation\StringTranslationTrait
    |         | and $this->t() instead
 52 | WARNING | \Drupal calls should be avoided in classes, use
    |         | dependency injection instead
 70 | WARNING | \Drupal calls should be avoided in classes, use
    |         | dependency injection instead
----------------------------------------------------------------------

Time: 262ms; Memory: 18MB
๐Ÿ“Œ Task
Status

RTBC

Version

1.0

Component

Code

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance lazzyvn paris

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 @lazzyvn
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance lazzyvn paris

    - Replace with Symfony\Component\HttpFoundation\JsonResponse;
    - Translation
    - Add composer.json
    - Summary widget
    - Fixed continent - country widget
    - Fixed all PHP_CodeSniffer

  • Merge request !48.x 1.x โ†’ (Open) created by apaderno
  • Pipeline finished with Failed
    10 months ago
    Total: 37s
    #96606
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Failed
    10 months ago
    Total: 130s
    #96607
  • Pipeline finished with Failed
    10 months ago
    Total: 201s
    #96621
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev16.addweb

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

  • Pipeline finished with Failed
    7 months ago
    Total: 174s
    #186822
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    Actually, the MR created for this issue is for the 8.x-1.x branch.

  • Pipeline finished with Failed
    7 months ago
    Total: 137s
    #186942
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    Hi @apdermo,

    I have applied the latest MR !4 to the Countries Field module against 8.x-1.x-dev on Drupal 10 and confirmed all PHPCS errors have been fixed.

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

    Please see the attached file for reference.

    I'm moving this now to โ€˜RTBCโ€™.

    Thank you!

Production build 0.71.5 2024