Skip to content

Commit

Permalink
Enable "native_constant_invocation" CS rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 2, 2020
1 parent e3e34e8 commit b7d9a52
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Encoder/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
4 changes: 2 additions & 2 deletions Encoder/JsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
16 changes: 8 additions & 8 deletions Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Mapping/Factory/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Normalizer/AbstractNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Encoder/JsonEncodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function encodeProvider()
{
return [
[[], '[]', []],
[[], '{}', ['json_encode_options' => JSON_FORCE_OBJECT]],
[[], '{}', ['json_encode_options' => \JSON_FORCE_OBJECT]],
];
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/Encoder/JsonEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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!',
Expand All @@ -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);
}

Expand Down

0 comments on commit b7d9a52

Please sign in to comment.