Fix the errors/warnings reported by PHP_CodeSniffer

Created on 11 February 2024, 4 months ago
Updated 31 May 2024, 24 days 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

Needs review

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

Production build 0.69.0 2024