1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +02:00

Type hint fixes

This commit is contained in:
Jordi Boggiano
2020-12-10 16:04:54 +01:00
parent f8c98ee2ba
commit d356586239
2 changed files with 35 additions and 41 deletions

View File

@@ -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
*
* @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 = [
self::DEBUG => 'DEBUG',
@@ -257,20 +257,14 @@ class Logger implements LoggerInterface, ResettableInterface
* Control the use of microsecond resolution timestamps in the 'datetime'
* 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
*/
public function useMicrosecondTimestamps(bool $micro)
public function useMicrosecondTimestamps(bool $micro): void
{
$this->microsecondTimestamps = $micro;
}
@@ -278,10 +272,10 @@ class Logger implements LoggerInterface, ResettableInterface
/**
* 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
{
@@ -378,7 +372,7 @@ class Logger implements LoggerInterface, ResettableInterface
/**
* 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
{
@@ -469,9 +463,9 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -485,8 +479,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -498,8 +492,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -511,8 +505,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -524,8 +518,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -537,8 +531,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -550,8 +544,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -563,8 +557,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -576,8 +570,8 @@ class Logger implements LoggerInterface, ResettableInterface
*
* 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
{
@@ -606,7 +600,7 @@ class Logger implements LoggerInterface, ResettableInterface
* Delegates exception management to the custom exception handler,
* 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) {
throw $e;

View File

@@ -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;
public static function getClass($object): string
public static function getClass(object $object): string
{
$class = \get_class($object);
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')) {
return mb_strcut($string, $start, $length);
@@ -139,7 +139,7 @@ final class Utils
* @param mixed $data data that was meant to be encoded
* @throws \RuntimeException
*/
private static function throwEncodeError(int $code, $data)
private static function throwEncodeError(int $code, $data): void
{
switch ($code) {
case JSON_ERROR_DEPTH:
@@ -176,7 +176,7 @@ final class Utils
*
* @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)) {
$data = preg_replace_callback(