Skip to content

Commit edcf3a6

Browse files
Merge branch '4.0'
* 4.0: [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 da19f1c + baec16c commit edcf3a6

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
@@ -32,7 +32,7 @@ class YamlFileLoader extends FileLoader
3232
*
3333
* @var array
3434
*/
35-
private $classes = null;
35+
private $classes;
3636

3737
/**
3838
* {@inheritdoc}
@@ -53,7 +53,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
5353

5454
$yaml = $this->classes[$classMetadata->getName()];
5555

56-
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
56+
if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) {
5757
$attributesMetadata = $classMetadata->getAttributesMetadata();
5858

5959
foreach ($yaml['attributes'] as $attribute => $data) {
@@ -65,12 +65,12 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
6565
}
6666

6767
if (isset($data['groups'])) {
68-
if (!is_array($data['groups'])) {
68+
if (!\is_array($data['groups'])) {
6969
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()));
7070
}
7171

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

@@ -136,7 +136,7 @@ private function getClassesFromYaml()
136136
return array();
137137
}
138138

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

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
@@ -123,7 +123,7 @@ public function setCircularReferenceHandler(callable $circularReferenceHandler)
123123
public function setCallbacks(array $callbacks)
124124
{
125125
foreach ($callbacks as $attribute => $callback) {
126-
if (!is_callable($callback)) {
126+
if (!\is_callable($callback)) {
127127
throw new InvalidArgumentException(sprintf(
128128
'The given callback for attribute "%s" is not callable.',
129129
$attribute
@@ -191,10 +191,10 @@ protected function isCircularReference($object, &$context)
191191
protected function handleCircularReference($object)
192192
{
193193
if ($this->circularReferenceHandler) {
194-
return call_user_func($this->circularReferenceHandler, $object);
194+
return \call_user_func($this->circularReferenceHandler, $object);
195195
}
196196

197-
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));
197+
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));
198198
}
199199

200200
/**
@@ -213,7 +213,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
213213
}
214214

215215
$groups = false;
216-
if (isset($context[static::GROUPS]) && is_array($context[static::GROUPS])) {
216+
if (isset($context[static::GROUPS]) && \is_array($context[static::GROUPS])) {
217217
$groups = $context[static::GROUPS];
218218
} elseif (!isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) || $context[static::ALLOW_EXTRA_ATTRIBUTES]) {
219219
return false;
@@ -224,7 +224,7 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
224224
$name = $attributeMetadata->getName();
225225

226226
if (
227-
(false === $groups || count(array_intersect($attributeMetadata->getGroups(), $groups))) &&
227+
(false === $groups || array_intersect($attributeMetadata->getGroups(), $groups)) &&
228228
$this->isAllowedAttribute($classOrObject, $name, null, $context)
229229
) {
230230
$allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;
@@ -329,11 +329,11 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
329329
$paramName = $constructorParameter->name;
330330
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName;
331331

332-
$allowed = false === $allowedAttributes || in_array($paramName, $allowedAttributes);
332+
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
333333
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
334334
if ($constructorParameter->isVariadic()) {
335335
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
336-
if (!is_array($data[$paramName])) {
336+
if (!\is_array($data[$paramName])) {
337337
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));
338338
}
339339

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
@@ -31,7 +31,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
3131

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

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)