drupal-console icon indicating copy to clipboard operation
drupal-console copied to clipboard

[generate:entity:content] Coding Standards Errors

Open thursdaybw opened this issue 10 years ago • 5 comments

Generated code from generate:entity:content and possibly many other scaffolding commands results in module code with numerous coding standards errors.

for example

FILE: .../web/modules/custom/digital_assets/src/DigitalAssetInterface.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
----------------------------------------------------------------------
 22 | ERROR   | [x] Expected 1 blank line before function; 0 found
 76 | WARNING | [ ] Line exceeds 80 characters; contains 83
    |         |     characters
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...eb/modules/custom/digital_assets/src/DigitalAssetListBuilder.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 20 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...odules/custom/digital_assets/src/DigitalAssetTypeListBuilder.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 15 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...ules/custom/digital_assets/src/DigitalAssetHtmlRouteProvider.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 19 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...ules/custom/digital_assets/src/Form/DigitalAssetSettingsForm.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 22 | ERROR | [x] Expected 1 blank line before function; 0 found
 36 | ERROR | [x] Expected 1 blank line after function; 2 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../modules/custom/digital_assets/src/Form/DigitalAssetTypeForm.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 17 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../web/modules/custom/digital_assets/src/Form/DigitalAssetForm.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 17 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...es/custom/digital_assets/src/Form/DigitalAssetTypeDeleteForm.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 16 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...dules/custom/digital_assets/src/Entity/DigitalAssetViewsData.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 15 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...is/web/modules/custom/digital_assets/src/Entity/DigitalAsset.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 65 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...s/custom/digital_assets/src/DigitalAssetAccessControlHandler.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 19 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...stom/digital_assets/src/Controller/DigitalAssetAddController.php
----------------------------------------------------------------------
FOUND 7 ERRORS AND 5 WARNINGS AFFECTING 10 LINES
----------------------------------------------------------------------
  7 | WARNING | [x] Unused use statement
 11 | ERROR   | [x] There must be one blank line after the last USE
    |         |     statement; 2 found;
 20 | ERROR   | [x] Line indented incorrectly; expected 2 spaces,
    |         |     found 4
 20 | ERROR   | [x] Missing function doc comment
 20 | ERROR   | [x] Expected 1 blank line before function; 0 found
 21 | ERROR   | [x] Line indented incorrectly; expected 4 spaces,
    |         |     found 6
 22 | ERROR   | [x] Line indented incorrectly; expected 4 spaces,
    |         |     found 6
 35 | ERROR   | [x] Expected 1 blank line after function; 0 found
 43 | WARNING | [ ] Line exceeds 80 characters; contains 90
    |         |     characters
 44 | WARNING | [ ] Line exceeds 80 characters; contains 119
    |         |     characters
 64 | WARNING | [ ] Line exceeds 80 characters; contains 82
    |         |     characters
 76 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: )
----------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: .../custom/digital_assets/src/DigitalAssetTypeHtmlRouteProvider.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 19 | ERROR | [x] Expected 1 blank line before function; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...l/doris/web/modules/custom/digital_assets/digital_asset.page.inc
----------------------------------------------------------------------
FOUND 12 ERRORS AND 1 WARNING AFFECTING 13 LINES
----------------------------------------------------------------------
 35 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 36 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 37 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 38 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 39 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 40 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 41 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 42 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 43 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 44 | ERROR   | [x] Expected 1 space(s) before asterisk; 0 found
 51 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: )
 54 | ERROR   | [x] Array indentation error, expected 8 spaces but
    |         |     found 6
 58 | ERROR   | [x] Array indentation error, expected 8 spaces but
    |         |     found 6
----------------------------------------------------------------------
PHPCBF CAN FIX THE 13 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...al/doris/web/modules/custom/digital_assets/digital_assets.module
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 45 | ERROR | [x] Expected 1 space(s) before asterisk; 0 found
 46 | ERROR | [x] Expected 1 space(s) before asterisk; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 253ms; Memory: 8.5Mb

thursdaybw avatar Apr 24 '16 04:04 thursdaybw

@thursdaybw , this is because recently Drupal change their coding standards and we need to fix them.

Thanks for filling up this issue.

itsdarrylnorris avatar Apr 24 '16 15:04 itsdarrylnorris

We need to validate every generator and fix those errors.

jmolivas avatar Apr 24 '16 21:04 jmolivas

It seems that a number of the standards errors have been fixed, however some new ones have popped up. Using the latest version of Drupal Console, I ran drupal generate:entity:content with the default options. I then ran PHP Coder Sniffer using the standards defined by the Coder module and got the following results:

FILE: modules/custom/test/src/Controller/TempController.php
---------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
---------------------------------------------------------------------------------------------------------------------------------
  91 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 106 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 132 | ERROR   | If the line declaring an array spans longer than 80 characters, each element should be broken into its own line
---------------------------------------------------------------------------------------------------------------------------------


FILE: modules/custom/test/src/Entity/TempInterface.php
----------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------------
  7 | WARNING | [x] Unused use statement
  8 | WARNING | [x] Unused use statement
 19 | WARNING | [x] There must be no blank line following an inline comment
 19 | WARNING | [ ] There must be no blank line following an inline comment
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------


FILE: modules/custom/test/src/Entity/TempViewsData.php
----------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 1 LINE
----------------------------------------------------------------------------
 19 | WARNING | [x] There must be no blank line following an inline comment
 19 | WARNING | [ ] There must be no blank line following an inline comment
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------


FILE: modules/custom/test/src/Form/TempForm.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 31 | WARNING | Unused variable $entity.
----------------------------------------------------------------------


FILE: modules/custom/test/src/TempTranslationHandler.php
----------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 1 LINE
----------------------------------------------------------------------------
 12 | WARNING | [x] There must be no blank line following an inline comment
 12 | WARNING | [ ] There must be no blank line following an inline comment
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------


FILE: modules/custom/test/temp.page.inc
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 24 | WARNING | Unused variable $temp.
----------------------------------------------------------------------

They all seem like they would be fairly straightforward to fix, but I'm not exactly sure what the right approach is for these warnings:

\Drupal calls should be avoided in classes, use dependency injection instead

The easiest way to fix this seems to be to update entry-controller.php.twig so that it has a constructor and implements its own create method so that the date formatter and renderer services are injected into generated entity controllers by default. That or I suppose a services option could be added to the generator command, similar to how some other generators have one?

s-robertson avatar Jan 16 '17 21:01 s-robertson

AjaxCommand.php - https://github.com/hechoendrupal/drupal-console/pull/3708

LOBsTerr avatar Jan 19 '18 14:01 LOBsTerr

AuthenticationProviderCommand.php - https://github.com/hechoendrupal/drupal-console/pull/3709

LOBsTerr avatar Jan 19 '18 15:01 LOBsTerr