Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / validator / Validator / RecursiveContextualValidator.php
index d1166ad913d657450f61bc42766c80d14bd38792..f50f767bd9685e7891908e2c342bca1b313d33ac 100644 (file)
@@ -23,11 +23,11 @@ use Symfony\Component\Validator\Exception\UnsupportedMetadataException;
 use Symfony\Component\Validator\Exception\ValidatorException;
 use Symfony\Component\Validator\Mapping\CascadingStrategy;
 use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
+use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
 use Symfony\Component\Validator\Mapping\GenericMetadata;
 use Symfony\Component\Validator\Mapping\MetadataInterface;
 use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
 use Symfony\Component\Validator\Mapping\TraversalStrategy;
-use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
 use Symfony\Component\Validator\ObjectInitializerInterface;
 use Symfony\Component\Validator\Util\PropertyPath;
 
@@ -99,7 +99,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
         if (null !== $constraints) {
             // You can pass a single constraint or an array of constraints
             // Make sure to deal with an array in the rest of the code
-            if (!is_array($constraints)) {
+            if (!\is_array($constraints)) {
                 $constraints = array($constraints);
             }
 
@@ -109,7 +109,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             $this->validateGenericNode(
                 $value,
                 $previousObject,
-                is_object($value) ? spl_object_hash($value) : null,
+                \is_object($value) ? spl_object_hash($value) : null,
                 $metadata,
                 $this->defaultPropertyPath,
                 $groups,
@@ -130,7 +130,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
 
         // If an object is passed without explicit constraints, validate that
         // object against the constraints defined for the object's class
-        if (is_object($value)) {
+        if (\is_object($value)) {
             $this->validateObject(
                 $value,
                 $this->defaultPropertyPath,
@@ -147,7 +147,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
 
         // If an array is passed without explicit constraints, validate each
         // object in the array
-        if (is_array($value)) {
+        if (\is_array($value)) {
             $this->validateEachObjectIn(
                 $value,
                 $this->defaultPropertyPath,
@@ -161,11 +161,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             return $this;
         }
 
-        throw new RuntimeException(sprintf(
-            'Cannot validate values of type "%s" automatically. Please '.
-            'provide a constraint.',
-            gettype($value)
-        ));
+        throw new RuntimeException(sprintf('Cannot validate values of type "%s" automatically. Please provide a constraint.', \gettype($value)));
     }
 
     /**
@@ -176,12 +172,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
         $classMetadata = $this->metadataFactory->getMetadataFor($object);
 
         if (!$classMetadata instanceof ClassMetadataInterface) {
-            throw new ValidatorException(sprintf(
-                'The metadata factory should return instances of '.
-                '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
-                'got: "%s".',
-                is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
-            ));
+            throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
         }
 
         $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
@@ -201,7 +192,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             $this->validateGenericNode(
                 $propertyValue,
                 $object,
-                $cacheKey.':'.get_class($object).':'.$propertyName,
+                $cacheKey.':'.\get_class($object).':'.$propertyName,
                 $propertyMetadata,
                 $propertyPath,
                 $groups,
@@ -225,20 +216,15 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
         $classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass);
 
         if (!$classMetadata instanceof ClassMetadataInterface) {
-            throw new ValidatorException(sprintf(
-                'The metadata factory should return instances of '.
-                '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
-                'got: "%s".',
-                is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
-            ));
+            throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
         }
 
         $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
         $groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups;
 
-        if (is_object($objectOrClass)) {
+        if (\is_object($objectOrClass)) {
             $object = $objectOrClass;
-            $class = get_class($object);
+            $class = \get_class($object);
             $cacheKey = spl_object_hash($objectOrClass);
             $propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
         } else {
@@ -286,13 +272,13 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
     /**
      * Normalizes the given group or list of groups to an array.
      *
-     * @param mixed $groups The groups to normalize
+     * @param string|GroupSequence|(string|GroupSequence)[] $groups The groups to normalize
      *
-     * @return array A group array
+     * @return (string|GroupSequence)[] A group array
      */
     protected function normalizeGroups($groups)
     {
-        if (is_array($groups)) {
+        if (\is_array($groups)) {
             return $groups;
         }
 
@@ -309,7 +295,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
      *
      * @param object                    $object            The object to cascade
      * @param string                    $propertyPath      The current property path
-     * @param string[]                  $groups            The validated groups
+     * @param (string|GroupSequence)[]  $groups            The validated groups
      * @param int                       $traversalStrategy The strategy for traversing the
      *                                                     cascaded object
      * @param ExecutionContextInterface $context           The current execution context
@@ -328,12 +314,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             $classMetadata = $this->metadataFactory->getMetadataFor($object);
 
             if (!$classMetadata instanceof ClassMetadataInterface) {
-                throw new UnsupportedMetadataException(sprintf(
-                    'The metadata factory should return instances of '.
-                    '"Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
-                    'got: "%s".',
-                    is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
-                ));
+                throw new UnsupportedMetadataException(sprintf('The metadata factory should return instances of "Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
             }
 
             $this->validateClassNode(
@@ -376,7 +357,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
      *
      * @param iterable                  $collection   The collection
      * @param string                    $propertyPath The current property path
-     * @param string[]                  $groups       The validated groups
+     * @param (string|GroupSequence)[]  $groups       The validated groups
      * @param ExecutionContextInterface $context      The current execution context
      *
      * @see ClassNode
@@ -385,7 +366,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
     private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context)
     {
         foreach ($collection as $key => $value) {
-            if (is_array($value)) {
+            if (\is_array($value)) {
                 // Arrays are always cascaded, independent of the specified
                 // traversal strategy
                 $this->validateEachObjectIn(
@@ -399,7 +380,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             }
 
             // Scalar and null values in the collection are ignored
-            if (is_object($value)) {
+            if (\is_object($value)) {
                 $this->validateObject(
                     $value,
                     $propertyPath.'['.$key.']',
@@ -443,7 +424,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
      *                                                     the object
      * @param string                    $propertyPath      The property path leading
      *                                                     to the object
-     * @param string[]                  $groups            The groups in which the
+     * @param (string|GroupSequence)[]  $groups            The groups in which the
      *                                                     object should be validated
      * @param string[]|null             $cascadedGroups    The groups in which
      *                                                     cascaded objects should
@@ -479,7 +460,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             $defaultOverridden = false;
 
             // Use the object hash for group sequences
-            $groupHash = is_object($group) ? spl_object_hash($group) : $group;
+            $groupHash = \is_object($group) ? spl_object_hash($group) : $group;
 
             if ($context->isGroupValidated($cacheKey, $groupHash)) {
                 // Skip this group when validating the properties and when
@@ -544,7 +525,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
 
         // If no more groups should be validated for the property nodes,
         // we can safely quit
-        if (0 === count($groups)) {
+        if (0 === \count($groups)) {
             return;
         }
 
@@ -555,12 +536,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             // returns two metadata objects, not just one
             foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
                 if (!$propertyMetadata instanceof PropertyMetadataInterface) {
-                    throw new UnsupportedMetadataException(sprintf(
-                        'The property metadata instances should implement '.
-                        '"Symfony\Component\Validator\Mapping\PropertyMetadataInterface", '.
-                        'got: "%s".',
-                        is_object($propertyMetadata) ? get_class($propertyMetadata) : gettype($propertyMetadata)
-                    ));
+                    throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', \is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata)));
                 }
 
                 $propertyValue = $propertyMetadata->getPropertyValue($object);
@@ -568,7 +544,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
                 $this->validateGenericNode(
                     $propertyValue,
                     $object,
-                    $cacheKey.':'.get_class($object).':'.$propertyName,
+                    $cacheKey.':'.\get_class($object).':'.$propertyName,
                     $propertyMetadata,
                     PropertyPath::append($propertyPath, $propertyName),
                     $groups,
@@ -597,11 +573,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
 
         // If TRAVERSE, fail if we have no Traversable
         if (!$object instanceof \Traversable) {
-            throw new ConstraintDefinitionException(sprintf(
-                'Traversal was enabled for "%s", but this class '.
-                'does not implement "\Traversable".',
-                get_class($object)
-            ));
+            throw new ConstraintDefinitionException(sprintf('Traversal was enabled for "%s", but this class does not implement "\Traversable".', \get_class($object)));
         }
 
         $this->validateEachObjectIn(
@@ -636,7 +608,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
      *                                                     value
      * @param string                    $propertyPath      The property path leading
      *                                                     to the value
-     * @param string[]                  $groups            The groups in which the
+     * @param (string|GroupSequence)[]  $groups            The groups in which the
      *                                                     value should be validated
      * @param string[]|null             $cascadedGroups    The groups in which
      *                                                     cascaded objects should
@@ -675,7 +647,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             $this->validateInGroup($value, $cacheKey, $metadata, $group, $context);
         }
 
-        if (0 === count($groups)) {
+        if (0 === \count($groups)) {
             return;
         }
 
@@ -686,7 +658,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
         $cascadingStrategy = $metadata->getCascadingStrategy();
 
         // Quit unless we have an array or a cascaded object
-        if (!is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) {
+        if (!\is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) {
             return;
         }
 
@@ -699,9 +671,9 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
         // The $cascadedGroups property is set, if the "Default" group is
         // overridden by a group sequence
         // See validateClassNode()
-        $cascadedGroups = null !== $cascadedGroups && count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
+        $cascadedGroups = null !== $cascadedGroups && \count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
 
-        if (is_array($value)) {
+        if (\is_array($value)) {
             // Arrays are always traversed, independent of the specified
             // traversal strategy
             $this->validateEachObjectIn(
@@ -757,7 +729,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
      */
     private function stepThroughGroupSequence($value, $object, $cacheKey, MetadataInterface $metadata = null, $propertyPath, $traversalStrategy, GroupSequence $groupSequence, $cascadedGroup, ExecutionContextInterface $context)
     {
-        $violationCount = count($context->getViolations());
+        $violationCount = \count($context->getViolations());
         $cascadedGroups = $cascadedGroup ? array($cascadedGroup) : null;
 
         foreach ($groupSequence->groups as $groupInSequence) {
@@ -789,7 +761,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
             }
 
             // Abort sequence validation if a violation was generated
-            if (count($context->getViolations()) > $violationCount) {
+            if (\count($context->getViolations()) > $violationCount) {
                 break;
             }
         }