Skip to content

Commit c3cfcfc

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Serializer] optims and cleanup [Form] Add translations for Tagalog
2 parents 0af616f + 464dc32 commit c3cfcfc

12 files changed

+64
-64
lines changed

Annotation/Groups.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ 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

40-
if (!is_array($data['value'])) {
41-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this)));
40+
if (!\is_array($data['value'])) {
41+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this)));
4242
}
4343

4444
foreach ($data['value'] as $group) {
45-
if (!is_string($group)) {
46-
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this)));
45+
if (!\is_string($group)) {
46+
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this)));
4747
}
4848
}
4949

Encoder/XmlEncoder.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getRootNodeName()
179179
*/
180180
final protected function appendXMLString(\DOMNode $node, $val)
181181
{
182-
if (strlen($val) > 0) {
182+
if (\strlen($val) > 0) {
183183
$frag = $this->dom->createDocumentFragment();
184184
$frag->appendXML($val);
185185
$node->appendChild($frag);
@@ -260,17 +260,17 @@ private function parseXml(\DOMNode $node)
260260

261261
$value = $this->parseXmlValue($node);
262262

263-
if (!count($data)) {
263+
if (!\count($data)) {
264264
return $value;
265265
}
266266

267-
if (!is_array($value)) {
267+
if (!\is_array($value)) {
268268
$data['#'] = $value;
269269

270270
return $data;
271271
}
272272

273-
if (1 === count($value) && key($value)) {
273+
if (1 === \count($value) && key($value)) {
274274
$data[key($value)] = current($value);
275275

276276
return $data;
@@ -326,7 +326,7 @@ private function parseXmlValue(\DOMNode $node)
326326
return $node->nodeValue;
327327
}
328328

329-
if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
329+
if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
330330
return $node->firstChild->nodeValue;
331331
}
332332

@@ -351,7 +351,7 @@ private function parseXmlValue(\DOMNode $node)
351351
}
352352

353353
foreach ($value as $key => $val) {
354-
if (is_array($val) && 1 === count($val)) {
354+
if (\is_array($val) && 1 === \count($val)) {
355355
$value[$key] = current($val);
356356
}
357357
}
@@ -374,7 +374,7 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
374374
{
375375
$append = true;
376376

377-
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
377+
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
378378
foreach ($data as $key => $data) {
379379
//Ah this is the magic @ attribute types.
380380
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
@@ -384,7 +384,7 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
384384
$parentNode->setAttribute($attributeName, $data);
385385
} elseif ('#' === $key) {
386386
$append = $this->selectNodeType($parentNode, $data);
387-
} elseif (is_array($data) && false === is_numeric($key)) {
387+
} elseif (\is_array($data) && false === is_numeric($key)) {
388388
// Is this array fully numeric keys?
389389
if (ctype_digit(implode('', array_keys($data)))) {
390390
/*
@@ -408,7 +408,7 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
408408
return $append;
409409
}
410410

411-
if (is_object($data)) {
411+
if (\is_object($data)) {
412412
$data = $this->serializer->normalize($data, $this->format, $this->context);
413413
if (null !== $data && !is_scalar($data)) {
414414
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
@@ -477,22 +477,22 @@ private function needsCdataWrapping($val)
477477
*/
478478
private function selectNodeType(\DOMNode $node, $val)
479479
{
480-
if (is_array($val)) {
480+
if (\is_array($val)) {
481481
return $this->buildXml($node, $val);
482482
} elseif ($val instanceof \SimpleXMLElement) {
483483
$child = $this->dom->importNode(dom_import_simplexml($val), true);
484484
$node->appendChild($child);
485485
} elseif ($val instanceof \Traversable) {
486486
$this->buildXml($node, $val);
487-
} elseif (is_object($val)) {
487+
} elseif (\is_object($val)) {
488488
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
489489
} elseif (is_numeric($val)) {
490490
return $this->appendText($node, (string) $val);
491-
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
491+
} elseif (\is_string($val) && $this->needsCdataWrapping($val)) {
492492
return $this->appendCData($node, $val);
493-
} elseif (is_string($val)) {
493+
} elseif (\is_string($val)) {
494494
return $this->appendText($node, $val);
495-
} elseif (is_bool($val)) {
495+
} elseif (\is_bool($val)) {
496496
return $this->appendText($node, (int) $val);
497497
} elseif ($val instanceof \DOMNode) {
498498
$child = $this->dom->importNode($val, true);

Mapping/AttributeMetadata.php

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

Mapping/Factory/ClassMetadataFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getMetadataFor($value)
4040
{
4141
$class = $this->getClass($value);
4242
if (!$class) {
43-
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($value)));
43+
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value)));
4444
}
4545

4646
if (isset($this->loadedClasses[$class])) {
@@ -96,10 +96,10 @@ public function hasMetadataFor($value)
9696
*/
9797
private function getClass($value)
9898
{
99-
if (!is_object($value) && !is_string($value)) {
99+
if (!\is_object($value) && !\is_string($value)) {
100100
return false;
101101
}
102102

103-
return ltrim(is_object($value) ? get_class($value) : $value, '\\');
103+
return ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
104104
}
105105
}

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}
@@ -53,7 +53,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
5353
}
5454

5555
// not an array
56-
if (!is_array($classes)) {
56+
if (!\is_array($classes)) {
5757
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
5858
}
5959

@@ -66,7 +66,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
6666

6767
$yaml = $this->classes[$classMetadata->getName()];
6868

69-
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
69+
if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) {
7070
$attributesMetadata = $classMetadata->getAttributesMetadata();
7171

7272
foreach ($yaml['attributes'] as $attribute => $data) {
@@ -78,12 +78,12 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
7878
}
7979

8080
if (isset($data['groups'])) {
81-
if (!is_array($data['groups'])) {
81+
if (!\is_array($data['groups'])) {
8282
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()));
8383
}
8484

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

NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function __construct(array $attributes = null, $lowerCamelCase = true)
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
$lcPropertyName = lcfirst($propertyName);
4141
$snakeCasedName = '';
4242

43-
$len = strlen($lcPropertyName);
43+
$len = \strlen($lcPropertyName);
4444
for ($i = 0; $i < $len; ++$i) {
4545
if (ctype_upper($lcPropertyName[$i])) {
4646
$snakeCasedName .= '_'.strtolower($lcPropertyName[$i]);
@@ -68,7 +68,7 @@ public function denormalize($propertyName)
6868
$camelCasedName = lcfirst($camelCasedName);
6969
}
7070

71-
if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) {
71+
if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) {
7272
return $camelCasedName;
7373
}
7474

Normalizer/AbstractNormalizer.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function setCircularReferenceLimit($circularReferenceLimit)
100100
*/
101101
public function setCircularReferenceHandler($circularReferenceHandler)
102102
{
103-
if (!is_callable($circularReferenceHandler)) {
103+
if (!\is_callable($circularReferenceHandler)) {
104104
throw new InvalidArgumentException('The given circular reference handler is not callable.');
105105
}
106106

@@ -121,7 +121,7 @@ public function setCircularReferenceHandler($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
@@ -220,10 +220,10 @@ protected function isCircularReference($object, &$context)
220220
protected function handleCircularReference($object)
221221
{
222222
if ($this->circularReferenceHandler) {
223-
return call_user_func($this->circularReferenceHandler, $object);
223+
return \call_user_func($this->circularReferenceHandler, $object);
224224
}
225225

226-
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));
226+
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));
227227
}
228228

229229
/**
@@ -253,13 +253,13 @@ protected function formatAttribute($attributeName)
253253
*/
254254
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
255255
{
256-
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !is_array($context[static::GROUPS])) {
256+
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
257257
return false;
258258
}
259259

260260
$allowedAttributes = array();
261261
foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) {
262-
if (count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS]))) {
262+
if (array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS])) {
263263
$allowedAttributes[] = $attributesAsString ? $attributeMetadata->getName() : $attributeMetadata;
264264
}
265265
}
@@ -302,7 +302,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
302302
{
303303
if (
304304
isset($context[static::OBJECT_TO_POPULATE]) &&
305-
is_object($context[static::OBJECT_TO_POPULATE]) &&
305+
\is_object($context[static::OBJECT_TO_POPULATE]) &&
306306
$context[static::OBJECT_TO_POPULATE] instanceof $class
307307
) {
308308
$object = $context[static::OBJECT_TO_POPULATE];
@@ -320,11 +320,11 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
320320
$paramName = $constructorParameter->name;
321321
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName;
322322

323-
$allowed = false === $allowedAttributes || in_array($paramName, $allowedAttributes);
324-
$ignored = in_array($paramName, $this->ignoredAttributes);
323+
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
324+
$ignored = \in_array($paramName, $this->ignoredAttributes);
325325
if (method_exists($constructorParameter, 'isVariadic') && $constructorParameter->isVariadic()) {
326326
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
327-
if (!is_array($data[$paramName])) {
327+
if (!\is_array($data[$paramName])) {
328328
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));
329329
}
330330

Normalizer/GetSetMethodNormalizer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ public function normalize($object, $format = null, array $context = array())
5858
foreach ($reflectionMethods as $method) {
5959
if ($this->isGetMethod($method)) {
6060
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
61-
if (in_array($attributeName, $this->ignoredAttributes)) {
61+
if (\in_array($attributeName, $this->ignoredAttributes)) {
6262
continue;
6363
}
6464

65-
if (false !== $allowedAttributes && !in_array($attributeName, $allowedAttributes)) {
65+
if (false !== $allowedAttributes && !\in_array($attributeName, $allowedAttributes)) {
6666
continue;
6767
}
6868

6969
$attributeValue = $method->invoke($object);
7070
if (isset($this->callbacks[$attributeName])) {
71-
$attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue);
71+
$attributeValue = \call_user_func($this->callbacks[$attributeName], $attributeValue);
7272
}
7373
if (null !== $attributeValue && !is_scalar($attributeValue)) {
7474
if (!$this->serializer instanceof NormalizerInterface) {
@@ -108,13 +108,13 @@ public function denormalize($data, $class, $format = null, array $context = arra
108108
$attribute = $this->nameConverter->denormalize($attribute);
109109
}
110110

111-
$allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes);
112-
$ignored = in_array($attribute, $this->ignoredAttributes);
111+
$allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes);
112+
$ignored = \in_array($attribute, $this->ignoredAttributes);
113113

114114
if ($allowed && !$ignored) {
115115
$setter = 'set'.ucfirst($attribute);
116116

117-
if (in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
117+
if (\in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
118118
$object->$setter($value);
119119
}
120120
}
@@ -128,7 +128,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
128128
*/
129129
public function supportsNormalization($data, $format = null)
130130
{
131-
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
131+
return \is_object($data) && !$data instanceof \Traversable && $this->supports(\get_class($data));
132132
}
133133

134134
/**
@@ -166,7 +166,7 @@ private function supports($class)
166166
*/
167167
private function isGetMethod(\ReflectionMethod $method)
168168
{
169-
$methodLength = strlen($method->name);
169+
$methodLength = \strlen($method->name);
170170

171171
return
172172
!$method->isStatic() &&

Normalizer/ObjectNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
4747
*/
4848
public function supportsNormalization($data, $format = null)
4949
{
50-
return is_object($data) && !$data instanceof \Traversable;
50+
return \is_object($data) && !$data instanceof \Traversable;
5151
}
5252

5353
/**
@@ -68,14 +68,14 @@ public function normalize($object, $format = null, array $context = array())
6868
$attributes = $this->getAttributes($object, $context);
6969

7070
foreach ($attributes as $attribute) {
71-
if (in_array($attribute, $this->ignoredAttributes)) {
71+
if (\in_array($attribute, $this->ignoredAttributes)) {
7272
continue;
7373
}
7474

7575
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
7676

7777
if (isset($this->callbacks[$attribute])) {
78-
$attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue);
78+
$attributeValue = \call_user_func($this->callbacks[$attribute], $attributeValue);
7979
}
8080

8181
if (null !== $attributeValue && !is_scalar($attributeValue)) {
@@ -123,8 +123,8 @@ public function denormalize($data, $class, $format = null, array $context = arra
123123
$attribute = $this->nameConverter->denormalize($attribute);
124124
}
125125

126-
$allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes);
127-
$ignored = in_array($attribute, $this->ignoredAttributes);
126+
$allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes);
127+
$ignored = \in_array($attribute, $this->ignoredAttributes);
128128

129129
if ($allowed && !$ignored) {
130130
try {

0 commit comments

Comments
 (0)