From 01a9baf8ac9a9e23328c6c0f8dc09d9a4183160e Mon Sep 17 00:00:00 2001
From: phenaproxima <phenaproxima@205645.no-reply.drupal.org>
Date: Mon, 6 Dec 2021 18:36:08 +0000
Subject: [PATCH] Issue #3252533 by phenaproxima, tedbow: Remove the ability
 for post-operation stage events to flag warnings

---
 .../src/Event/ErrorEventInterface.php         | 22 -------------------
 package_manager/src/Event/PostApplyEvent.php  |  2 +-
 package_manager/src/Event/PostCreateEvent.php |  2 +-
 .../src/Event/PostDestroyEvent.php            |  2 +-
 .../src/Event/PostOperationStageEvent.php     | 20 -----------------
 .../src/Event/PostRequireEvent.php            |  2 +-
 .../src/Event/PreOperationStageEvent.php      |  2 +-
 .../src/Event/WarningEventInterface.php       | 22 -------------------
 .../PostOperationStageValidatorInterface.php  | 21 ------------------
 .../tests/src/Kernel/StageEventsTest.php      | 14 +++---------
 src/Event/ReadinessCheckEvent.php             |  3 +--
 11 files changed, 9 insertions(+), 103 deletions(-)
 delete mode 100644 package_manager/src/Event/ErrorEventInterface.php
 delete mode 100644 package_manager/src/Event/PostOperationStageEvent.php
 delete mode 100644 package_manager/src/Event/WarningEventInterface.php
 delete mode 100644 package_manager/src/EventSubscriber/PostOperationStageValidatorInterface.php

diff --git a/package_manager/src/Event/ErrorEventInterface.php b/package_manager/src/Event/ErrorEventInterface.php
deleted file mode 100644
index 493c8f50c3..0000000000
--- a/package_manager/src/Event/ErrorEventInterface.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-namespace Drupal\package_manager\Event;
-
-use Drupal\Core\StringTranslation\TranslatableMarkup;
-
-/**
- * Defines an interface for events which can collect validation errors.
- */
-interface ErrorEventInterface {
-
-  /**
-   * Adds a validation error.
-   *
-   * @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $messages
-   *   The error messages.
-   * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
-   *   (optional) The summary.
-   */
-  public function addError(array $messages, TranslatableMarkup $summary = NULL);
-
-}
diff --git a/package_manager/src/Event/PostApplyEvent.php b/package_manager/src/Event/PostApplyEvent.php
index 7cd7291582..d2a9693cf9 100644
--- a/package_manager/src/Event/PostApplyEvent.php
+++ b/package_manager/src/Event/PostApplyEvent.php
@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
 /**
  * Event fired after staged changes are synced to the active directory.
  */
-class PostApplyEvent extends PostOperationStageEvent {
+class PostApplyEvent extends StageEvent {
 }
diff --git a/package_manager/src/Event/PostCreateEvent.php b/package_manager/src/Event/PostCreateEvent.php
index a0833522ff..104bc78ad6 100644
--- a/package_manager/src/Event/PostCreateEvent.php
+++ b/package_manager/src/Event/PostCreateEvent.php
@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
 /**
  * Event fired after a staging area has been created.
  */
-class PostCreateEvent extends PostOperationStageEvent {
+class PostCreateEvent extends StageEvent {
 }
diff --git a/package_manager/src/Event/PostDestroyEvent.php b/package_manager/src/Event/PostDestroyEvent.php
index 7402ae9a8d..3388a988e1 100644
--- a/package_manager/src/Event/PostDestroyEvent.php
+++ b/package_manager/src/Event/PostDestroyEvent.php
@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
 /**
  * Event fired after the staging area is destroyed.
  */
-class PostDestroyEvent extends PostOperationStageEvent {
+class PostDestroyEvent extends StageEvent {
 }
diff --git a/package_manager/src/Event/PostOperationStageEvent.php b/package_manager/src/Event/PostOperationStageEvent.php
deleted file mode 100644
index 6751d87a13..0000000000
--- a/package_manager/src/Event/PostOperationStageEvent.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-namespace Drupal\package_manager\Event;
-
-use Drupal\Core\StringTranslation\TranslatableMarkup;
-use Drupal\package_manager\ValidationResult;
-
-/**
- * Base class for events dispatched after a stage life cycle operation.
- */
-abstract class PostOperationStageEvent extends StageEvent implements WarningEventInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function addWarning(array $messages, ?TranslatableMarkup $summary = NULL) {
-    $this->results[] = ValidationResult::createWarning($messages, $summary);
-  }
-
-}
diff --git a/package_manager/src/Event/PostRequireEvent.php b/package_manager/src/Event/PostRequireEvent.php
index 78e1ceda75..55b4184dd3 100644
--- a/package_manager/src/Event/PostRequireEvent.php
+++ b/package_manager/src/Event/PostRequireEvent.php
@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
 /**
  * Event fired after packages are added to the staging area.
  */
-class PostRequireEvent extends PostOperationStageEvent {
+class PostRequireEvent extends StageEvent {
 }
diff --git a/package_manager/src/Event/PreOperationStageEvent.php b/package_manager/src/Event/PreOperationStageEvent.php
index 3bb91df605..ee826f3ac3 100644
--- a/package_manager/src/Event/PreOperationStageEvent.php
+++ b/package_manager/src/Event/PreOperationStageEvent.php
@@ -8,7 +8,7 @@ use Drupal\package_manager\ValidationResult;
 /**
  * Base class for events dispatched before a stage life cycle operation.
  */
-abstract class PreOperationStageEvent extends StageEvent implements ErrorEventInterface {
+abstract class PreOperationStageEvent extends StageEvent {
 
   /**
    * {@inheritdoc}
diff --git a/package_manager/src/Event/WarningEventInterface.php b/package_manager/src/Event/WarningEventInterface.php
deleted file mode 100644
index 74f087a1b6..0000000000
--- a/package_manager/src/Event/WarningEventInterface.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-namespace Drupal\package_manager\Event;
-
-use Drupal\Core\StringTranslation\TranslatableMarkup;
-
-/**
- * Defines an interface for events which can collect validation warnings.
- */
-interface WarningEventInterface {
-
-  /**
-   * Adds a warning.
-   *
-   * @param array $messages
-   *   The warning messages.
-   * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
-   *   (optional) The summary.
-   */
-  public function addWarning(array $messages, TranslatableMarkup $summary = NULL);
-
-}
diff --git a/package_manager/src/EventSubscriber/PostOperationStageValidatorInterface.php b/package_manager/src/EventSubscriber/PostOperationStageValidatorInterface.php
deleted file mode 100644
index 5613002845..0000000000
--- a/package_manager/src/EventSubscriber/PostOperationStageValidatorInterface.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace Drupal\package_manager\EventSubscriber;
-
-use Drupal\package_manager\Event\PostOperationStageEvent;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-/**
- * Defines an interface for classes that validate a stage after an operation.
- */
-interface PostOperationStageValidatorInterface extends EventSubscriberInterface {
-
-  /**
-   * Validates a stage after an operation.
-   *
-   * @param \Drupal\package_manager\Event\PostOperationStageEvent $event
-   *   The stage event.
-   */
-  public function validateStagePostOperation(PostOperationStageEvent $event): void;
-
-}
diff --git a/package_manager/tests/src/Kernel/StageEventsTest.php b/package_manager/tests/src/Kernel/StageEventsTest.php
index c5f92892fe..eb5f46c1b4 100644
--- a/package_manager/tests/src/Kernel/StageEventsTest.php
+++ b/package_manager/tests/src/Kernel/StageEventsTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\package_manager\Kernel;
 
-use Drupal\package_manager\Event\ErrorEventInterface;
 use Drupal\package_manager\Event\PostApplyEvent;
 use Drupal\package_manager\Event\PostCreateEvent;
 use Drupal\package_manager\Event\PostDestroyEvent;
@@ -10,9 +9,9 @@ use Drupal\package_manager\Event\PostRequireEvent;
 use Drupal\package_manager\Event\PreApplyEvent;
 use Drupal\package_manager\Event\PreCreateEvent;
 use Drupal\package_manager\Event\PreDestroyEvent;
+use Drupal\package_manager\Event\PreOperationStageEvent;
 use Drupal\package_manager\Event\PreRequireEvent;
 use Drupal\package_manager\Event\StageEvent;
-use Drupal\package_manager\Event\WarningEventInterface;
 use Drupal\package_manager\Exception\StageValidationException;
 use Drupal\package_manager\Stage;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -76,7 +75,7 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
   /**
    * Handles a staging area life cycle event.
    *
-   * @param \Drupal\package_manager\Event\PreOperationStageEvent|\Drupal\package_manager\Event\PostOperationStageEvent $event
+   * @param \Drupal\package_manager\Event\StageEvent $event
    *   The event object.
    */
   public function handleEvent(StageEvent $event): void {
@@ -118,13 +117,9 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
   public function providerValidationResults(): array {
     return [
       [PreCreateEvent::class],
-      [PostCreateEvent::class],
       [PreRequireEvent::class],
-      [PostRequireEvent::class],
       [PreApplyEvent::class],
-      [PostApplyEvent::class],
       [PreDestroyEvent::class],
-      [PostDestroyEvent::class],
     ];
   }
 
@@ -141,12 +136,9 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
     // class under test.
     $handler = function (StageEvent $event) use ($event_class): void {
       if (get_class($event) === $event_class) {
-        if ($event instanceof ErrorEventInterface) {
+        if ($event instanceof PreOperationStageEvent) {
           $event->addError([['Burn, baby, burn']]);
         }
-        elseif ($event instanceof WarningEventInterface) {
-          $event->addWarning(['Be careful about fires.']);
-        }
       }
     };
     $this->container->get('event_dispatcher')
diff --git a/src/Event/ReadinessCheckEvent.php b/src/Event/ReadinessCheckEvent.php
index 50524211f7..c226ecd35d 100644
--- a/src/Event/ReadinessCheckEvent.php
+++ b/src/Event/ReadinessCheckEvent.php
@@ -5,7 +5,6 @@ namespace Drupal\automatic_updates\Event;
 use Drupal\automatic_updates\Updater;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
 use Drupal\package_manager\Event\PreOperationStageEvent;
-use Drupal\package_manager\Event\WarningEventInterface;
 use Drupal\package_manager\ValidationResult;
 
 /**
@@ -20,7 +19,7 @@ use Drupal\package_manager\ValidationResult;
  *
  * @see \Drupal\automatic_updates\Validation\ReadinessValidationManager
  */
-class ReadinessCheckEvent extends PreOperationStageEvent implements WarningEventInterface {
+class ReadinessCheckEvent extends PreOperationStageEvent {
 
   /**
    * The desired package versions to update to, keyed by package name.
-- 
GitLab