From a7457099f85ed028f8553f9c659b979b1b54fa72 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 16 Aug 2019 01:09:31 +0200 Subject: [PATCH] [Validator] Add more parameter types. --- .../Validator/ConstraintValidator.php | 4 +-- .../Validator/Constraints/FileValidator.php | 4 +-- .../Validator/Mapping/ClassMetadata.php | 27 +++++-------------- .../Mapping/Loader/AbstractLoader.php | 7 ++--- .../Validator/Mapping/Loader/FilesLoader.php | 8 ++---- .../Mapping/Loader/XmlFileLoader.php | 4 +-- .../Mapping/Loader/XmlFilesLoader.php | 2 +- .../Mapping/Loader/YamlFilesLoader.php | 2 +- .../Validator/Tests/Fixtures/FilesLoader.php | 2 +- .../Component/Validator/Util/PropertyPath.php | 9 +++---- 10 files changed, 22 insertions(+), 47 deletions(-) diff --git a/src/Symfony/Component/Validator/ConstraintValidator.php b/src/Symfony/Component/Validator/ConstraintValidator.php index 35f41889eaee7..704252f4021b0 100644 --- a/src/Symfony/Component/Validator/ConstraintValidator.php +++ b/src/Symfony/Component/Validator/ConstraintValidator.php @@ -83,7 +83,7 @@ protected function formatTypeOf($value) * * @return string The string representation of the passed value */ - protected function formatValue($value, $format = 0) + protected function formatValue($value, int $format = 0) { $isDateTime = $value instanceof \DateTimeInterface; @@ -156,7 +156,7 @@ protected function formatValue($value, $format = 0) * * @see formatValue() */ - protected function formatValues(array $values, $format = 0) + protected function formatValues(array $values, int $format = 0) { foreach ($values as $key => $value) { $values[$key] = $this->formatValue($value, $format); diff --git a/src/Symfony/Component/Validator/Constraints/FileValidator.php b/src/Symfony/Component/Validator/Constraints/FileValidator.php index 29c25b70bb162..eb06c732ec996 100644 --- a/src/Symfony/Component/Validator/Constraints/FileValidator.php +++ b/src/Symfony/Component/Validator/Constraints/FileValidator.php @@ -199,9 +199,9 @@ public function validate($value, Constraint $constraint) } } - private static function moreDecimalsThan($double, $numberOfDecimals) + private static function moreDecimalsThan(string $double, int $numberOfDecimals): bool { - return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals)); + return \strlen($double) > \strlen(round($double, $numberOfDecimals)); } /** diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index f5695e3821c09..a07a608c3af4d 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -205,11 +205,9 @@ public function addConstraint(Constraint $constraint) /** * Adds a constraint to the given property. * - * @param string $property The name of the property - * * @return $this */ - public function addPropertyConstraint($property, Constraint $constraint) + public function addPropertyConstraint(string $property, Constraint $constraint) { if (!isset($this->properties[$property])) { $this->properties[$property] = new PropertyMetadata($this->getClassName(), $property); @@ -225,12 +223,11 @@ public function addPropertyConstraint($property, Constraint $constraint) } /** - * @param string $property * @param Constraint[] $constraints * * @return $this */ - public function addPropertyConstraints($property, array $constraints) + public function addPropertyConstraints(string $property, array $constraints) { foreach ($constraints as $constraint) { $this->addPropertyConstraint($property, $constraint); @@ -245,11 +242,9 @@ public function addPropertyConstraints($property, array $constraints) * The name of the getter is assumed to be the name of the property with an * uppercased first letter and either the prefix "get" or "is". * - * @param string $property The name of the property - * * @return $this */ - public function addGetterConstraint($property, Constraint $constraint) + public function addGetterConstraint(string $property, Constraint $constraint) { if (!isset($this->getters[$property])) { $this->getters[$property] = new GetterMetadata($this->getClassName(), $property); @@ -267,12 +262,9 @@ public function addGetterConstraint($property, Constraint $constraint) /** * Adds a constraint to the getter of the given property. * - * @param string $property The name of the property - * @param string $method The name of the getter method - * * @return $this */ - public function addGetterMethodConstraint($property, $method, Constraint $constraint) + public function addGetterMethodConstraint(string $property, string $method, Constraint $constraint) { if (!isset($this->getters[$property])) { $this->getters[$property] = new GetterMetadata($this->getClassName(), $property, $method); @@ -288,12 +280,11 @@ public function addGetterMethodConstraint($property, $method, Constraint $constr } /** - * @param string $property * @param Constraint[] $constraints * * @return $this */ - public function addGetterConstraints($property, array $constraints) + public function addGetterConstraints(string $property, array $constraints) { foreach ($constraints as $constraint) { $this->addGetterConstraint($property, $constraint); @@ -303,13 +294,11 @@ public function addGetterConstraints($property, array $constraints) } /** - * @param string $property - * @param string $method * @param Constraint[] $constraints * * @return $this */ - public function addGetterMethodConstraints($property, $method, array $constraints) + public function addGetterMethodConstraints(string $property, string $method, array $constraints) { foreach ($constraints as $constraint) { $this->addGetterMethodConstraint($property, $method, $constraint); @@ -451,11 +440,9 @@ public function getReflectionClass() /** * Sets whether a group sequence provider should be used. * - * @param bool $active - * * @throws GroupDefinitionException */ - public function setGroupSequenceProvider($active) + public function setGroupSequenceProvider(bool $active) { if ($this->hasGroupSequence()) { throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence'); diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php index ae2e1e04cde2a..7a9eb026f1f94 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php @@ -43,11 +43,8 @@ abstract class AbstractLoader implements LoaderInterface * $this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\'); * * $constraint = $this->newConstraint('mynamespace:NotNull'); - * - * @param string $alias The alias - * @param string $namespace The PHP namespace */ - protected function addNamespaceAlias($alias, $namespace) + protected function addNamespaceAlias(string $alias, string $namespace) { $this->namespaces[$alias] = $namespace; } @@ -67,7 +64,7 @@ protected function addNamespaceAlias($alias, $namespace) * * @throws MappingException If the namespace prefix is undefined */ - protected function newConstraint($name, $options = null) + protected function newConstraint(string $name, $options = null) { if (false !== strpos($name, '\\') && class_exists($name)) { $className = (string) $name; diff --git a/src/Symfony/Component/Validator/Mapping/Loader/FilesLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/FilesLoader.php index 0882c3932f01b..74ec8cd013922 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/FilesLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/FilesLoader.php @@ -35,11 +35,9 @@ public function __construct(array $paths) /** * Returns an array of file loaders for the given file paths. * - * @param array $paths An array of file paths - * * @return LoaderInterface[] The metadata loaders */ - protected function getFileLoaders($paths) + protected function getFileLoaders(array $paths) { $loaders = []; @@ -53,9 +51,7 @@ protected function getFileLoaders($paths) /** * Creates a loader for the given file path. * - * @param string $path The file path - * * @return LoaderInterface The created loader */ - abstract protected function getFileLoaderInstance($path); + abstract protected function getFileLoaderInstance(string $path); } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php index cec3ea6c2d56e..80d083c9bb540 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php @@ -167,13 +167,11 @@ protected function parseOptions(\SimpleXMLElement $nodes) /** * Loads the XML class descriptions from the given file. * - * @param string $path The path of the XML file - * * @return \SimpleXMLElement The class descriptions * * @throws MappingException If the file could not be loaded */ - protected function parseFile($path) + protected function parseFile(string $path) { try { $dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd'); diff --git a/src/Symfony/Component/Validator/Mapping/Loader/XmlFilesLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/XmlFilesLoader.php index 6017c3f44d23b..5a242b0256769 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/XmlFilesLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/XmlFilesLoader.php @@ -24,7 +24,7 @@ class XmlFilesLoader extends FilesLoader /** * {@inheritdoc} */ - public function getFileLoaderInstance($file) + public function getFileLoaderInstance(string $file) { return new XmlFileLoader($file); } diff --git a/src/Symfony/Component/Validator/Mapping/Loader/YamlFilesLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/YamlFilesLoader.php index 235856f5b980c..f32c67c74d9aa 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/YamlFilesLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/YamlFilesLoader.php @@ -24,7 +24,7 @@ class YamlFilesLoader extends FilesLoader /** * {@inheritdoc} */ - public function getFileLoaderInstance($file) + public function getFileLoaderInstance(string $file) { return new YamlFileLoader($file); } diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/FilesLoader.php b/src/Symfony/Component/Validator/Tests/Fixtures/FilesLoader.php index a4d6a6ab474a8..2719cc7fc66a3 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/FilesLoader.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/FilesLoader.php @@ -25,7 +25,7 @@ public function __construct(array $paths, LoaderInterface $loader) parent::__construct($paths); } - protected function getFileLoaderInstance($file) + protected function getFileLoaderInstance(string $file) { ++$this->timesCalled; diff --git a/src/Symfony/Component/Validator/Util/PropertyPath.php b/src/Symfony/Component/Validator/Util/PropertyPath.php index 4108a02c24f25..80cc73a1a1290 100644 --- a/src/Symfony/Component/Validator/Util/PropertyPath.php +++ b/src/Symfony/Component/Validator/Util/PropertyPath.php @@ -29,19 +29,16 @@ class PropertyPath * returned. Otherwise, the concatenation of the two paths is returned, * separated by a dot ("."). * - * @param string $basePath The base path - * @param string $subPath The path to append - * * @return string The concatenation of the two property paths */ - public static function append($basePath, $subPath) + public static function append(string $basePath, string $subPath) { - if ('' !== (string) $subPath) { + if ('' !== $subPath) { if ('[' === $subPath[0]) { return $basePath.$subPath; } - return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath; + return '' !== $basePath ? $basePath.'.'.$subPath : $subPath; } return $basePath;