From b7d9a52bb1b3ec606238feb645908ffc8b4f714f Mon Sep 17 00:00:00 2001
From: Nicolas Grekas <nicolas.grekas@gmail.com>
Date: Wed, 2 Sep 2020 18:06:40 +0200
Subject: [PATCH] Enable "native_constant_invocation" CS rule

---
 Encoder/JsonDecode.php                   |  4 ++--
 Encoder/JsonEncode.php                   |  4 ++--
 Encoder/XmlEncoder.php                   | 16 ++++++++--------
 Mapping/Factory/ClassMetadataFactory.php |  2 +-
 Normalizer/AbstractNormalizer.php        |  2 +-
 Serializer.php                           |  8 ++++----
 Tests/Encoder/JsonEncodeTest.php         |  2 +-
 Tests/Encoder/JsonEncoderTest.php        | 10 +++++-----
 8 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/Encoder/JsonDecode.php b/Encoder/JsonDecode.php
index e4f6795a6..790fbc44e 100644
--- a/Encoder/JsonDecode.php
+++ b/Encoder/JsonDecode.php
@@ -78,11 +78,11 @@ public function decode($data, $format, array $context = [])
             throw new NotEncodableValueException($e->getMessage(), 0, $e);
         }
 
-        if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
+        if (\PHP_VERSION_ID >= 70300 && (\JSON_THROW_ON_ERROR & $options)) {
             return $decodedData;
         }
 
-        if (JSON_ERROR_NONE !== json_last_error()) {
+        if (\JSON_ERROR_NONE !== json_last_error()) {
             throw new NotEncodableValueException(json_last_error_msg());
         }
 
diff --git a/Encoder/JsonEncode.php b/Encoder/JsonEncode.php
index 71f695039..955c92d8e 100644
--- a/Encoder/JsonEncode.php
+++ b/Encoder/JsonEncode.php
@@ -43,11 +43,11 @@ public function encode($data, $format, array $context = [])
             throw new NotEncodableValueException($e->getMessage(), 0, $e);
         }
 
-        if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
+        if (\PHP_VERSION_ID >= 70300 && (\JSON_THROW_ON_ERROR & $options)) {
             return $encodedJson;
         }
 
-        if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($options & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
+        if (\JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($options & \JSON_PARTIAL_OUTPUT_ON_ERROR))) {
             throw new NotEncodableValueException(json_last_error_msg());
         }
 
diff --git a/Encoder/XmlEncoder.php b/Encoder/XmlEncoder.php
index 412dbb2f3..1cf8ee126 100644
--- a/Encoder/XmlEncoder.php
+++ b/Encoder/XmlEncoder.php
@@ -44,7 +44,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
     public function __construct($rootNodeName = 'response', $loadOptions = null)
     {
         $this->rootNodeName = $rootNodeName;
-        $this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;
+        $this->loadOptions = null !== $loadOptions ? $loadOptions : \LIBXML_NONET | \LIBXML_NOBLANKS;
     }
 
     /**
@@ -83,7 +83,7 @@ public function decode($data, $format, array $context = [])
         }
 
         $internalErrors = libxml_use_internal_errors(true);
-        if (LIBXML_VERSION < 20900) {
+        if (\LIBXML_VERSION < 20900) {
             $disableEntities = libxml_disable_entity_loader(true);
         }
         libxml_clear_errors();
@@ -92,7 +92,7 @@ public function decode($data, $format, array $context = [])
         $dom->loadXML($data, $this->loadOptions);
 
         libxml_use_internal_errors($internalErrors);
-        if (LIBXML_VERSION < 20900) {
+        if (\LIBXML_VERSION < 20900) {
             libxml_disable_entity_loader($disableEntities);
         }
 
@@ -104,10 +104,10 @@ public function decode($data, $format, array $context = [])
 
         $rootNode = null;
         foreach ($dom->childNodes as $child) {
-            if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) {
+            if (\XML_DOCUMENT_TYPE_NODE === $child->nodeType) {
                 throw new NotEncodableValueException('Document types are not allowed.');
             }
-            if (!$rootNode && XML_PI_NODE !== $child->nodeType) {
+            if (!$rootNode && \XML_PI_NODE !== $child->nodeType) {
                 $rootNode = $child;
             }
         }
@@ -310,7 +310,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = [])
                 continue;
             }
 
-            if (false !== $val = filter_var($attr->nodeValue, FILTER_VALIDATE_INT)) {
+            if (false !== $val = filter_var($attr->nodeValue, \FILTER_VALIDATE_INT)) {
                 $data['@'.$attr->nodeName] = $val;
 
                 continue;
@@ -333,14 +333,14 @@ private function parseXmlValue(\DOMNode $node, array $context = [])
             return $node->nodeValue;
         }
 
-        if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, [XML_TEXT_NODE, XML_CDATA_SECTION_NODE])) {
+        if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, [\XML_TEXT_NODE, \XML_CDATA_SECTION_NODE])) {
             return $node->firstChild->nodeValue;
         }
 
         $value = [];
 
         foreach ($node->childNodes as $subnode) {
-            if (XML_PI_NODE === $subnode->nodeType) {
+            if (\XML_PI_NODE === $subnode->nodeType) {
                 continue;
             }
 
diff --git a/Mapping/Factory/ClassMetadataFactory.php b/Mapping/Factory/ClassMetadataFactory.php
index 294dfd9e3..7e01131e6 100644
--- a/Mapping/Factory/ClassMetadataFactory.php
+++ b/Mapping/Factory/ClassMetadataFactory.php
@@ -35,7 +35,7 @@ public function __construct(LoaderInterface $loader, Cache $cache = null)
         $this->cache = $cache;
 
         if (null !== $cache) {
-            @trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since Symfony 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), E_USER_DEPRECATED);
+            @trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since Symfony 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), \E_USER_DEPRECATED);
         }
     }
 
diff --git a/Normalizer/AbstractNormalizer.php b/Normalizer/AbstractNormalizer.php
index e88b5a211..ca0490d1a 100644
--- a/Normalizer/AbstractNormalizer.php
+++ b/Normalizer/AbstractNormalizer.php
@@ -307,7 +307,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
             if (__CLASS__ !== static::class) {
                 $r = new \ReflectionMethod($this, __FUNCTION__);
                 if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
-                    @trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', static::class, __FUNCTION__), E_USER_DEPRECATED);
+                    @trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since Symfony 3.2.', static::class, __FUNCTION__), \E_USER_DEPRECATED);
                 }
             }
 
diff --git a/Serializer.php b/Serializer.php
index 87b32a6ca..1d885ee9d 100644
--- a/Serializer.php
+++ b/Serializer.php
@@ -196,7 +196,7 @@ public function supportsNormalization($data, $format = null/*, array $context =
             if (__CLASS__ !== static::class) {
                 $r = new \ReflectionMethod($this, __FUNCTION__);
                 if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
-                    @trigger_error(sprintf('The "%s()" method will have a third `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED);
+                    @trigger_error(sprintf('The "%s()" method will have a third `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
                 }
             }
 
@@ -217,7 +217,7 @@ public function supportsDenormalization($data, $type, $format = null/*, array $c
             if (__CLASS__ !== static::class) {
                 $r = new \ReflectionMethod($this, __FUNCTION__);
                 if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
-                    @trigger_error(sprintf('The "%s()" method will have a fourth `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED);
+                    @trigger_error(sprintf('The "%s()" method will have a fourth `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
                 }
             }
 
@@ -295,7 +295,7 @@ public function supportsEncoding($format/*, array $context = []*/)
             if (__CLASS__ !== static::class) {
                 $r = new \ReflectionMethod($this, __FUNCTION__);
                 if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
-                    @trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED);
+                    @trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
                 }
             }
 
@@ -316,7 +316,7 @@ public function supportsDecoding($format/*, array $context = []*/)
             if (__CLASS__ !== static::class) {
                 $r = new \ReflectionMethod($this, __FUNCTION__);
                 if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
-                    @trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED);
+                    @trigger_error(sprintf('The "%s()" method will have a second `$context = []` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), \E_USER_DEPRECATED);
                 }
             }
 
diff --git a/Tests/Encoder/JsonEncodeTest.php b/Tests/Encoder/JsonEncodeTest.php
index 1a3d7c867..266acc6a6 100644
--- a/Tests/Encoder/JsonEncodeTest.php
+++ b/Tests/Encoder/JsonEncodeTest.php
@@ -45,7 +45,7 @@ public function encodeProvider()
     {
         return [
             [[], '[]', []],
-            [[], '{}', ['json_encode_options' => JSON_FORCE_OBJECT]],
+            [[], '{}', ['json_encode_options' => \JSON_FORCE_OBJECT]],
         ];
     }
 
diff --git a/Tests/Encoder/JsonEncoderTest.php b/Tests/Encoder/JsonEncoderTest.php
index 191e8dc35..30a80444a 100644
--- a/Tests/Encoder/JsonEncoderTest.php
+++ b/Tests/Encoder/JsonEncoderTest.php
@@ -48,7 +48,7 @@ public function testComplexObject()
 
     public function testOptions()
     {
-        $context = ['json_encode_options' => JSON_NUMERIC_CHECK];
+        $context = ['json_encode_options' => \JSON_NUMERIC_CHECK];
 
         $arr = [];
         $arr['foo'] = '3';
@@ -78,7 +78,7 @@ public function testEncodeNotUtf8WithoutPartialOnError()
 
     public function testEncodeNotUtf8WithPartialOnError()
     {
-        $context = ['json_encode_options' => JSON_PARTIAL_OUTPUT_ON_ERROR];
+        $context = ['json_encode_options' => \JSON_PARTIAL_OUTPUT_ON_ERROR];
 
         $arr = [
             'utf8' => 'Hello World!',
@@ -88,16 +88,16 @@ public function testEncodeNotUtf8WithPartialOnError()
         $result = $this->encoder->encode($arr, 'json', $context);
         $jsonLastError = json_last_error();
 
-        $this->assertSame(JSON_ERROR_UTF8, $jsonLastError);
+        $this->assertSame(\JSON_ERROR_UTF8, $jsonLastError);
         $this->assertEquals('{"utf8":"Hello World!","notUtf8":null}', $result);
 
-        $this->assertEquals('0', $this->serializer->serialize(NAN, 'json', $context));
+        $this->assertEquals('0', $this->serializer->serialize(\NAN, 'json', $context));
     }
 
     public function testDecodeFalseString()
     {
         $result = $this->encoder->decode('false', 'json');
-        $this->assertSame(JSON_ERROR_NONE, json_last_error());
+        $this->assertSame(\JSON_ERROR_NONE, json_last_error());
         $this->assertFalse($result);
     }