Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Enable "native_constant_invocation" CS rule
  Make AbstractPhpFileCacheWarmer public
  • Loading branch information
nicolas-grekas committed Sep 2, 2020
2 parents bcda9e5 + c4bc95b commit acffef3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Encoder/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function decode(string $data, string $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 @@ -46,11 +46,11 @@ public function encode($data, string $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
18 changes: 9 additions & 9 deletions Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa

private $defaultContext = [
self::AS_COLLECTION => false,
self::DECODER_IGNORED_NODE_TYPES => [XML_PI_NODE, XML_COMMENT_NODE],
self::DECODER_IGNORED_NODE_TYPES => [\XML_PI_NODE, \XML_COMMENT_NODE],
self::ENCODER_IGNORED_NODE_TYPES => [],
self::LOAD_OPTIONS => LIBXML_NONET | LIBXML_NOBLANKS,
self::LOAD_OPTIONS => \LIBXML_NONET | \LIBXML_NOBLANKS,
self::REMOVE_EMPTY_TAGS => false,
self::ROOT_NODE_NAME => 'response',
self::TYPE_CAST_ATTRIBUTES => true,
Expand All @@ -83,7 +83,7 @@ public function __construct(array $defaultContext = [])
public function encode($data, string $format, array $context = [])
{
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
$ignorePiNode = \in_array(XML_PI_NODE, $encoderIgnoredNodeTypes, true);
$ignorePiNode = \in_array(\XML_PI_NODE, $encoderIgnoredNodeTypes, true);
if ($data instanceof \DOMDocument) {
return $data->saveXML($ignorePiNode ? $data->documentElement : null);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public function decode(string $data, string $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 @@ -124,7 +124,7 @@ public function decode(string $data, string $format, array $context = [])
$dom->loadXML($data, $context[self::LOAD_OPTIONS] ?? $this->defaultContext[self::LOAD_OPTIONS]);

libxml_use_internal_errors($internalErrors);
if (LIBXML_VERSION < 20900) {
if (\LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}

Expand All @@ -137,7 +137,7 @@ public function decode(string $data, string $format, array $context = [])
$rootNode = null;
$decoderIgnoredNodeTypes = $context[self::DECODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::DECODER_IGNORED_NODE_TYPES];
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 && !\in_array($child->nodeType, $decoderIgnoredNodeTypes, true)) {
Expand Down Expand Up @@ -307,7 +307,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = []): array
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 @@ -330,7 +330,7 @@ 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;
}

Expand Down Expand Up @@ -384,7 +384,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
} elseif ('#' === $key) {
$append = $this->selectNodeType($parentNode, $data);
} elseif ('#comment' === $key) {
if (!\in_array(XML_COMMENT_NODE, $encoderIgnoredNodeTypes, true)) {
if (!\in_array(\XML_COMMENT_NODE, $encoderIgnoredNodeTypes, true)) {
$append = $this->appendComment($parentNode, $data);
}
} elseif (\is_array($data) && false === is_numeric($key)) {
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]],
[new \ArrayObject(), '{}', []],
[new \ArrayObject(['foo' => 'bar']), '{"foo":"bar"}', []],
];
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
6 changes: 3 additions & 3 deletions Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public function testDecodePreserveComments()

$this->encoder = new XmlEncoder([
XmlEncoder::ROOT_NODE_NAME => 'people',
XmlEncoder::DECODER_IGNORED_NODE_TYPES => [XML_PI_NODE],
XmlEncoder::DECODER_IGNORED_NODE_TYPES => [\XML_PI_NODE],
]);
$serializer = new Serializer([new CustomNormalizer()], ['xml' => new XmlEncoder()]);
$this->encoder->setSerializer($serializer);
Expand Down Expand Up @@ -813,7 +813,7 @@ public function testEncodeWithoutPi()
{
$encoder = new XmlEncoder([
XmlEncoder::ROOT_NODE_NAME => 'response',
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [XML_PI_NODE],
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [\XML_PI_NODE],
]);

$expected = '<response/>';
Expand All @@ -825,7 +825,7 @@ public function testEncodeWithoutComment()
{
$encoder = new XmlEncoder([
XmlEncoder::ROOT_NODE_NAME => 'response',
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [XML_COMMENT_NODE],
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [\XML_COMMENT_NODE],
]);

$expected = <<<'XML'
Expand Down

0 comments on commit acffef3

Please sign in to comment.