Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Add more parameter types #33190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Validator/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Validator/Constraints/FileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
27 changes: 7 additions & 20 deletions 27 src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class XmlFilesLoader extends FilesLoader
/**
* {@inheritdoc}
*/
public function getFileLoaderInstance($file)
public function getFileLoaderInstance(string $file)
{
return new XmlFileLoader($file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class YamlFilesLoader extends FilesLoader
/**
* {@inheritdoc}
*/
public function getFileLoaderInstance($file)
public function getFileLoaderInstance(string $file)
{
return new YamlFileLoader($file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 3 additions & 6 deletions 9 src/Symfony/Component/Validator/Util/PropertyPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.