Coding standards and best practices

Created on 16 November 2022, about 2 years ago
Updated 26 July 2023, over 1 year ago

Hi, While reviewing the module for best practices and standards. I have found this with the help of PHPCS:

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml yaml_content/

FILE: /var/www/html/dContri/yaml_content/tests/src/Unit/Plugin/yaml_content/process/ReferenceTest.php
-----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
-----------------------------------------------------------------------------------------------------
  11 | WARNING | [x] Unused use statement
  72 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
  99 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
 129 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
-----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Unit/EntityLoadHelper/EntityLoadHelperTest.php
------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 8 WARNINGS AFFECTING 11 LINES
------------------------------------------------------------------------------------------------------------------------
  32 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 149 | WARNING | [x] A comma should follow the last multiline array item. Found: '3c6485e4-69a3-429d-8ab1-3e7df48747bc'
 179 | WARNING | [x] A comma should follow the last multiline array item. Found: '3c6485e4-69a3-429d-8ab1-3e7df48747bc'
 259 | WARNING | [x] A comma should follow the last multiline array item. Found: '3c6485e4-69a3-429d-8ab1-3e7df48747bc'
 274 | WARNING | [ ] Line exceeds 80 characters; contains 84 characters
 289 | WARNING | [x] A comma should follow the last multiline array item. Found: '3c6485e4-69a3-429d-8ab1-3e7df48747bc'
 305 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
 334 | WARNING | [ ] Line exceeds 80 characters; contains 88 characters
 574 | ERROR   | [ ] Missing parameter type
 589 | ERROR   | [ ] Description for the @return value is missing
 600 | ERROR   | [ ] Description for the @return value is missing
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Unit/ContentLoader/ExistenceCheckingTest.php
-----------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 4 WARNINGS AFFECTING 5 LINES
-----------------------------------------------------------------------------------------------
 191 | ERROR   | [x] Expected 1 blank line after function; 2 found
 351 | WARNING | [ ] Unused variable $media_test.
 352 | WARNING | [ ] Unused variable $file_test.
 356 | WARNING | [ ] Unused variable $node_match_test.
 358 | WARNING | [ ] Unused variable $node_no_match_test.
-----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Unit/ContentLoader/ContentLoaderTest.php
-------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 1 WARNING AFFECTING 11 LINES
-------------------------------------------------------------------------------------------
  9 | WARNING | [x] Unused use statement
 48 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 3
 49 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 51 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 52 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 54 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 55 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 57 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 58 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 59 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 5
 60 | ERROR   | [x] Line indented incorrectly; expected 2 spaces, found 3
-------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 11 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Traits/LoadFixturesTrait.php
-------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------
 26 | ERROR | Missing parameter type
-------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Functional/Plugin/yaml_content/process/FileTest.php
------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------
  9 | WARNING | [x] Unused use statement
 32 | ERROR   | [ ] Missing member variable doc comment
------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Functional/NodeImportTest.php
------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
------------------------------------------------------------------------------------------------------------------------
  26 | ERROR | [x] Do not append variable name "$contentDirectory" to the type declaration in a member variable comment
  33 | ERROR | [x] Do not append variable name "$contentLoader" to the type declaration in a member variable comment
  63 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
  64 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
  65 | ERROR | [x] Array closing indentation error, expected 4 spaces but found 6
 108 | ERROR | [x] Missing function doc comment
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/tests/src/Functional/TaxonomyImportTest.php
-------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
-------------------------------------------------------------------------------------------------------------------------
 23 | ERROR   | [x] Do not append variable name "$contentDirectory" to the type declaration in a member variable comment
 30 | ERROR   | [x] Do not append variable name "$contentLoader" to the type declaration in a member variable comment
 74 | WARNING | [ ] Line exceeds 80 characters; contains 83 characters
-------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Plugin/yaml_content/process/LayoutSection.php
------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------
 66 | WARNING | Unused variable $index.
------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Plugin/yaml_content/process/Reference.php
-----------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------
 30 | ERROR | Parameter $entity_type_manager is not described in comment
 39 | ERROR | Doc comment for parameter $entity_manager does not match actual variable name $entity_type_manager
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Plugin/yaml_content/process/File.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
 35 | WARNING | [x] 'TODO path not set.' should match the format '@todo Fix problem X here.'
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Commands/YamlContentCommands.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
 94 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Service/LoadHelper.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
  90 | WARNING | Line exceeds 80 characters; contains 81 characters
 116 | WARNING | Line exceeds 80 characters; contains 81 characters
----------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Service/EntityLoadHelper.php
-------------------------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 9 LINES
-------------------------------------------------------------------------------------------------------------------------------
  20 | ERROR | [x] Do not append variable name "$requiresSpecialHandling" to the type declaration in a member variable comment
  33 | ERROR | [x] Do not append variable name "$container" to the type declaration in a member variable comment
 119 | ERROR | [ ] Missing parameter type
 124 | ERROR | [ ] Description for the @return value is missing
 174 | ERROR | [ ] Parameter tags must be defined first in a doc comment
 206 | ERROR | [ ] Missing parameter type
 225 | ERROR | [ ] Missing parameter type
 303 | ERROR | [ ] Missing parameter type
 333 | ERROR | [ ] Missing parameter type
-------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/Annotation/YamlContentProcess.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
 13 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/src/ContentLoader/ContentLoader.php
----------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------
 95 | ERROR | Missing short description in doc comment
----------------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/yaml_content.drush.inc
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 116 | ERROR | [x] Expected 1 newline at end of file; 2 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: /var/www/html/dContri/yaml_content/README.txt
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
 41 | WARNING | Line exceeds 80 characters; contains 84 characters
 42 | WARNING | Line exceeds 80 characters; contains 81 characters
 46 | WARNING | Line exceeds 80 characters; contains 82 characters
----------------------------------------------------------------------

I have fixed these and have provided the patch.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇮🇳India akshay.singh Noida

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024