Rename validator methods to `validate` unless there different methods for different events

Created on 15 February 2023, over 2 years ago
Updated 21 February 2023, over 2 years ago

Problem/Motivation

package_manager/src/Validator/PreOperationStageValidatorInterface.php has been delete

We used the name validateStagePreOperation many places because we use implement this interface

Steps to reproduce

Proposed resolution

In all validators where there is only 1 method is subscribed to 1 or more events rename that method to validate(). Usually not that method is validateStagePreOperation but not always. Replace all the {@inheritdoc} comments that are left over from when validateStagePreOperation was part of an interface

Examples

In cases like LockFileValidator where we have

PreCreateEvent::class => 'storeHash',
      PreRequireEvent::class => 'validateStagePreOperation',
      PreApplyEvent::class => 'validateStagePreOperation',
      StatusCheckEvent::class => 'validateStagePreOperation',
      PostDestroyEvent::class => 'deleteHash',

Cases like \Drupal\package_manager\Validator\StageNotInActiveValidator::checkNotInActive should also be renamed to validate()

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States tedbow Ithaca, NY, USA

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

Comments & Activities

  • Issue created by @tedbow
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • Assigned to yash.rode
  • Status changed to Needs work over 2 years ago
  • @yashrode opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 2 years ago
  • Status changed to RTBC over 2 years ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I think this is what @tedbow wanted 👍

    @tedbow: what do you think about just naming all of these methods validate()? The specifics are already captured by the class name IMHO…

  • 🇺🇸United States tedbow Ithaca, NY, USA

    @tedbow: what do you think about just naming all of these methods validate()? The specifics are already captured by the class name IMHO…

    I can see just having the same for the method. but if we are going to do that than maybe validateStagePreOperation is actually correct because all the event that use these methods extend `PreOperationStageEvent` or maybe just validatePreOperation

    But maybe that is redundant we can only validate in `PreOperationStageEvent` post events don't have addError or addWarning.

    So yes lets go with validate

    Updated summary

  • Status changed to Needs work over 2 years ago
  • 🇺🇸United States tedbow Ithaca, NY, USA

    Sorry for changing the scope @yash.rode

  • 🇮🇳India yash.rode pune

    I have a doubt about the summary, correct me if I am wrong, if there is only one method and subscribed to 1 or more events then that should be renamed to validate() in other case(if the validator has multiple methods) it should be renamed to class specific name.

  • Assigned to wim leers
  • Status changed to Needs review over 2 years ago
  • 🇮🇳India yash.rode pune

    assigning to confirm my doubt in previous comment.

  • Assigned to yash.rode
  • Status changed to Needs work over 2 years ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    #9: Yep, that sounds right! But I don't see any such case? What am I missing? 🙈

    I was going to RTBC but then I found several cases that have not yet been updated:

    1. ComposerJsonExistsValidator
    2. ComposerMinimumStabilityValidator
    3. ComposerPatchesValidator
    4. DuplicateInfoFileValidator
    5. LockFileValidator
    6. StageNotInActiveValidator
    7. SupportedReleaseValidator
  • 🇮🇳India yash.rode pune

    #11 📌 Rename validator methods to `validate` unless there different methods for different events Fixed : LockFileValidator is the case I am talking about, changed other method names.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    @yash.rode the methods for that validator are:

      public static function getSubscribedEvents(): array {
        return [
          PreCreateEvent::class => 'storeHash',
          PreRequireEvent::class => 'validateStagePreOperation',
          PreApplyEvent::class => 'validateStagePreOperation',
          StatusCheckEvent::class => 'validateStagePreOperation',
          PostDestroyEvent::class => 'deleteHash',
        ];
      }
    

    There's only one validation method, the two others do other things than validating. So those should remain unchanged.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Thanks to the latest commit, this is 99% done — only LockFileValidator still needs to be updated 👍

  • Assigned to wim leers
  • Status changed to Needs review over 2 years ago
  • Issue was unassigned.
  • Status changed to RTBC over 2 years ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Perfect! 👍

  • First commit to issue fork.
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to Fixed over 2 years ago
  • 🇺🇸United States phenaproxima Massachusetts

    Merged!

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

Production build 0.71.5 2024