mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 09:06:10 +02:00
Move to strict mode and fix tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
@@ -30,7 +30,7 @@ class NormalizerFormatter implements FormatterInterface
|
||||
*/
|
||||
public function __construct(string $dateFormat = null)
|
||||
{
|
||||
$this->dateFormat = $dateFormat;
|
||||
$this->dateFormat = null === $dateFormat ? static::SIMPLE_DATE : $dateFormat;
|
||||
if (!function_exists('json_encode')) {
|
||||
throw new \RuntimeException('PHP\'s json extension is required to use Monolog\'s NormalizerFormatter');
|
||||
}
|
||||
@@ -87,11 +87,7 @@ class NormalizerFormatter implements FormatterInterface
|
||||
}
|
||||
|
||||
if ($data instanceof \DateTimeInterface) {
|
||||
if ($data instanceof DateTimeImmutable) {
|
||||
return (string) $data;
|
||||
}
|
||||
|
||||
return $data->format($this->dateFormat ?: static::SIMPLE_DATE);
|
||||
return $this->formatDate($data);
|
||||
}
|
||||
|
||||
if (is_object($data)) {
|
||||
@@ -271,7 +267,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
if (is_string($data) && !preg_match('//u', $data)) {
|
||||
$data = preg_replace_callback(
|
||||
'/[\x80-\xFF]+/',
|
||||
function ($m) { return utf8_encode($m[0]); },
|
||||
function ($m) {
|
||||
return utf8_encode($m[0]);
|
||||
},
|
||||
$data
|
||||
);
|
||||
$data = str_replace(
|
||||
@@ -281,4 +279,13 @@ class NormalizerFormatter implements FormatterInterface
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatDate(\DateTimeInterface $date)
|
||||
{
|
||||
if ($date instanceof DateTimeImmutable) {
|
||||
return (string) $date;
|
||||
}
|
||||
|
||||
return $date->format($this->dateFormat);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user