Ver Fonte

Type hint fixes

Jordi Boggiano há 5 anos atrás
pai
commit
d356586239
2 ficheiros alterados com 35 adições e 41 exclusões
  1. 31 37
      src/Monolog/Logger.php
  2. 4 4
      src/Monolog/Utils.php

+ 31 - 37
src/Monolog/Logger.php

@@ -90,7 +90,7 @@ class Logger implements LoggerInterface, ResettableInterface
     /**
     /**
      * This is a static variable and not a constant to serve as an extension point for custom levels
      * This is a static variable and not a constant to serve as an extension point for custom levels
      *
      *
-     * @var string[] $levels Logging levels with the levels as key
+     * @var array<int, string> $levels Logging levels with the levels as key
      */
      */
     protected static $levels = [
     protected static $levels = [
         self::DEBUG     => 'DEBUG',
         self::DEBUG     => 'DEBUG',
@@ -257,20 +257,14 @@ class Logger implements LoggerInterface, ResettableInterface
      * Control the use of microsecond resolution timestamps in the 'datetime'
      * Control the use of microsecond resolution timestamps in the 'datetime'
      * member of new records.
      * member of new records.
      *
      *
-     * On PHP7.0, generating microsecond resolution timestamps by calling
-     * microtime(true), formatting the result via sprintf() and then parsing
-     * the resulting string via \DateTime::createFromFormat() can incur
-     * a measurable runtime overhead vs simple usage of DateTime to capture
-     * a second resolution timestamp in systems which generate a large number
-     * of log events.
-     *
-     * On PHP7.1 however microseconds are always included by the engine, so
-     * this setting can be left alone unless you really want to suppress
-     * microseconds in the output.
+     * As of PHP7.1 microseconds are always included by the engine, so
+     * there is no performance penalty and Monolog 2 enabled microseconds
+     * by default. This function lets you disable them though in case you want
+     * to suppress microseconds from the output.
      *
      *
      * @param bool $micro True to use microtime() to create timestamps
      * @param bool $micro True to use microtime() to create timestamps
      */
      */
-    public function useMicrosecondTimestamps(bool $micro)
+    public function useMicrosecondTimestamps(bool $micro): void
     {
     {
         $this->microsecondTimestamps = $micro;
         $this->microsecondTimestamps = $micro;
     }
     }
@@ -278,10 +272,10 @@ class Logger implements LoggerInterface, ResettableInterface
     /**
     /**
      * Adds a log record.
      * Adds a log record.
      *
      *
-     * @param  int    $level   The logging level
-     * @param  string $message The log message
-     * @param  array  $context The log context
-     * @return bool   Whether the record has been processed
+     * @param  int     $level   The logging level
+     * @param  string  $message The log message
+     * @param  mixed[] $context The log context
+     * @return bool    Whether the record has been processed
      */
      */
     public function addRecord(int $level, string $message, array $context = []): bool
     public function addRecord(int $level, string $message, array $context = []): bool
     {
     {
@@ -378,7 +372,7 @@ class Logger implements LoggerInterface, ResettableInterface
     /**
     /**
      * Gets all supported logging levels.
      * Gets all supported logging levels.
      *
      *
-     * @return array Assoc array with human-readable level names => level codes.
+     * @return array<string, int> Assoc array with human-readable level names => level codes.
      */
      */
     public static function getLevels(): array
     public static function getLevels(): array
     {
     {
@@ -469,9 +463,9 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param mixed  $level   The log level
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param mixed   $level   The log level
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function log($level, $message, array $context = []): void
     public function log($level, $message, array $context = []): void
     {
     {
@@ -485,8 +479,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function debug($message, array $context = []): void
     public function debug($message, array $context = []): void
     {
     {
@@ -498,8 +492,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function info($message, array $context = []): void
     public function info($message, array $context = []): void
     {
     {
@@ -511,8 +505,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function notice($message, array $context = []): void
     public function notice($message, array $context = []): void
     {
     {
@@ -524,8 +518,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function warning($message, array $context = []): void
     public function warning($message, array $context = []): void
     {
     {
@@ -537,8 +531,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function error($message, array $context = []): void
     public function error($message, array $context = []): void
     {
     {
@@ -550,8 +544,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function critical($message, array $context = []): void
     public function critical($message, array $context = []): void
     {
     {
@@ -563,8 +557,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function alert($message, array $context = []): void
     public function alert($message, array $context = []): void
     {
     {
@@ -576,8 +570,8 @@ class Logger implements LoggerInterface, ResettableInterface
      *
      *
      * This method allows for compatibility with common interfaces.
      * This method allows for compatibility with common interfaces.
      *
      *
-     * @param string $message The log message
-     * @param array  $context The log context
+     * @param string  $message The log message
+     * @param mixed[] $context The log context
      */
      */
     public function emergency($message, array $context = []): void
     public function emergency($message, array $context = []): void
     {
     {
@@ -606,7 +600,7 @@ class Logger implements LoggerInterface, ResettableInterface
      * Delegates exception management to the custom exception handler,
      * Delegates exception management to the custom exception handler,
      * or throws the exception if no custom handler is set.
      * or throws the exception if no custom handler is set.
      */
      */
-    protected function handleException(Throwable $e, array $record)
+    protected function handleException(Throwable $e, array $record): void
     {
     {
         if (!$this->exceptionHandler) {
         if (!$this->exceptionHandler) {
             throw $e;
             throw $e;

+ 4 - 4
src/Monolog/Utils.php

@@ -15,14 +15,14 @@ final class Utils
 {
 {
     const DEFAULT_JSON_FLAGS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_SUBSTITUTE;
     const DEFAULT_JSON_FLAGS = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION | JSON_INVALID_UTF8_SUBSTITUTE;
 
 
-    public static function getClass($object): string
+    public static function getClass(object $object): string
     {
     {
         $class = \get_class($object);
         $class = \get_class($object);
 
 
         return 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
         return 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class;
     }
     }
 
 
-    public static function substr(string $string, int $start, ?int $length = null)
+    public static function substr(string $string, int $start, ?int $length = null): string
     {
     {
         if (extension_loaded('mbstring')) {
         if (extension_loaded('mbstring')) {
             return mb_strcut($string, $start, $length);
             return mb_strcut($string, $start, $length);
@@ -139,7 +139,7 @@ final class Utils
      * @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 static function throwEncodeError(int $code, $data)
+    private static function throwEncodeError(int $code, $data): void
     {
     {
         switch ($code) {
         switch ($code) {
             case JSON_ERROR_DEPTH:
             case JSON_ERROR_DEPTH:
@@ -176,7 +176,7 @@ final class Utils
      *
      *
      * @param mixed $data Input to check and convert if needed, passed by ref
      * @param mixed $data Input to check and convert if needed, passed by ref
      */
      */
-    private static function detectAndCleanUtf8(&$data)
+    private static function detectAndCleanUtf8(&$data): void
     {
     {
         if (is_string($data) && !preg_match('//u', $data)) {
         if (is_string($data) && !preg_match('//u', $data)) {
             $data = preg_replace_callback(
             $data = preg_replace_callback(