Skip to content

Commit baec16c

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Serializer] optims and cleanup do not mock the container builder in tests [PhpUnitBridge] Added support for PHPUnit 7 in Coverage Listener fix accessing request values Avoid running the remove command without any packages [Form] Add translations for Tagalog
2 parents d058c35 + 11bea1a commit baec16c

File tree

11 files changed

+57
-75
lines changed

11 files changed

+57
-75
lines changed

Annotation/Groups.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class Groups
3434
public function __construct(array $data)
3535
{
3636
if (!isset($data['value']) || !$data['value']) {
37-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this)));
37+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', \get_class($this)));
3838
}
3939

4040
$value = (array) $data['value'];
4141
foreach ($value as $group) {
42-
if (!is_string($group)) {
43-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', get_class($this)));
42+
if (!\is_string($group)) {
43+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', \get_class($this)));
4444
}
4545
}
4646

Encoder/XmlEncoder.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,17 @@ private function parseXml(\DOMNode $node, array $context = array())
245245

246246
$value = $this->parseXmlValue($node, $context);
247247

248-
if (!count($data)) {
248+
if (!\count($data)) {
249249
return $value;
250250
}
251251

252-
if (!is_array($value)) {
252+
if (!\is_array($value)) {
253253
$data['#'] = $value;
254254

255255
return $data;
256256
}
257257

258-
if (1 === count($value) && key($value)) {
258+
if (1 === \count($value) && key($value)) {
259259
$data[key($value)] = current($value);
260260

261261
return $data;
@@ -310,7 +310,7 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
310310
return $node->nodeValue;
311311
}
312312

313-
if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
313+
if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
314314
return $node->firstChild->nodeValue;
315315
}
316316

@@ -335,7 +335,7 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
335335
}
336336

337337
foreach ($value as $key => $val) {
338-
if (is_array($val) && 1 === count($val)) {
338+
if (\is_array($val) && 1 === \count($val)) {
339339
$value[$key] = current($val);
340340
}
341341
}
@@ -355,7 +355,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
355355
{
356356
$append = true;
357357

358-
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
358+
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
359359
foreach ($data as $key => $data) {
360360
//Ah this is the magic @ attribute types.
361361
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
@@ -365,7 +365,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
365365
$parentNode->setAttribute($attributeName, $data);
366366
} elseif ('#' === $key) {
367367
$append = $this->selectNodeType($parentNode, $data);
368-
} elseif (is_array($data) && false === is_numeric($key)) {
368+
} elseif (\is_array($data) && false === is_numeric($key)) {
369369
// Is this array fully numeric keys?
370370
if (ctype_digit(implode('', array_keys($data)))) {
371371
/*
@@ -389,7 +389,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
389389
return $append;
390390
}
391391

392-
if (is_object($data)) {
392+
if (\is_object($data)) {
393393
$data = $this->serializer->normalize($data, $this->format, $this->context);
394394
if (null !== $data && !is_scalar($data)) {
395395
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
@@ -448,22 +448,22 @@ private function needsCdataWrapping(string $val): bool
448448
*/
449449
private function selectNodeType(\DOMNode $node, $val): bool
450450
{
451-
if (is_array($val)) {
451+
if (\is_array($val)) {
452452
return $this->buildXml($node, $val);
453453
} elseif ($val instanceof \SimpleXMLElement) {
454454
$child = $this->dom->importNode(dom_import_simplexml($val), true);
455455
$node->appendChild($child);
456456
} elseif ($val instanceof \Traversable) {
457457
$this->buildXml($node, $val);
458-
} elseif (is_object($val)) {
458+
} elseif (\is_object($val)) {
459459
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
460460
} elseif (is_numeric($val)) {
461461
return $this->appendText($node, (string) $val);
462-
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
462+
} elseif (\is_string($val) && $this->needsCdataWrapping($val)) {
463463
return $this->appendCData($node, $val);
464-
} elseif (is_string($val)) {
464+
} elseif (\is_string($val)) {
465465
return $this->appendText($node, $val);
466-
} elseif (is_bool($val)) {
466+
} elseif (\is_bool($val)) {
467467
return $this->appendText($node, (int) $val);
468468
} elseif ($val instanceof \DOMNode) {
469469
$child = $this->dom->importNode($val, true);

Mapping/AttributeMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getName()
5959
*/
6060
public function addGroup($group)
6161
{
62-
if (!in_array($group, $this->groups)) {
62+
if (!\in_array($group, $this->groups)) {
6363
$this->groups[] = $group;
6464
}
6565
}

Mapping/Loader/LoaderChain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(array $loaders)
4040
{
4141
foreach ($loaders as $loader) {
4242
if (!$loader instanceof LoaderInterface) {
43-
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
43+
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', \get_class($loader)));
4444
}
4545
}
4646

Mapping/Loader/YamlFileLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class YamlFileLoader extends FileLoader
3030
*
3131
* @var array
3232
*/
33-
private $classes = null;
33+
private $classes;
3434

3535
/**
3636
* {@inheritdoc}
@@ -51,7 +51,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
5151

5252
$yaml = $this->classes[$classMetadata->getName()];
5353

54-
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
54+
if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) {
5555
$attributesMetadata = $classMetadata->getAttributesMetadata();
5656

5757
foreach ($yaml['attributes'] as $attribute => $data) {
@@ -63,12 +63,12 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
6363
}
6464

6565
if (isset($data['groups'])) {
66-
if (!is_array($data['groups'])) {
66+
if (!\is_array($data['groups'])) {
6767
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
6868
}
6969

7070
foreach ($data['groups'] as $group) {
71-
if (!is_string($group)) {
71+
if (!\is_string($group)) {
7272
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
7373
}
7474

@@ -119,7 +119,7 @@ private function getClassesFromYaml()
119119
return array();
120120
}
121121

122-
if (!is_array($classes)) {
122+
if (!\is_array($classes)) {
123123
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
124124
}
125125

NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(array $attributes = null, bool $lowerCamelCase = tru
3636
*/
3737
public function normalize($propertyName)
3838
{
39-
if (null === $this->attributes || in_array($propertyName, $this->attributes)) {
39+
if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
4040
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
4141
}
4242

@@ -56,7 +56,7 @@ public function denormalize($propertyName)
5656
$camelCasedName = lcfirst($camelCasedName);
5757
}
5858

59-
if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) {
59+
if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) {
6060
return $camelCasedName;
6161
}
6262

Normalizer/AbstractNormalizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function setCircularReferenceHandler(callable $circularReferenceHandler)
121121
public function setCallbacks(array $callbacks)
122122
{
123123
foreach ($callbacks as $attribute => $callback) {
124-
if (!is_callable($callback)) {
124+
if (!\is_callable($callback)) {
125125
throw new InvalidArgumentException(sprintf(
126126
'The given callback for attribute "%s" is not callable.',
127127
$attribute
@@ -189,10 +189,10 @@ protected function isCircularReference($object, &$context)
189189
protected function handleCircularReference($object)
190190
{
191191
if ($this->circularReferenceHandler) {
192-
return call_user_func($this->circularReferenceHandler, $object);
192+
return \call_user_func($this->circularReferenceHandler, $object);
193193
}
194194

195-
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', get_class($object), $this->circularReferenceLimit));
195+
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', \get_class($object), $this->circularReferenceLimit));
196196
}
197197

198198
/**
@@ -211,7 +211,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
211211
}
212212

213213
$groups = false;
214-
if (isset($context[static::GROUPS]) && is_array($context[static::GROUPS])) {
214+
if (isset($context[static::GROUPS]) && \is_array($context[static::GROUPS])) {
215215
$groups = $context[static::GROUPS];
216216
} elseif (!isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) || $context[static::ALLOW_EXTRA_ATTRIBUTES]) {
217217
return false;
@@ -222,7 +222,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
222222
$name = $attributeMetadata->getName();
223223

224224
if (
225-
(false === $groups || count(array_intersect($attributeMetadata->getGroups(), $groups))) &&
225+
(false === $groups || array_intersect($attributeMetadata->getGroups(), $groups)) &&
226226
$this->isAllowedAttribute($classOrObject, $name, null, $context)
227227
) {
228228
$allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;
@@ -326,11 +326,11 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
326326
$paramName = $constructorParameter->name;
327327
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName;
328328

329-
$allowed = false === $allowedAttributes || in_array($paramName, $allowedAttributes);
329+
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
330330
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
331331
if ($constructorParameter->isVariadic()) {
332332
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
333-
if (!is_array($data[$paramName])) {
333+
if (!\is_array($data[$paramName])) {
334334
throw new RuntimeException(sprintf('Cannot create an instance of %s from serialized data because the variadic parameter %s can only accept an array.', $class, $constructorParameter->name));
335335
}
336336

Normalizer/GetSetMethodNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function supports(string $class): bool
7474
*/
7575
private function isGetMethod(\ReflectionMethod $method): bool
7676
{
77-
$methodLength = strlen($method->name);
77+
$methodLength = \strlen($method->name);
7878

7979
return
8080
!$method->isStatic() &&
@@ -119,17 +119,17 @@ protected function getAttributeValue($object, $attribute, $format = null, array
119119
$ucfirsted = ucfirst($attribute);
120120

121121
$getter = 'get'.$ucfirsted;
122-
if (is_callable(array($object, $getter))) {
122+
if (\is_callable(array($object, $getter))) {
123123
return $object->$getter();
124124
}
125125

126126
$isser = 'is'.$ucfirsted;
127-
if (is_callable(array($object, $isser))) {
127+
if (\is_callable(array($object, $isser))) {
128128
return $object->$isser();
129129
}
130130

131131
$haser = 'has'.$ucfirsted;
132-
if (is_callable(array($object, $haser))) {
132+
if (\is_callable(array($object, $haser))) {
133133
return $object->$haser();
134134
}
135135
}
@@ -140,10 +140,10 @@ protected function getAttributeValue($object, $attribute, $format = null, array
140140
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
141141
{
142142
$setter = 'set'.ucfirst($attribute);
143-
$key = get_class($object).':'.$setter;
143+
$key = \get_class($object).':'.$setter;
144144

145145
if (!isset(self::$setterAccessibleCache[$key])) {
146-
self::$setterAccessibleCache[$key] = is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
146+
self::$setterAccessibleCache[$key] = \is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
147147
}
148148

149149
if (self::$setterAccessibleCache[$key]) {

Normalizer/ObjectNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
3030

3131
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null)
3232
{
33-
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccess')) {
33+
if (!\class_exists(PropertyAccess::class)) {
3434
throw new RuntimeException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.');
3535
}
3636

Serializer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function normalize($data, $format = null, array $context = array())
137137
return $data;
138138
}
139139

140-
if (is_array($data) || $data instanceof \Traversable) {
140+
if (\is_array($data) || $data instanceof \Traversable) {
141141
$normalized = array();
142142
foreach ($data as $key => $val) {
143143
$normalized[$key] = $this->normalize($val, $format, $context);
@@ -146,12 +146,12 @@ public function normalize($data, $format = null, array $context = array())
146146
return $normalized;
147147
}
148148

149-
if (is_object($data)) {
149+
if (\is_object($data)) {
150150
if (!$this->normalizers) {
151151
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
152152
}
153153

154-
throw new NotNormalizableValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($data)));
154+
throw new NotNormalizableValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', \get_class($data)));
155155
}
156156

157157
throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));

Tests/DependencyInjection/SerializerPassTest.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,30 @@
2323
*/
2424
class SerializerPassTest extends TestCase
2525
{
26+
/**
27+
* @expectedException \RuntimeException
28+
* @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
29+
*/
2630
public function testThrowExceptionWhenNoNormalizers()
2731
{
28-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds'))->getMock();
29-
30-
$container->expects($this->once())
31-
->method('hasDefinition')
32-
->with('serializer')
33-
->will($this->returnValue(true));
34-
35-
$container->expects($this->once())
36-
->method('findTaggedServiceIds')
37-
->with('serializer.normalizer')
38-
->will($this->returnValue(array()));
39-
40-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class);
32+
$container = new ContainerBuilder();
33+
$container->register('serializer');
4134

4235
$serializerPass = new SerializerPass();
4336
$serializerPass->process($container);
4437
}
4538

39+
/**
40+
* @expectedException \RuntimeException
41+
* @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
42+
*/
4643
public function testThrowExceptionWhenNoEncoders()
4744
{
48-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
49-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
50-
51-
$container->expects($this->once())
52-
->method('hasDefinition')
53-
->with('serializer')
54-
->will($this->returnValue(true));
55-
56-
$container->expects($this->any())
57-
->method('findTaggedServiceIds')
58-
->will($this->onConsecutiveCalls(
59-
array('n' => array('serializer.normalizer')),
60-
array()
61-
));
62-
63-
$container->expects($this->any())
64-
->method('getDefinition')
65-
->will($this->returnValue($definition));
66-
67-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\RuntimeException::class);
45+
$container = new ContainerBuilder();
46+
$container->register('serializer')
47+
->addArgument(array())
48+
->addArgument(array());
49+
$container->register('normalizer')->addTag('serializer.normalizer');
6850

6951
$serializerPass = new SerializerPass();
7052
$serializerPass->process($container);

0 commit comments

Comments
 (0)