Browse Source

Removed unnecessary php version checks after php dependency bump to 7.0

Jeroen Thora 10 năm trước cách đây
mục cha
commit
8ceda1b62e

+ 1 - 4
src/Monolog/Formatter/HtmlFormatter.php

@@ -132,10 +132,7 @@ class HtmlFormatter extends NormalizerFormatter
         }
         }
 
 
         $data = $this->normalize($data);
         $data = $this->normalize($data);
-        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
-            return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
-        }
 
 
-        return str_replace('\\/', '/', json_encode($data));
+        return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     }
 }
 }

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

@@ -141,11 +141,7 @@ class LineFormatter extends NormalizerFormatter
             return (string) $data;
             return (string) $data;
         }
         }
 
 
-        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
-            return $this->toJson($data, true);
-        }
-
-        return str_replace('\\/', '/', @json_encode($data));
+        return $this->toJson($data, true);
     }
     }
 
 
     protected function replaceNewlines($str)
     protected function replaceNewlines($str)

+ 1 - 5
src/Monolog/Formatter/NormalizerFormatter.php

@@ -168,11 +168,7 @@ class NormalizerFormatter implements FormatterInterface
      */
      */
     private function jsonEncode($data)
     private function jsonEncode($data)
     {
     {
-        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
-            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
-        }
-
-        return json_encode($data);
+        return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     }
 
 
     /**
     /**

+ 1 - 11
tests/Monolog/Formatter/LogstashFormatterTest.php

@@ -296,10 +296,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
 
 
     public function testFormatWithLatin9Data()
     public function testFormatWithLatin9Data()
     {
     {
-        if (version_compare(PHP_VERSION, '5.5.0', '<')) {
-            // Ignore the warning that will be emitted by PHP <5.5.0
-            \PHPUnit_Framework_Error_Warning::$enabled = false;
-        }
         $formatter = new LogstashFormatter('test', 'hostname');
         $formatter = new LogstashFormatter('test', 'hostname');
         $record = array(
         $record = array(
             'level' => Logger::ERROR,
             'level' => Logger::ERROR,
@@ -322,12 +318,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(Logger::ERROR, $message['@fields']['level']);
         $this->assertEquals(Logger::ERROR, $message['@fields']['level']);
         $this->assertEquals('test', $message['@type']);
         $this->assertEquals('test', $message['@type']);
         $this->assertEquals('hostname', $message['@source']);
         $this->assertEquals('hostname', $message['@source']);
-        if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
-            $this->assertEquals('ÖWN; FBCR/OrangeEspaña; Versão/4.0; Färist', $message['@fields']['user_agent']);
-        } else {
-            // PHP <5.5 does not return false for an element encoding failure,
-            // instead it emits a warning (possibly) and nulls the value.
-            $this->assertEquals(null, $message['@fields']['user_agent']);
-        }
+        $this->assertEquals('ÖWN; FBCR/OrangeEspaña; Versão/4.0; Färist', $message['@fields']['user_agent']);
     }
     }
 }
 }

+ 3 - 24
tests/Monolog/Formatter/NormalizerFormatterTest.php

@@ -195,10 +195,6 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
      */
      */
     public function testThrowsOnInvalidEncoding()
     public function testThrowsOnInvalidEncoding()
     {
     {
-        if (version_compare(PHP_VERSION, '5.5.0', '<')) {
-            // Ignore the warning that will be emitted by PHP <5.5.0
-            \PHPUnit_Framework_Error_Warning::$enabled = false;
-        }
         $formatter = new NormalizerFormatter();
         $formatter = new NormalizerFormatter();
         $reflMethod = new \ReflectionMethod($formatter, 'toJson');
         $reflMethod = new \ReflectionMethod($formatter, 'toJson');
         $reflMethod->setAccessible(true);
         $reflMethod->setAccessible(true);
@@ -206,31 +202,18 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
         // send an invalid unicode sequence as a object that can't be cleaned
         // send an invalid unicode sequence as a object that can't be cleaned
         $record = new \stdClass;
         $record = new \stdClass;
         $record->message = "\xB1\x31";
         $record->message = "\xB1\x31";
-        $res = $reflMethod->invoke($formatter, $record);
-        if (PHP_VERSION_ID < 50500 && $res === '{"message":null}') {
-            throw new \RuntimeException('PHP 5.3/5.4 throw a warning and null the value instead of returning false entirely');
-        }
+        $reflMethod->invoke($formatter, $record);
     }
     }
 
 
     public function testConvertsInvalidEncodingAsLatin9()
     public function testConvertsInvalidEncodingAsLatin9()
     {
     {
-        if (version_compare(PHP_VERSION, '5.5.0', '<')) {
-            // Ignore the warning that will be emitted by PHP <5.5.0
-            \PHPUnit_Framework_Error_Warning::$enabled = false;
-        }
         $formatter = new NormalizerFormatter();
         $formatter = new NormalizerFormatter();
         $reflMethod = new \ReflectionMethod($formatter, 'toJson');
         $reflMethod = new \ReflectionMethod($formatter, 'toJson');
         $reflMethod->setAccessible(true);
         $reflMethod->setAccessible(true);
 
 
         $res = $reflMethod->invoke($formatter, array('message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"));
         $res = $reflMethod->invoke($formatter, array('message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"));
 
 
-        if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
-            $this->assertSame('{"message":"€ŠšŽžŒœŸ"}', $res);
-        } else {
-            // PHP <5.5 does not return false for an element encoding failure,
-            // instead it emits a warning (possibly) and nulls the value.
-            $this->assertSame('{"message":null}', $res);
-        }
+        $this->assertSame('{"message":"€ŠšŽžŒœŸ"}', $res);
     }
     }
 
 
     /**
     /**
@@ -323,11 +306,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
             $result['context']['exception']['trace'][0]
             $result['context']['exception']['trace'][0]
         );
         );
 
 
-        if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
-            $pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
-        } else {
-            $pattern = '%\\\\"foo\\\\":null%';
-        }
+        $pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
 
 
         // Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4
         // Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4
         $this->assertRegExp(
         $this->assertRegExp(

+ 1 - 5
tests/Monolog/Formatter/ScalarFormatterTest.php

@@ -37,11 +37,7 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
 
 
     public function encodeJson($data)
     public function encodeJson($data)
     {
     {
-        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
-            return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
-        }
-
-        return json_encode($data);
+        return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     }
 
 
     public function testFormat()
     public function testFormat()