Skip to content

[Validator] add parameter type hints to the Validator component #32264

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
Jun 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(ManagerRegistry $registry)
$this->registry = $registry;
}

public function initialize($object)
public function initialize(object $object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, DoctrineBridge 5.0 will become incompatible with Validator 4.4. We should either revert this line or update the composer.json file of DoctrineBridge.

{
$manager = $this->registry->getManagerForClass(\get_class($object));
if (null !== $manager) {
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/ConstraintViolationList.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function addAll(ConstraintViolationListInterface $otherList)
/**
* {@inheritdoc}
*/
public function get($offset)
public function get(int $offset)
{
if (!isset($this->violations[$offset])) {
throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
Expand All @@ -84,23 +84,23 @@ public function get($offset)
/**
* {@inheritdoc}
*/
public function has($offset)
public function has(int $offset)
{
return isset($this->violations[$offset]);
}

/**
* {@inheritdoc}
*/
public function set($offset, ConstraintViolationInterface $violation)
public function set(int $offset, ConstraintViolationInterface $violation)
{
$this->violations[$offset] = $violation;
}

/**
* {@inheritdoc}
*/
public function remove($offset)
public function remove(int $offset)
{
unset($this->violations[$offset]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function addAll(self $otherList);
*
* @throws \OutOfBoundsException if the offset does not exist
*/
public function get($offset);
public function get(int $offset);

/**
* Returns whether the given offset exists.
Expand All @@ -46,20 +46,20 @@ public function get($offset);
*
* @return bool Whether the offset exists
*/
public function has($offset);
public function has(int $offset);

/**
* Sets a violation at a given offset.
*
* @param int $offset The violation offset
* @param ConstraintViolationInterface $violation The violation
*/
public function set($offset, ConstraintViolationInterface $violation);
public function set(int $offset, ConstraintViolationInterface $violation);

/**
* Removes a violation at a given offset.
*
* @param int $offset The offset to remove
*/
public function remove($offset);
public function remove(int $offset);
}
22 changes: 11 additions & 11 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function __construct(ValidatorInterface $validator, $root, TranslatorInte
/**
* {@inheritdoc}
*/
public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath)
public function setNode($value, ?object $object, MetadataInterface $metadata = null, string $propertyPath)
{
$this->value = $value;
$this->object = $object;
Expand All @@ -154,7 +154,7 @@ public function setNode($value, $object, MetadataInterface $metadata = null, $pr
/**
* {@inheritdoc}
*/
public function setGroup($group)
public function setGroup(?string $group)
{
$this->group = $group;
}
Expand All @@ -170,7 +170,7 @@ public function setConstraint(Constraint $constraint)
/**
* {@inheritdoc}
*/
public function addViolation($message, array $parameters = [])
public function addViolation(string $message, array $parameters = [])
{
$this->violations->add(new ConstraintViolation(
$this->translator->trans($message, $parameters, $this->translationDomain),
Expand All @@ -188,7 +188,7 @@ public function addViolation($message, array $parameters = [])
/**
* {@inheritdoc}
*/
public function buildViolation($message, array $parameters = [])
public function buildViolation(string $message, array $parameters = [])
{
return new ConstraintViolationBuilder(
$this->violations,
Expand Down Expand Up @@ -283,15 +283,15 @@ public function getPropertyName()
/**
* {@inheritdoc}
*/
public function getPropertyPath($subPath = '')
public function getPropertyPath(string $subPath = '')
{
return PropertyPath::append($this->propertyPath, $subPath);
}

/**
* {@inheritdoc}
*/
public function markGroupAsValidated($cacheKey, $groupHash)
public function markGroupAsValidated(string $cacheKey, string $groupHash)
{
if (!isset($this->validatedObjects[$cacheKey])) {
$this->validatedObjects[$cacheKey] = [];
Expand All @@ -303,39 +303,39 @@ public function markGroupAsValidated($cacheKey, $groupHash)
/**
* {@inheritdoc}
*/
public function isGroupValidated($cacheKey, $groupHash)
public function isGroupValidated(string $cacheKey, string $groupHash)
{
return isset($this->validatedObjects[$cacheKey][$groupHash]);
}

/**
* {@inheritdoc}
*/
public function markConstraintAsValidated($cacheKey, $constraintHash)
public function markConstraintAsValidated(string $cacheKey, string $constraintHash)
{
$this->validatedConstraints[$cacheKey.':'.$constraintHash] = true;
}

/**
* {@inheritdoc}
*/
public function isConstraintValidated($cacheKey, $constraintHash)
public function isConstraintValidated(string $cacheKey, string $constraintHash)
{
return isset($this->validatedConstraints[$cacheKey.':'.$constraintHash]);
}

/**
* {@inheritdoc}
*/
public function markObjectAsInitialized($cacheKey)
public function markObjectAsInitialized(string $cacheKey)
{
$this->initializedObjects[$cacheKey] = true;
}

/**
* {@inheritdoc}
*/
public function isObjectInitialized($cacheKey)
public function isObjectInitialized(string $cacheKey)
{
return isset($this->initializedObjects[$cacheKey]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface ExecutionContextInterface
* @param string $message The error message
* @param array $params The parameters substituted in the error message
*/
public function addViolation($message, array $params = []);
public function addViolation(string $message, array $params = []);

/**
* Returns a builder for adding a violation with extended information.
Expand All @@ -86,7 +86,7 @@ public function addViolation($message, array $params = []);
*
* @return ConstraintViolationBuilderInterface The violation builder
*/
public function buildViolation($message, array $parameters = []);
public function buildViolation(string $message, array $parameters = []);

/**
* Returns the validator.
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getObject();
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath);
public function setNode($value, ?object $object, MetadataInterface $metadata = null, string $propertyPath);

/**
* Sets the currently validated group.
Expand All @@ -143,7 +143,7 @@ public function setNode($value, $object, MetadataInterface $metadata = null, $pr
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function setGroup($group);
public function setGroup(?string $group);

/**
* Sets the currently validated constraint.
Expand All @@ -165,7 +165,7 @@ public function setConstraint(Constraint $constraint);
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function markGroupAsValidated($cacheKey, $groupHash);
public function markGroupAsValidated(string $cacheKey, string $groupHash);

/**
* Returns whether an object was validated in a specific validation group.
Expand All @@ -180,7 +180,7 @@ public function markGroupAsValidated($cacheKey, $groupHash);
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function isGroupValidated($cacheKey, $groupHash);
public function isGroupValidated(string $cacheKey, string $groupHash);

/**
* Marks a constraint as validated for an object.
Expand All @@ -191,7 +191,7 @@ public function isGroupValidated($cacheKey, $groupHash);
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function markConstraintAsValidated($cacheKey, $constraintHash);
public function markConstraintAsValidated(string $cacheKey, string $constraintHash);

/**
* Returns whether a constraint was validated for an object.
Expand All @@ -204,7 +204,7 @@ public function markConstraintAsValidated($cacheKey, $constraintHash);
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function isConstraintValidated($cacheKey, $constraintHash);
public function isConstraintValidated(string $cacheKey, string $constraintHash);

/**
* Marks that an object was initialized.
Expand All @@ -216,7 +216,7 @@ public function isConstraintValidated($cacheKey, $constraintHash);
*
* @see ObjectInitializerInterface
*/
public function markObjectAsInitialized($cacheKey);
public function markObjectAsInitialized(string $cacheKey);

/**
* Returns whether an object was initialized.
Expand All @@ -230,7 +230,7 @@ public function markObjectAsInitialized($cacheKey);
*
* @see ObjectInitializerInterface
*/
public function isObjectInitialized($cacheKey);
public function isObjectInitialized(string $cacheKey);

/**
* Returns the violations generated by the validator so far.
Expand Down Expand Up @@ -340,5 +340,5 @@ public function getPropertyName();
* string if the validator is currently validating the
* root value of the validation graph.
*/
public function getPropertyPath($subPath = '');
public function getPropertyPath(string $subPath = '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface CacheInterface
*
* @param string $class
*/
public function has($class);
public function has(string $class);

/**
* Returns the metadata for the given class from the cache.
Expand All @@ -34,7 +34,7 @@ public function has($class);
*
* @return ClassMetadata|false A ClassMetadata instance or false on miss
*/
public function read($class);
public function read(string $class);

/**
* Stores a class metadata in the cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public function setCache(Cache $cache)
/**
* {@inheritdoc}
*/
public function has($class): bool
public function has(string $class): bool
{
return $this->cache->contains($class);
}

/**
* {@inheritdoc}
*/
public function read($class)
public function read(string $class)
{
return $this->cache->fetch($class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function __construct(CacheItemPoolInterface $cacheItemPool)
/**
* {@inheritdoc}
*/
public function has($class)
public function has(string $class)
{
return $this->cacheItemPool->hasItem($this->escapeClassName($class));
}

/**
* {@inheritdoc}
*/
public function read($class)
public function read(string $class)
{
$item = $this->cacheItemPool->getItem($this->escapeClassName($class));

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ public function mergeConstraints(self $source)
/**
* {@inheritdoc}
*/
public function hasPropertyMetadata($property)
public function hasPropertyMetadata(string $property)
{
return \array_key_exists($property, $this->members);
}

/**
* {@inheritdoc}
*/
public function getPropertyMetadata($property)
public function getPropertyMetadata(string $property)
{
if (!isset($this->members[$property])) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function isGroupSequenceProvider();
*
* @return bool
*/
public function hasPropertyMetadata($property);
public function hasPropertyMetadata(string $property);

/**
* Returns all metadata instances for the given named property.
Expand All @@ -94,7 +94,7 @@ public function hasPropertyMetadata($property);
* @return PropertyMetadataInterface[] A list of metadata instances. Empty if
* no metadata exists for the property.
*/
public function getPropertyMetadata($property);
public function getPropertyMetadata(string $property);

/**
* Returns the name of the backing PHP class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function hasConstraints()
*
* Aware of the global group (* group).
*/
public function findConstraints($group)
public function findConstraints(string $group)
{
return isset($this->constraintsByGroup[$group])
? $this->constraintsByGroup[$group]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ public function getConstraints();
*
* @return Constraint[] A list of constraint instances
*/
public function findConstraints($group);
public function findConstraints(string $group);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface ObjectInitializerInterface
*
* @param object $object The object to validate
*/
public function initialize($object);
public function initialize(object $object);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class FakeClassMetadata extends ClassMetadata
{
public function addCustomPropertyMetadata($propertyName, $metadata)
public function addCustomPropertyMetadata(string $propertyName, $metadata)
{
if (!isset($this->members[$propertyName])) {
$this->members[$propertyName] = [];
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy