]> BookStack Code Mirror - bookstack/commitdiff
Exceptions: Added some types, simplified some classes
authorDan Brown <redacted>
Thu, 15 Jun 2023 16:07:40 +0000 (17:07 +0100)
committerDan Brown <redacted>
Thu, 15 Jun 2023 16:07:40 +0000 (17:07 +0100)
During review of #4291

app/Exceptions/NotifyException.php
app/Exceptions/PrettyException.php

index 67ef27a75a5f9167eb25b9f13a06545446911aff..b62b8fde64673a767b28996e79ae97b6e4ebd4c7 100644 (file)
@@ -9,13 +9,8 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 class NotifyException extends Exception implements Responsable, HttpExceptionInterface
 {
     public $message;
-    public $redirectLocation;
-    protected $status;
-
-    /**
-     * @var array<mixed>
-     */
-    protected array $headers = [];
+    public string $redirectLocation;
+    protected int $status;
 
     public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
     {
@@ -23,18 +18,11 @@ class NotifyException extends Exception implements Responsable, HttpExceptionInt
         $this->redirectLocation = $redirectLocation;
         $this->status = $status;
 
-        if ($status >= 300 && $status < 400) {
-            // add redirect header only when a matching HTTP status is given
-            $this->headers = ['location' => $redirectLocation];
-        }
-
         parent::__construct();
     }
 
     /**
      * Get the desired HTTP status code for this exception.
-     *
-     * {@inheritdoc}
      */
     public function getStatusCode(): int
     {
@@ -43,20 +31,10 @@ class NotifyException extends Exception implements Responsable, HttpExceptionInt
 
     /**
      * Get the desired HTTP headers for this exception.
-     *
-     * {@inheritdoc}
      */
     public function getHeaders(): array
     {
-        return $this->headers;
-    }
-
-    /**
-     * @param array<mixed> $headers
-     */
-    public function setHeaders(array $headers): void
-    {
-        $this->headers = $headers;
+        return [];
     }
 
     /**
index d0aca59225a4fc09c24fdfa344dcfe8c2569057f..606085231f77411e467b2395437373d7e5bf04d6 100644 (file)
@@ -8,20 +8,8 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
 
 class PrettyException extends Exception implements Responsable, HttpExceptionInterface
 {
-    /**
-     * @var ?string
-     */
-    protected $subtitle = null;
-
-    /**
-     * @var ?string
-     */
-    protected $details = null;
-
-    /**
-     * @var array
-     */
-    protected $headers = [];
+    protected ?string $subtitle = null;
+    protected ?string $details = null;
 
     /**
      * Render a response for when this exception occurs.
@@ -63,19 +51,9 @@ class PrettyException extends Exception implements Responsable, HttpExceptionInt
 
     /**
      * Get the desired HTTP headers for this exception.
-     * @return array<mixed>
      */
     public function getHeaders(): array
     {
-        return $this->headers;
-    }
-
-    /**
-     * Set the desired HTTP headers for this exception.
-     * @param array<mixed> $headers
-     */
-    public function setHeaders(array $headers): void
-    {
-        $this->headers = $headers;
+        return [];
     }
 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.