[Validator] Add more parameter types.
This commit is contained in:
parent
90e3da4edd
commit
a7457099f8
@ -83,7 +83,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
*
|
*
|
||||||
* @return string The string representation of the passed 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;
|
$isDateTime = $value instanceof \DateTimeInterface;
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
*
|
*
|
||||||
* @see formatValue()
|
* @see formatValue()
|
||||||
*/
|
*/
|
||||||
protected function formatValues(array $values, $format = 0)
|
protected function formatValues(array $values, int $format = 0)
|
||||||
{
|
{
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
$values[$key] = $this->formatValue($value, $format);
|
$values[$key] = $this->formatValue($value, $format);
|
||||||
|
@ -199,9 +199,9 @@ class FileValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,11 +205,9 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
/**
|
/**
|
||||||
* Adds a constraint to the given property.
|
* Adds a constraint to the given property.
|
||||||
*
|
*
|
||||||
* @param string $property The name of the property
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addPropertyConstraint($property, Constraint $constraint)
|
public function addPropertyConstraint(string $property, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if (!isset($this->properties[$property])) {
|
if (!isset($this->properties[$property])) {
|
||||||
$this->properties[$property] = new PropertyMetadata($this->getClassName(), $property);
|
$this->properties[$property] = new PropertyMetadata($this->getClassName(), $property);
|
||||||
@ -225,12 +223,11 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $property
|
|
||||||
* @param Constraint[] $constraints
|
* @param Constraint[] $constraints
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addPropertyConstraints($property, array $constraints)
|
public function addPropertyConstraints(string $property, array $constraints)
|
||||||
{
|
{
|
||||||
foreach ($constraints as $constraint) {
|
foreach ($constraints as $constraint) {
|
||||||
$this->addPropertyConstraint($property, $constraint);
|
$this->addPropertyConstraint($property, $constraint);
|
||||||
@ -245,11 +242,9 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
* The name of the getter is assumed to be the name of the property with an
|
* 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".
|
* uppercased first letter and either the prefix "get" or "is".
|
||||||
*
|
*
|
||||||
* @param string $property The name of the property
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addGetterConstraint($property, Constraint $constraint)
|
public function addGetterConstraint(string $property, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if (!isset($this->getters[$property])) {
|
if (!isset($this->getters[$property])) {
|
||||||
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property);
|
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property);
|
||||||
@ -267,12 +262,9 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
/**
|
/**
|
||||||
* Adds a constraint to the getter of the given property.
|
* 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
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addGetterMethodConstraint($property, $method, Constraint $constraint)
|
public function addGetterMethodConstraint(string $property, string $method, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if (!isset($this->getters[$property])) {
|
if (!isset($this->getters[$property])) {
|
||||||
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property, $method);
|
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property, $method);
|
||||||
@ -288,12 +280,11 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $property
|
|
||||||
* @param Constraint[] $constraints
|
* @param Constraint[] $constraints
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addGetterConstraints($property, array $constraints)
|
public function addGetterConstraints(string $property, array $constraints)
|
||||||
{
|
{
|
||||||
foreach ($constraints as $constraint) {
|
foreach ($constraints as $constraint) {
|
||||||
$this->addGetterConstraint($property, $constraint);
|
$this->addGetterConstraint($property, $constraint);
|
||||||
@ -303,13 +294,11 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $property
|
|
||||||
* @param string $method
|
|
||||||
* @param Constraint[] $constraints
|
* @param Constraint[] $constraints
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addGetterMethodConstraints($property, $method, array $constraints)
|
public function addGetterMethodConstraints(string $property, string $method, array $constraints)
|
||||||
{
|
{
|
||||||
foreach ($constraints as $constraint) {
|
foreach ($constraints as $constraint) {
|
||||||
$this->addGetterMethodConstraint($property, $method, $constraint);
|
$this->addGetterMethodConstraint($property, $method, $constraint);
|
||||||
@ -451,11 +440,9 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
|||||||
/**
|
/**
|
||||||
* Sets whether a group sequence provider should be used.
|
* Sets whether a group sequence provider should be used.
|
||||||
*
|
*
|
||||||
* @param bool $active
|
|
||||||
*
|
|
||||||
* @throws GroupDefinitionException
|
* @throws GroupDefinitionException
|
||||||
*/
|
*/
|
||||||
public function setGroupSequenceProvider($active)
|
public function setGroupSequenceProvider(bool $active)
|
||||||
{
|
{
|
||||||
if ($this->hasGroupSequence()) {
|
if ($this->hasGroupSequence()) {
|
||||||
throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence');
|
throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence');
|
||||||
|
@ -43,11 +43,8 @@ abstract class AbstractLoader implements LoaderInterface
|
|||||||
* $this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\');
|
* $this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\');
|
||||||
*
|
*
|
||||||
* $constraint = $this->newConstraint('mynamespace:NotNull');
|
* $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;
|
$this->namespaces[$alias] = $namespace;
|
||||||
}
|
}
|
||||||
@ -67,7 +64,7 @@ abstract class AbstractLoader implements LoaderInterface
|
|||||||
*
|
*
|
||||||
* @throws MappingException If the namespace prefix is undefined
|
* @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)) {
|
if (false !== strpos($name, '\\') && class_exists($name)) {
|
||||||
$className = (string) $name;
|
$className = (string) $name;
|
||||||
|
@ -35,11 +35,9 @@ abstract class FilesLoader extends LoaderChain
|
|||||||
/**
|
/**
|
||||||
* Returns an array of file loaders for the given file 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
|
* @return LoaderInterface[] The metadata loaders
|
||||||
*/
|
*/
|
||||||
protected function getFileLoaders($paths)
|
protected function getFileLoaders(array $paths)
|
||||||
{
|
{
|
||||||
$loaders = [];
|
$loaders = [];
|
||||||
|
|
||||||
@ -53,9 +51,7 @@ abstract class FilesLoader extends LoaderChain
|
|||||||
/**
|
/**
|
||||||
* Creates a loader for the given file path.
|
* Creates a loader for the given file path.
|
||||||
*
|
*
|
||||||
* @param string $path The file path
|
|
||||||
*
|
|
||||||
* @return LoaderInterface The created loader
|
* @return LoaderInterface The created loader
|
||||||
*/
|
*/
|
||||||
abstract protected function getFileLoaderInstance($path);
|
abstract protected function getFileLoaderInstance(string $path);
|
||||||
}
|
}
|
||||||
|
@ -167,13 +167,11 @@ class XmlFileLoader extends FileLoader
|
|||||||
/**
|
/**
|
||||||
* Loads the XML class descriptions from the given file.
|
* Loads the XML class descriptions from the given file.
|
||||||
*
|
*
|
||||||
* @param string $path The path of the XML file
|
|
||||||
*
|
|
||||||
* @return \SimpleXMLElement The class descriptions
|
* @return \SimpleXMLElement The class descriptions
|
||||||
*
|
*
|
||||||
* @throws MappingException If the file could not be loaded
|
* @throws MappingException If the file could not be loaded
|
||||||
*/
|
*/
|
||||||
protected function parseFile($path)
|
protected function parseFile(string $path)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');
|
$dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');
|
||||||
|
@ -24,7 +24,7 @@ class XmlFilesLoader extends FilesLoader
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getFileLoaderInstance($file)
|
public function getFileLoaderInstance(string $file)
|
||||||
{
|
{
|
||||||
return new XmlFileLoader($file);
|
return new XmlFileLoader($file);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class YamlFilesLoader extends FilesLoader
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getFileLoaderInstance($file)
|
public function getFileLoaderInstance(string $file)
|
||||||
{
|
{
|
||||||
return new YamlFileLoader($file);
|
return new YamlFileLoader($file);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ abstract class FilesLoader extends BaseFilesLoader
|
|||||||
parent::__construct($paths);
|
parent::__construct($paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFileLoaderInstance($file)
|
protected function getFileLoaderInstance(string $file)
|
||||||
{
|
{
|
||||||
++$this->timesCalled;
|
++$this->timesCalled;
|
||||||
|
|
||||||
|
@ -29,19 +29,16 @@ class PropertyPath
|
|||||||
* returned. Otherwise, the concatenation of the two paths is returned,
|
* returned. Otherwise, the concatenation of the two paths is returned,
|
||||||
* separated by a dot (".").
|
* 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
|
* @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]) {
|
if ('[' === $subPath[0]) {
|
||||||
return $basePath.$subPath;
|
return $basePath.$subPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath;
|
return '' !== $basePath ? $basePath.'.'.$subPath : $subPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $basePath;
|
return $basePath;
|
||||||
|
Reference in New Issue
Block a user