Jordi Boggiano пре 9 година
родитељ
комит
6f26801be6

+ 2 - 7
src/Monolog/Formatter/JsonFormatter.php

@@ -163,17 +163,12 @@ class JsonFormatter extends NormalizerFormatter
      * Normalizes given exception with or without its own stack trace based on
      * Normalizes given exception with or without its own stack trace based on
      * `includeStacktraces` property.
      * `includeStacktraces` property.
      *
      *
-     * @param Exception|Throwable $e
+     * @param Throwable $e
      *
      *
      * @return array
      * @return array
      */
      */
-    protected function normalizeException($e)
+    protected function normalizeException(\Throwable $e)
     {
     {
-        // TODO 2.0 only check for Throwable
-        if (!$e instanceof Exception && !$e instanceof \Throwable) {
-            throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
-        }
-
         $data = array(
         $data = array(
             'class' => get_class($e),
             'class' => get_class($e),
             'message' => $e->getMessage(),
             'message' => $e->getMessage(),

+ 1 - 6
src/Monolog/Formatter/LineFormatter.php

@@ -119,13 +119,8 @@ class LineFormatter extends NormalizerFormatter
         return $this->replaceNewlines($this->convertToString($value));
         return $this->replaceNewlines($this->convertToString($value));
     }
     }
 
 
-    protected function normalizeException($e)
+    protected function normalizeException(\Throwable $e)
     {
     {
-        // TODO 2.0 only check for Throwable
-        if (!$e instanceof \Exception && !$e instanceof \Throwable) {
-            throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e));
-        }
-
         $previousText = '';
         $previousText = '';
         if ($previous = $e->getPrevious()) {
         if ($previous = $e->getPrevious()) {
             do {
             do {

+ 6 - 10
src/Monolog/Formatter/NormalizerFormatter.php

@@ -28,7 +28,7 @@ class NormalizerFormatter implements FormatterInterface
     /**
     /**
      * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
      * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
      */
      */
-    public function __construct($dateFormat = null)
+    public function __construct(string $dateFormat = null)
     {
     {
         $this->dateFormat = $dateFormat;
         $this->dateFormat = $dateFormat;
         if (!function_exists('json_encode')) {
         if (!function_exists('json_encode')) {
@@ -116,12 +116,8 @@ class NormalizerFormatter implements FormatterInterface
         return '[unknown('.gettype($data).')]';
         return '[unknown('.gettype($data).')]';
     }
     }
 
 
-    protected function normalizeException($e)
+    protected function normalizeException(Throwable $e)
     {
     {
-        if (!$e instanceof Throwable) {
-            throw new \InvalidArgumentException('Throwable expected, got '.gettype($e).' / '.get_class($e));
-        }
-
         $data = array(
         $data = array(
             'class' => get_class($e),
             'class' => get_class($e),
             'message' => $e->getMessage(),
             'message' => $e->getMessage(),
@@ -155,7 +151,7 @@ class NormalizerFormatter implements FormatterInterface
      * @param  mixed             $data
      * @param  mixed             $data
      * @param  bool              $ignoreErrors
      * @param  bool              $ignoreErrors
      * @throws \RuntimeException if encoding fails and errors are not ignored
      * @throws \RuntimeException if encoding fails and errors are not ignored
-     * @return string
+     * @return string|bool
      */
      */
     protected function toJson($data, $ignoreErrors = false)
     protected function toJson($data, $ignoreErrors = false)
     {
     {
@@ -175,7 +171,7 @@ class NormalizerFormatter implements FormatterInterface
 
 
     /**
     /**
      * @param  mixed  $data
      * @param  mixed  $data
-     * @return string JSON encoded data or null on failure
+     * @return string|bool JSON encoded data or false on failure
      */
      */
     private function jsonEncode($data)
     private function jsonEncode($data)
     {
     {
@@ -195,7 +191,7 @@ class NormalizerFormatter implements FormatterInterface
      * @throws \RuntimeException if failure can't be corrected
      * @throws \RuntimeException if failure can't be corrected
      * @return string            JSON encoded data after error correction
      * @return string            JSON encoded data after error correction
      */
      */
-    private function handleJsonError($code, $data)
+    private function handleJsonError(int $code, $data): string
     {
     {
         if ($code !== JSON_ERROR_UTF8) {
         if ($code !== JSON_ERROR_UTF8) {
             $this->throwEncodeError($code, $data);
             $this->throwEncodeError($code, $data);
@@ -225,7 +221,7 @@ class NormalizerFormatter implements FormatterInterface
      * @param  mixed             $data data that was meant to be encoded
      * @param  mixed             $data data that was meant to be encoded
      * @throws \RuntimeException
      * @throws \RuntimeException
      */
      */
-    private function throwEncodeError($code, $data)
+    private function throwEncodeError(int $code, $data)
     {
     {
         switch ($code) {
         switch ($code) {
             case JSON_ERROR_DEPTH:
             case JSON_ERROR_DEPTH: