Skip to content

Commit eead643

Browse files
committed
minor #32264 [Validator] add parameter type hints to the Validator component (xabbuh)
This PR was merged into the 5.0-dev branch. Discussion ---------- [Validator] add parameter type hints to the Validator component | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | Commits ------- df3a5cb add parameter type hints to the Validator component
2 parents faaa83c + df3a5cb commit eead643

21 files changed

+71
-71
lines changed

src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(ManagerRegistry $registry)
2828
$this->registry = $registry;
2929
}
3030

31-
public function initialize($object)
31+
public function initialize(object $object)
3232
{
3333
$manager = $this->registry->getManagerForClass(\get_class($object));
3434
if (null !== $manager) {

src/Symfony/Component/Validator/ConstraintViolationList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function addAll(ConstraintViolationListInterface $otherList)
7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function get($offset)
75+
public function get(int $offset)
7676
{
7777
if (!isset($this->violations[$offset])) {
7878
throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
@@ -84,23 +84,23 @@ public function get($offset)
8484
/**
8585
* {@inheritdoc}
8686
*/
87-
public function has($offset)
87+
public function has(int $offset)
8888
{
8989
return isset($this->violations[$offset]);
9090
}
9191

9292
/**
9393
* {@inheritdoc}
9494
*/
95-
public function set($offset, ConstraintViolationInterface $violation)
95+
public function set(int $offset, ConstraintViolationInterface $violation)
9696
{
9797
$this->violations[$offset] = $violation;
9898
}
9999

100100
/**
101101
* {@inheritdoc}
102102
*/
103-
public function remove($offset)
103+
public function remove(int $offset)
104104
{
105105
unset($this->violations[$offset]);
106106
}

src/Symfony/Component/Validator/ConstraintViolationListInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function addAll(self $otherList);
3737
*
3838
* @throws \OutOfBoundsException if the offset does not exist
3939
*/
40-
public function get($offset);
40+
public function get(int $offset);
4141

4242
/**
4343
* Returns whether the given offset exists.
@@ -46,20 +46,20 @@ public function get($offset);
4646
*
4747
* @return bool Whether the offset exists
4848
*/
49-
public function has($offset);
49+
public function has(int $offset);
5050

5151
/**
5252
* Sets a violation at a given offset.
5353
*
5454
* @param int $offset The violation offset
5555
* @param ConstraintViolationInterface $violation The violation
5656
*/
57-
public function set($offset, ConstraintViolationInterface $violation);
57+
public function set(int $offset, ConstraintViolationInterface $violation);
5858

5959
/**
6060
* Removes a violation at a given offset.
6161
*
6262
* @param int $offset The offset to remove
6363
*/
64-
public function remove($offset);
64+
public function remove(int $offset);
6565
}

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function __construct(ValidatorInterface $validator, $root, TranslatorInte
143143
/**
144144
* {@inheritdoc}
145145
*/
146-
public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath)
146+
public function setNode($value, ?object $object, MetadataInterface $metadata = null, string $propertyPath)
147147
{
148148
$this->value = $value;
149149
$this->object = $object;
@@ -154,7 +154,7 @@ public function setNode($value, $object, MetadataInterface $metadata = null, $pr
154154
/**
155155
* {@inheritdoc}
156156
*/
157-
public function setGroup($group)
157+
public function setGroup(?string $group)
158158
{
159159
$this->group = $group;
160160
}
@@ -170,7 +170,7 @@ public function setConstraint(Constraint $constraint)
170170
/**
171171
* {@inheritdoc}
172172
*/
173-
public function addViolation($message, array $parameters = [])
173+
public function addViolation(string $message, array $parameters = [])
174174
{
175175
$this->violations->add(new ConstraintViolation(
176176
$this->translator->trans($message, $parameters, $this->translationDomain),
@@ -188,7 +188,7 @@ public function addViolation($message, array $parameters = [])
188188
/**
189189
* {@inheritdoc}
190190
*/
191-
public function buildViolation($message, array $parameters = [])
191+
public function buildViolation(string $message, array $parameters = [])
192192
{
193193
return new ConstraintViolationBuilder(
194194
$this->violations,
@@ -283,15 +283,15 @@ public function getPropertyName()
283283
/**
284284
* {@inheritdoc}
285285
*/
286-
public function getPropertyPath($subPath = '')
286+
public function getPropertyPath(string $subPath = '')
287287
{
288288
return PropertyPath::append($this->propertyPath, $subPath);
289289
}
290290

291291
/**
292292
* {@inheritdoc}
293293
*/
294-
public function markGroupAsValidated($cacheKey, $groupHash)
294+
public function markGroupAsValidated(string $cacheKey, string $groupHash)
295295
{
296296
if (!isset($this->validatedObjects[$cacheKey])) {
297297
$this->validatedObjects[$cacheKey] = [];
@@ -303,39 +303,39 @@ public function markGroupAsValidated($cacheKey, $groupHash)
303303
/**
304304
* {@inheritdoc}
305305
*/
306-
public function isGroupValidated($cacheKey, $groupHash)
306+
public function isGroupValidated(string $cacheKey, string $groupHash)
307307
{
308308
return isset($this->validatedObjects[$cacheKey][$groupHash]);
309309
}
310310

311311
/**
312312
* {@inheritdoc}
313313
*/
314-
public function markConstraintAsValidated($cacheKey, $constraintHash)
314+
public function markConstraintAsValidated(string $cacheKey, string $constraintHash)
315315
{
316316
$this->validatedConstraints[$cacheKey.':'.$constraintHash] = true;
317317
}
318318

319319
/**
320320
* {@inheritdoc}
321321
*/
322-
public function isConstraintValidated($cacheKey, $constraintHash)
322+
public function isConstraintValidated(string $cacheKey, string $constraintHash)
323323
{
324324
return isset($this->validatedConstraints[$cacheKey.':'.$constraintHash]);
325325
}
326326

327327
/**
328328
* {@inheritdoc}
329329
*/
330-
public function markObjectAsInitialized($cacheKey)
330+
public function markObjectAsInitialized(string $cacheKey)
331331
{
332332
$this->initializedObjects[$cacheKey] = true;
333333
}
334334

335335
/**
336336
* {@inheritdoc}
337337
*/
338-
public function isObjectInitialized($cacheKey)
338+
public function isObjectInitialized(string $cacheKey)
339339
{
340340
return isset($this->initializedObjects[$cacheKey]);
341341
}

src/Symfony/Component/Validator/Context/ExecutionContextInterface.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface ExecutionContextInterface
6767
* @param string $message The error message
6868
* @param array $params The parameters substituted in the error message
6969
*/
70-
public function addViolation($message, array $params = []);
70+
public function addViolation(string $message, array $params = []);
7171

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

9191
/**
9292
* Returns the validator.
@@ -133,7 +133,7 @@ public function getObject();
133133
* @internal Used by the validator engine. Should not be called by user
134134
* code.
135135
*/
136-
public function setNode($value, $object, MetadataInterface $metadata = null, $propertyPath);
136+
public function setNode($value, ?object $object, MetadataInterface $metadata = null, string $propertyPath);
137137

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

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

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

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

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

209209
/**
210210
* Marks that an object was initialized.
@@ -216,7 +216,7 @@ public function isConstraintValidated($cacheKey, $constraintHash);
216216
*
217217
* @see ObjectInitializerInterface
218218
*/
219-
public function markObjectAsInitialized($cacheKey);
219+
public function markObjectAsInitialized(string $cacheKey);
220220

221221
/**
222222
* Returns whether an object was initialized.
@@ -230,7 +230,7 @@ public function markObjectAsInitialized($cacheKey);
230230
*
231231
* @see ObjectInitializerInterface
232232
*/
233-
public function isObjectInitialized($cacheKey);
233+
public function isObjectInitialized(string $cacheKey);
234234

235235
/**
236236
* Returns the violations generated by the validator so far.
@@ -340,5 +340,5 @@ public function getPropertyName();
340340
* string if the validator is currently validating the
341341
* root value of the validation graph.
342342
*/
343-
public function getPropertyPath($subPath = '');
343+
public function getPropertyPath(string $subPath = '');
344344
}

src/Symfony/Component/Validator/Mapping/Cache/CacheInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface CacheInterface
2525
*
2626
* @param string $class
2727
*/
28-
public function has($class);
28+
public function has(string $class);
2929

3030
/**
3131
* Returns the metadata for the given class from the cache.
@@ -34,7 +34,7 @@ public function has($class);
3434
*
3535
* @return ClassMetadata|false A ClassMetadata instance or false on miss
3636
*/
37-
public function read($class);
37+
public function read(string $class);
3838

3939
/**
4040
* Stores a class metadata in the cache.

src/Symfony/Component/Validator/Mapping/Cache/DoctrineCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public function setCache(Cache $cache)
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function has($class): bool
39+
public function has(string $class): bool
4040
{
4141
return $this->cache->contains($class);
4242
}
4343

4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function read($class)
47+
public function read(string $class)
4848
{
4949
return $this->cache->fetch($class);
5050
}

src/Symfony/Component/Validator/Mapping/Cache/Psr6Cache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public function __construct(CacheItemPoolInterface $cacheItemPool)
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function has($class)
34+
public function has(string $class)
3535
{
3636
return $this->cacheItemPool->hasItem($this->escapeClassName($class));
3737
}
3838

3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function read($class)
42+
public function read(string $class)
4343
{
4444
$item = $this->cacheItemPool->getItem($this->escapeClassName($class));
4545

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,15 @@ public function mergeConstraints(self $source)
364364
/**
365365
* {@inheritdoc}
366366
*/
367-
public function hasPropertyMetadata($property)
367+
public function hasPropertyMetadata(string $property)
368368
{
369369
return \array_key_exists($property, $this->members);
370370
}
371371

372372
/**
373373
* {@inheritdoc}
374374
*/
375-
public function getPropertyMetadata($property)
375+
public function getPropertyMetadata(string $property)
376376
{
377377
if (!isset($this->members[$property])) {
378378
return [];

src/Symfony/Component/Validator/Mapping/ClassMetadataInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function isGroupSequenceProvider();
8181
*
8282
* @return bool
8383
*/
84-
public function hasPropertyMetadata($property);
84+
public function hasPropertyMetadata(string $property);
8585

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

9999
/**
100100
* Returns the name of the backing PHP class.

0 commit comments

Comments
 (0)
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