Fix the issues reported by phpcs

Created on 9 May 2023, over 1 year ago
Updated 22 May 2023, over 1 year ago

Problem/Motivation

vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig web/modules/contrib/paragraph_blocks/

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/ParagraphBlocksEntityManager.php
------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 6 WARNINGS AFFECTING 8 LINES
------------------------------------------------------------------------------------------------------------------
14 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
68 | WARNING | Line exceeds 80 characters; contains 91 characters
73 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
84 | ERROR | Missing parameter comment
86 | ERROR | Description for the @return value is missing
93 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
98 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
103 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/ParagraphBlocksLabeller.php
--------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
--------------------------------------------------------------------------------------------------
163 | ERROR | [x] Object operator not indented correctly; expected 6 spaces but found 8
169 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
170 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
192 | ERROR | [ ] Missing parameter comment
193 | ERROR | [ ] Missing parameter comment
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/Controller/ParagraphBlocksPanelsController.php
----------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------
21 | WARNING | [x] '@todo: Should this be a panels IPE patch?' should match the format '@todo Fix problem X here.'
23 | WARNING | [x] '@todo: Is there a way to let blockManager contexts filter this so that we' should match the format '@todo Fix problem X here.'
----------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/Plugin/Block/ParagraphBlock.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 8 ERRORS AND 2 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
219 | ERROR | [ ] Missing parameter comment
221 | ERROR | [x] Expected "\Drupal\paragraphs\Entity\Paragraph" but found "?\Drupal\paragraphs\Entity\Paragraph" for function return type
221 | ERROR | [ ] Description for the @return value is missing
230 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
231 | ERROR | [x] Object operator not indented correctly; expected 6 spaces but found 8
233 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
244 | ERROR | [ ] Missing parameter comment
244 | ERROR | [x] Data types in @param tags need to be fully namespaced
246 | ERROR | [x] Expected "\Drupal\paragraphs\Entity\Paragraph" but found "?\Drupal\paragraphs\Entity\Paragraph" for function return type
246 | ERROR | [ ] Description for the @return value is missing
----------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/Plugin/Deriver/ParagraphBlocksDeriver.php
-----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------
68 | WARNING | Unused variable $field_storage_type.
-----------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/ParagraphBlocksEntityPresaveHelper.php
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 47 ERRORS AND 4 WARNINGS AFFECTING 48 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
12 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
25 | ERROR | [x] Expected "\Drupal\Core\TempStore\PrivateTempStore" but found "?\Drupal\Core\TempStore\PrivateTempStore" for @var tag in member variable comment
42 | ERROR | [ ] Content missing for @var tag in member variable comment
70 | ERROR | [x] Object operator not indented correctly; expected 6 spaces but found 8
82 | ERROR | [ ] Description for the @return value is missing
89 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
139 | ERROR | [x] Object operator not indented correctly; expected 10 spaces but found 12
141 | ERROR | [x] Object operator not indented correctly; expected 12 spaces but found 21
141 | WARNING | [ ] Unused variable $delta.
152 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
172 | ERROR | [ ] Description for the @return value is missing
183 | ERROR | [ ] Description for the @return value is missing
189 | ERROR | [x] Object operator not indented correctly; expected 8 spaces but found 10
199 | ERROR | [ ] Missing parameter comment
199 | ERROR | [ ] Missing parameter type
201 | ERROR | [ ] Description for the @return value is missing
206 | ERROR | [x] Object operator not indented correctly; expected 6 spaces but found 15
215 | ERROR | [ ] Missing parameter comment
217 | ERROR | [ ] Description for the @return value is missing
233 | ERROR | [ ] Missing parameter comment
234 | ERROR | [ ] Missing parameter comment
236 | ERROR | [ ] Description for the @return value is missing
254 | ERROR | [ ] Missing parameter comment
255 | ERROR | [ ] Missing parameter comment
256 | ERROR | [ ] Missing parameter comment
258 | ERROR | [ ] Description for the @return value is missing
273 | ERROR | [ ] Missing parameter comment
274 | ERROR | [ ] Missing parameter comment
275 | ERROR | [ ] Missing parameter comment
276 | ERROR | [ ] Missing parameter comment
277 | ERROR | [ ] Missing parameter comment
278 | ERROR | [ ] Missing parameter comment
280 | ERROR | [ ] Description for the @return value is missing
286 | ERROR | [x] Object operator not indented correctly; expected 10 spaces but found 12
288 | ERROR | [x] Object operator not indented correctly; expected 10 spaces but found 12
305 | ERROR | [ ] Missing parameter comment
307 | ERROR | [ ] Description for the @return value is missing
310 | ERROR | [ ] The array declaration extends to column 146 (the limit is 80). The array content should be split up over multiple lines
326 | ERROR | [ ] Missing parameter comment
327 | ERROR | [ ] Missing parameter comment
328 | ERROR | [ ] Missing parameter comment
329 | ERROR | [ ] Missing parameter comment
329 | ERROR | [ ] Missing parameter type
330 | ERROR | [ ] Missing parameter comment
331 | ERROR | [ ] Missing parameter comment
332 | ERROR | [ ] Missing parameter comment
334 | ERROR | [ ] Description for the @return value is missing
339 | ERROR | [x] Object operator not indented correctly; expected 8 spaces but found 10
355 | ERROR | [ ] Missing parameter comment
357 | ERROR | [ ] Description for the @return value is missing
360 | ERROR | [ ] The array declaration extends to column 142 (the limit is 80). The array content should be split up over multiple lines
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/src/Entity/ParagraphBlocksEntity.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
60 | ERROR | Description for the @return value is missing
--------------------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/paragraph_blocks.install
--------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
--------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------

FILE: /var/www/html/vbd9/web/modules/contrib/paragraph_blocks/paragraph_blocks.module
---------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------
106 | WARNING | [x] '@todo: Allow multiple modules to override this class (with reflection)?' should match the format '@todo Fix problem X here.'
210 | ERROR | [x] Missing function doc comment
---------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------------

Time: 1.73 secs; Memory: 14MB

Steps to reproduce

Proposed resolution

RUN::

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig web/modules/contrib/paragraph_blocks/

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇳India dineshkumarbollu

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

    Hi
    I fixed the all phpcs issues including DI except (\Drupal::moduleHandler()->moduleExists('content_moderation')) this type of DI

    Please review.

    Thanks

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India Anmol_Specbee

    The patch does not apply cleanly and not all the issues reported by phpcs are fixed. Attaching a screenshot for reference.

  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    I will work on this issue and raise the MR for the same.

  • @akshaydalvi212 opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India akshaydalvi212

    Raised the MR which removes all the reported errors.
    only warning as unused variables $field_storage_type and $delta is remaining which need to be confirmed from module maintainers.
    kindly review the MR.

  • 🇮🇳India Jaspreet-Kaur

    MR! 17 successfully applied on Drupal 9.5.x

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇳🇱Netherlands basvredeling Amsterdam
  • Assigned to akshaydalvi212
  • 🇮🇳India akshaydalvi212

    I will update the MR as per comments added on the MR.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India akshaydalvi212

    Updated the MR as per suggested.
    kindly review the MR.

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    --- a/paragraph_blocks.install
    +++ b/paragraph_blocks.install
    @@ -1,5 +1,10 @@
     <?php
     
    +/**
    + * @file
    + * Contains install, update functions to DB.
    + */
    +

    The correct description is Install, update, and uninstall hooks for the Paragraph blocks module.

       * @return bool
    +   *   Returns length of admin title.
        */
       public function hasAdminTitle(): bool {

    Since the return value is a Boolean, it cannot be the title length. The method name should give a hint on what that method returns.

     /**
    - * Class ParagraphBlocksEntityManager.
    + * Defines ParagraphBlocksEntityManager class.
      */

    Even with Defines, that description merely repeats the class name. It must describe the class purpose.

        * @param \Drupal\Core\Entity\ContentEntityInterface $entity
    +   *   ContentEntityInterface service.

    That is not a service, so it cannot be described as such.

        * @return \Drupal\Core\Entity\ContentEntityInterface
    +   *   Returns ContentEntityInterface service.
        *
        * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
        * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
        */
       public function getLatestEntityRevision(ContentEntityInterface &$entity): ContentEntityInterface {

    The method does not return a service. (See the method name for a possible hint of what the method returns.)

    -    $moderation_info = \Drupal::service('content_moderation.moderation_information');
    +    // \Drupal::service('content_moderation.moderation_information');
    +    $moderation_info = $this->moderationInformation;

    It is not necessary to comment out the previously used code.

    +  /**
    +   * The Drupal Logger Factory.
    +   *
    +   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
    +   */
    +  protected $loggerFactory;
    +

    There is no need to add Drupal in descriptions.
    In that description, only the first word must be capitalized.

    -   * @var
    +   * @var layout
        */
       private $layout;

    layout is not a PHP type and it cannot be used with @var.

        * @return array
    +   *   Return fields.
        */

    The return value description must not start with Return.

    -   * @param $field
    +   * @param mixed $field
    +   *   Provide field.

    Parameter descriptions must not start with Provide.

        * @return array
    +   *   Returns deltas fields before save.
        */
       private function getDeltasOriginal($field): array {

    That description is not clear and probably not correct.

        * @param mixed $field
    +   *   List of Fields.

    Given the parameter name, that is probably not a list of fields.

        * @param array $new_paragraph_ids
    +   *   Paragraph ids.

    The correct spelling for ids is IDs.

        * @param string $field
    +   *   Field string.
        * @param array $configuration
    +   *   Configuration array.

    Those descriptions are each missing a definite article.

        * @param int|string $section_index
    +   *   Section_index.
        * @param int|string $component_index
    -   *
    -   * @return void
    +   *   Component_index.

    Those descriptions are merely repeating the parameter name.

    +   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
    +   *   The module handler service.
        */

    There is no need to say that is a service.

  • Assigned to imustakim
  • 🇮🇳India imustakim Ahmedabad

    Working on this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India imustakim Ahmedabad

    All the warnings and errors are resolved except these 2 warnings, It is caused by including the class namespace in constructor description, hence assuming this can be ignored.
    Updated patch is attached.
    Please review.

    ❯ phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml .
    
    FILE: /Users/specbee/Sites/Projects/paragraph_blocks/src/ParagraphBlocksEntityPresaveHelper.php
    -----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------
     51 | WARNING | Line exceeds 80 characters; contains 85 characters
    -----------------------------------------------------------------------------------------------
    
    
    FILE: /Users/specbee/Sites/Projects/paragraph_blocks/src/ParagraphBlocksEntityManager.php
    -----------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------
     55 | WARNING | Line exceeds 80 characters; contains 83 characters
    -----------------------------------------------------------------------------------------
    
    Time: 351ms; Memory: 12MB
    
  • 🇳🇱Netherlands basvredeling Amsterdam

    #15 was a big improvement but also contained a couple of nasty typos. Here's an updated patch. Could you please review?

  • 🇳🇱Netherlands basvredeling Amsterdam
  • 🇳🇱Netherlands basvredeling Amsterdam
  • Status changed to Fixed over 1 year ago
  • 🇳🇱Netherlands basvredeling Amsterdam

    Made some extra changes to the services after #18.
    Thanks for your efforts all.

  • Status changed to Fixed over 1 year ago
  • 🇳🇱Netherlands basvredeling Amsterdam
Production build 0.71.5 2024