Fix 'Generic.CodeAnalysis.UselessOverridingMethod' coding standard

Created on 28 March 2020, almost 5 years ago
Updated 18 November 2023, about 1 year ago

Part of 🌱 [meta] Fix PHP coding standards in core Active .

Approach

We are testing coding standards with PHP CodeSniffer, using the Drupal coding standards from the Coder module. Both of these packages are not installed in Drupal core. We need to do a couple of steps in order to download and configure them so we can run a coding standards check.

How to run tests?

Clone changes from branch 3123069-11.x-useless-overriding-method.
Run the following command from Drupal root to launch the test:

$ phpcs --standard=core/phpcs.xml.dist -- '--report-full' '--report-summary' -p core

This takes a couple of minutes. The -p flag shows the progress, so you have a bunch of nice dots to look at while it is running.

Fix the failures

When the test is complete it will present you a list of all the files that contain violations of your sniff, and the line numbers where the violations occur. You could fix all of these manually.
You can then make a diff of the changes using git. You can also re-run the test with phpcs and determine if that fixed all of them.

Current failures on 11.x

PHP CODE SNIFFER REPORT SUMMARY
---------------------------------------------------------------------------------------------------------------------------------
FILE                                                                                                             ERRORS  WARNINGS
---------------------------------------------------------------------------------------------------------------------------------
core/lib/Drupal/Core/Action/ActionPluginCollection.php                                             0       1
core/lib/Drupal/Core/Condition/ConditionPluginCollection.php                                       0       1
core/lib/Drupal/Core/Config/InstallStorage.php                                                     0       1
core/lib/Drupal/Core/Config/Entity/Query/Query.php                                                 0       1
core/lib/Drupal/Core/Installer/InstallerKernel.php                                                 0       1
core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php                                    0       2
core/lib/Drupal/Core/Layout/LayoutDefault.php                                                      0       1
core/lib/Drupal/Core/Queue/QueueWorkerManager.php                                                  0       1
core/lib/Drupal/Core/Render/ElementInfoManager.php                                                 0       1
core/lib/Drupal/Core/Test/TestRunnerKernel.php                                                     0       1
core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/EmailValidator.php                    0       1
core/modules/block/src/BlockPluginCollection.php                                                   0       1
core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditorStylesheetsWarningTest.php           0       1
core/modules/comment/tests/src/Functional/Views/CommentApproveLinkTest.php                         0       1
core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php                         0       1
core/modules/config_translation/src/Form/ConfigTranslationAddForm.php                              0       1
core/modules/filter/src/FilterFormatAddForm.php                                                    0       1
core/modules/filter/src/FilterPluginCollection.php                                                 0       1
core/modules/forum/tests/src/Functional/Views/ForumIntegrationTest.php                             0       1
core/modules/image/src/ImageEffectPluginCollection.php                                             0       1
core/modules/jsonapi/tests/src/Functional/MediaTest.php                                            0       1
core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php                     0       1
core/modules/migrate/tests/src/Kernel/Plugin/LogTest.php                                           0       1
core/modules/migrate/tests/src/Unit/SqlBaseTest.php                                                0       1
core/modules/migrate/tests/src/Unit/TestMigrateExecutable.php                                      0       1
core/modules/migrate/tests/src/Unit/TestSqlIdMap.php                                               0       3
core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php                             0       2
core/modules/migrate/tests/src/Unit/process/SubstrTest.php                                         0       1
core/modules/migrate_drupal/tests/modules/field_discovery_test/src/FieldDiscoveryTestClass.php     0       6
core/modules/node/src/Entity/Node.php                                                              0       1
core/modules/node/tests/src/Functional/Views/NodeTestBase.php                                      0       1
core/modules/options/tests/src/Kernel/OptionsFormattersTest.php                                    0       1
core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php                                          0       1
core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php                                  0       1
core/modules/search/src/Plugin/SearchPluginCollection.php                                          0       1
core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php             0       1
core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php                    0       1
core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php                   0       1
core/modules/system/src/Plugin/ImageToolkit/Operation/gd/GDImageToolkitOperationBase.php           0       1
core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php                            0       1
core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMul.php                         0       1
core/modules/system/tests/src/Functional/Datetime/DrupalDateTimeTest.php                           0       1
core/modules/system/tests/src/Functional/Render/UrlBubbleableMetadataBubblingTest.php              0       1
core/modules/system/tests/src/Functional/System/IndexPhpTest.php                                   0       1
core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php                                 0       1
core/modules/taxonomy/tests/src/Functional/Views/TaxonomyParentUITest.php                          0       1
core/modules/tour/src/TipsPluginCollection.php                                                     0       1
core/modules/user/tests/src/Functional/AccessRoleUITest.php                                        0       1
core/modules/user/tests/src/Functional/Views/AccessRoleTest.php                                    0       1
core/modules/views/src/DisplayPluginCollection.php                                                 0       1
core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php                                      0       1
core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php                            0       1
core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php                            0       1
core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php                                   0       1
core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php                                0       1
core/tests/Drupal/Tests/Core/Entity/Routing/DefaultHtmlRouteProviderTest.php                       0       5
core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php                                0       2
core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php                      0       2
core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php                         0       1
---------------------------------------------------------------------------------------------------------------------------------
A TOTAL OF 0 ERRORS AND 74 WARNINGS WERE FOUND IN 59 FILES
---------------------------------------------------------------------------------------------------------------------------------
πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
OtherΒ  β†’

Last updated 8 minutes ago

Created by

πŸ‡¨πŸ‡³China jungle Chongqing, China

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

Not all content is available!

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

  • πŸ‡·πŸ‡ΊRussia zniki.ru

    zniki.ru β†’ made their first commit to this issue’s fork.

  • @znikiru opened merge request.
  • Status changed to Needs review about 1 year ago
  • πŸ‡·πŸ‡ΊRussia zniki.ru

    I wasn't able to find any commits in the branch 3123069-fix-generic.codeanalysis.uselessoverridingmethod-coding.
    Compare to 9.4.x
    And I wasn't able to merge changes to 11.x, so I decide to create a new branch.

    I create draft MR with some changes, and I want to get some feedback about approach.
    I update issue description and change target branch for this issue.

  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    I still think we need to decide what to do about #2, where the updated return type does add value for people using IDEs and perhaps static analysis too. Just removing them all outright seems like we are losing information.

    Ideally we would just add return types everywhere anyway, and it is valid to return a more specific type in a subclass because of covariance, but we can't do that without breaking backward compatibility where contrib or custom code might have already extended without adding a type.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    For #13

Production build 0.71.5 2024