Fix the issues reported by phpcs

Created on 6 February 2023, almost 2 years ago
Updated 2 April 2024, 9 months ago

Problem/Motivation

A scan of this module identifies some coding standards issues:

> ./vendor/bin/phpcs -p --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md --ignore=node_modules,vendor ./web/modules/contrib/jsonapi_resources
...W..EE.WEEEEEEEEEE.E.EEEEEEEEE 32 / 32 (100%)



FILE: /var/www/html/web/modules/contrib/jsonapi_resources/tests/modules/jsonapi_resources_test/src/Resource/CurrentUserInfo.php
----------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------------
 122 | WARNING | [x] '@todo: convert this to a ResourceTypeRelationship.' should match the format '@todo Fix problem X here.'
 127 | WARNING | [x] '@todo: Add role entities as a relatable resource type.' should match the format '@todo Fix problem X here.'
----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/tests/src/Kernel/Routing/ResourceEnhancerTest.php
-----------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
-----------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/tests/src/Unit/Routing/ResourceRoutesTest.php
--------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------
 38 | ERROR | The array declaration extends to column 149 (the limit is 80). The array content should be split up over multiple lines
--------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/README.md
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
 3 | WARNING | Line exceeds 80 characters; contains 119 characters
 4 | WARNING | Line exceeds 80 characters; contains 116 characters
----------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Exception/ResourceImplementationException.php
-----------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
-----------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Exception/RouteDefinitionException.php
----------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Entity/Query/PaginatorInterface.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Entity/Query/PaginatorMetadata.php
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Resource/ResourceBase.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
 118 | WARNING | [x] '@todo: try to move this exception into Drupal\jsonapi_resources\Routing\ResourceRoutes::ensureResourceImplementationValid().' should match the format '@todo
     |         |     Fix problem X here.'
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Resource/EntityQueryResourceBase.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Resource/EntityResourceBase.php
---------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/DependencyInjection/JsonapiResourceClassResolver.php
---------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
---------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/DocumentExtractor.php
-------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------------------------------------
   1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
 122 | ERROR | [ ] The array declaration extends to column 100 (the limit is 80). The array content should be split up over multiple lines
-------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Routing/Enhancer/ResourceEnhancer.php
------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/ResourceResponseFactory.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Value/NewResourceObject.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/ResourceObjectToEntityMapperAwareTrait.php
------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/Query/CacheabilityCapturingExecutor.php
---------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/Query/Pagination/OffsetLimitPaginator.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/ResourceObjectToEntityMapperAwareInterface.php
----------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/EntityCreationTrait.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
 62 | WARNING | [x] '@todo: remove the assignment of the entity type manager to a variable when an "Aware" interface is added.' should match the format '@todo Fix problem X here.'
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Entity/ResourceObjectToEntityMapper.php
--------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
--------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Controller/ArgumentResolver/DocumentResolver.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------
 1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/web/modules/contrib/jsonapi_resources/src/Unstable/Controller/JsonapiResourceController.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
 64 | ERROR | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
-----------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------------------------
📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇯🇵Japan ptmkenny

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 @ptmkenny
  • Merge request !3Issue #3339626: Fix coding standards → (Merged) created by ptmkenny
  • 🇯🇵Japan ptmkenny

    This MR fixes all the coding standards issues.

  • Status changed to Needs work over 1 year ago
  • 🇵🇭Philippines paraderojether

    Hi ptmkenny

    I reviewed MR!3, and confirmed it fixes all the issue that you addressed. However I'm getting this new issue/warning that is shown below:

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/jsonapi_resources/tests/modules/jsonapi_resources_test/jsonapi_resources_test.info.yml
    -------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------------------------------
    1 | WARNING | "Description" property is missing in the info.yml file
    -------------------------------------------------------------------------------------------------------------------------------------------------------------

    Time: 1.02 secs; Memory: 12MB

    Please check.
    Thank You.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    7 pass
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India bharath-kondeti Hyderabad

    Updated the MR with the changes. Please review the same.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -        // @todo: try to move this exception into Drupal\jsonapi_resources\Routing\ResourceRoutes::ensureResourceImplementationValid().
    +        // @todo try to move this exception into Drupal\jsonapi_resources\Routing\ResourceRoutes::ensureResourceImplementationValid().

    What follows @todo is a sentence: It starts with a capitalized word and ends with a period.

    -    $args = $this->argumentResolver->getArguments($request, [$resource, 'process']);
    +    $args = $this->argumentResolver->getArguments(
    +    $request,
    +    [$resource, 'process'],
    +    );

    Lines are allowed to be longer than 80 characters, if they are more readable. The existing code is more readable than the changed code.

    +      if (!empty(array_intersect_key(
    +      $decoded['data'][0], array_flip(['attributes', 'relationships'])
    +      ))) {
             throw new UnprocessableEntityHttpException("To add or update a resource object, the request document's primary data must not be an array.");
           }

    As per Drupal coding standards, control structures are written in a single line.

    -    $route_collection->add('jsonapi_resource_multi_method_route', new Route('/%jsonapi%/resource', $route_defaults, [], [], '', [], ['POST', 'PATCH']));
    +    $route_collection->add('jsonapi_resource_multi_method_route', new Route(
    +    '/%jsonapi%/resource',
    +    $route_defaults,
    +    [],
    +    [],
    +    '',
    +    [],
    +    ['POST', 'PATCH'],
    +    ));

    The existing code is more readable.

  • Assigned to nitin_lama
  • Merge request !4Updating ResourceBase.php → (Closed) created by nitin_lama
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    7 pass
  • Issue was unassigned.
  • 🇮🇳India nitin_lama India

    Updated pointer 1.

  • First commit to issue fork.
  • First commit to issue fork.
  • 🇮🇳India Shank115

    These are remaining issues.

    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml jsonapi_resources/
    
    FILE: /home/sites/jsonapi_resources/src/Unstable/Controller/JsonapiResourceController.php
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------------
     66 | ERROR | The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
    -------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/sites/jsonapi_resources/src/Unstable/DocumentExtractor.php
    ---------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------------------------------
     124 | ERROR | The array declaration extends to column 100 (the limit is 80). The array content should be split up over multiple lines
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/sites/jsonapi_resources/tests/src/Unit/Routing/ResourceRoutesTest.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------
     38 | ERROR | The array declaration extends to column 149 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------------------------------------------------------------
  • Assigned to nitin_lama
  • 🇮🇳India nitin_lama India

    Code is more readable for the remaining issues, no need to fix. Lets see what the maintainer says.

  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • First commit to issue fork.
  • 🇺🇸United States mglaman WI, USA

    There are two MRs. That's confusing. I rebased both to have GitLab CI running and determine which is most correct.

  • 🇺🇸United States mglaman WI, USA
  • Pipeline finished with Skipped
    9 months ago
    #123358
  • Status changed to Fixed 9 months ago
  • 🇺🇸United States mglaman WI, USA

    Merged, thanks everyone!

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

Production build 0.71.5 2024