Fix the issues reported by phpcs

Created on 11 May 2023, about 1 year ago
Updated 4 August 2023, 11 months ago

Problem/Motivation

C:\xampp\htdocs\backendassignment\web\modules\contrib>phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig serial

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\serial.install
----------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
----------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\serial.module
----------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
----------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------

FILE: ...mpp\htdocs\backendassignment\web\modules\contrib\serial\src\Plugin\Field\FieldFormatter\SerialDefaultFormatter.php
------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
33 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\src\Plugin\Field\FieldType\SerialItem.php
------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
124 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
131 | 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: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\src\Plugin\Field\FieldWidget\SerialDefaultWidget.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\src\SerialSQLStorage.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
150 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\src\SerialStorageInterface.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\templates\serial-default.html.twig
-----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------
1 | ERROR | [x] Expected 1 newline at end of file; 0 found
-----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------

FILE: C:\xampp\htdocs\backendassignment\web\modules\contrib\serial\tests\src\Functional\SerialFieldTest.php
------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
20 | ERROR | [ ] Missing @var tag in member variable comment
142 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait
| | and $this->t() instead
168 | 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: 1.85 secs; Memory: 6MB

Steps to reproduce

Run the phpcs command on the module.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India sidharth_soman Bangalore

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 @sidharth_soman
  • 🇮🇳India sidharth_soman Bangalore

    I am working on this and will provide an MR.

  • Status changed to Active about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Since there are not patches nor MRs, the status is still Active.

  • @sidharth_soman opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sidharth_soman Bangalore
  • Status changed to Needs work about 1 year ago
  • 🇨🇴Colombia metallized

    I still getting this

    FILE: /home/drupal/serial/src/SerialSQLStorage.php
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------
     150 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    
    FILE: /home/drupal/serial/src/Plugin/Field/FieldFormatter/SerialDefaultFormatter.php
    ------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------
     33 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ------------------------------------------------------------------------------------------------------
    
    Time: 275ms; Memory: 10MB
    

    the output of phpcs -i:

    The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard
    
  • First commit to issue fork.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sakthi_dev

    Please review.

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * Drupal\Core\Render\RendererInterface definition.
    +   *
    +   * @var \Drupal\Core\Render\RendererInterface
    +   */
    +  protected $renderer;

    The short description must not repeat the class name (which is already given in the @var line) nor contain just the class name and definition. (Drupal\Core\Render\RendererInterface definition. is not even correct, since a class property is not an interface definition.)

    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(RendererInterface $renderer) {
    +    $this->renderer = $renderer;
    +  }

    {@inheritdoc} is not used in documentation comments for constructors.
    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.
    The documentation description for a constructor must describe its parameters.

    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function __construct(RendererInterface $renderer) {
    +    $this->renderer = $renderer;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static function create(ContainerInterface $container) {
    +    return new static(
    +      $container->get('renderer')
    +    );
    +  }

    Since this class extends FormatterBase, that code is not correct. The parent class constructor is not called.

    -          \Drupal::messenger()->addMessage(t('Serial values have been automatically set for %count existing entities, starting from %start_value.', [
    +          \Drupal::messenger()->addMessage($this->t('Serial values have been automatically set for %count existing entities, starting from %start_value.', [

    The messenger should be injected too, or phpcs would still complain with \Drupal calls should be avoided in classes, use dependency injection.

  • Assigned to imustakim
  • 🇮🇳India imustakim Ahmedabad
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India imustakim Ahmedabad
  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    +  /**
    +   * Constructs a new SerialDefaultFormatter object.
    +   *
    +   * @param \Drupal\Core\Render\RendererInterface $renderer
    +   *   The renderer.
    +   */
    +  public function __construct(RendererInterface $renderer) {
    +    $this->renderer = $renderer;
    +  }

    The class name is still missing its namespace.
    What is more important, the constructor is not calling the constructor for the parent class, the create() method is missing.
    This means the changed code does not work. I would suggest to check what a class like OEmbedFormatter does.

    Since that is introducing a bug in the code, that must be immediately corrected.

  • 🇨🇴Colombia metallized

    Hey, if you get lost just follow this guide → .

  • Status changed to Needs review about 1 year ago
  • 🇨🇴Colombia metallized

    This was fixed on dev, can anyone please review, thanks.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    This is an issue that reports only PHP_CodeSniffer warnings/errors.

  • 🇨🇴Colombia metallized

    Can anyone review this so we can change to RTBC, thanks.

  • Status changed to Fixed 11 months ago
  • 🇨🇴Colombia metallized

    Released a new version with this fix, thanks to all.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024