8000 minor #41899 Add more types (nicolas-grekas) · symfony/symfony@ff940a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff940a0

Browse files
minor #41899 Add more types (nicolas-grekas)
This PR was merged into the 6.0 branch. Discussion ---------- Add more types | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Related to #41424 Commits ------- c21a7be Add more types
2 parents d0c7287 + c21a7be commit ff940a0

File tree

13 files changed

+44
-58
lines changed

13 files changed

+44
-58
lines changed

src/Symfony/Component/Validator/ConstraintViolation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConstraintViolation implements ConstraintViolationInterface
4949
* caused the violation
5050
* @param mixed $cause The cause of the violation
5151
*/
52-
public function __construct(string|\Stringable $message, ?string $messageTemplate, array $parameters, $root, ?string $propertyPath, $invalidValue, int $plural = null, string $code = null, Constraint $constraint = null, mixed $cause = null)
52+
public function __construct(string|\Stringable $message, ?string $messageTemplate, array $parameters, mixed $root, ?string $propertyPath, mixed $invalidValue, int $plural = null, string $code = null, Constraint $constraint = null, mixed $cause = null)
5353
{
5454
$this->message = $message;
5555
$this->messageTemplate = $messageTemplate;

src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\ExpectationFailedException;
2020
use PHPUnit\Framework\TestCase;
2121
use Symfony\Component\Validator\Constraint;
22+
use Symfony\Component\Validator\Constraints\GroupSequence;
2223
use Symfony\Component\Validator\Constraints\NotNull;
2324
use Symfony\Component\Validator\Constraints\Valid;
2425
use Symfony< F438 /span>\Component\Validator\ConstraintValidatorInterface;
@@ -168,13 +169,13 @@ protected function createContext()
168169
return $context;
169170
}
170171

171-
protected function setGroup($group)
172+
protected function setGroup(?string $group)
172173
{
173174
$this->group = $group;
174175
$this->context->setGroup($group);
175176
}
176177

177-
protected function setObject($object)
178+
protected function setObject(mixed $object)
178179
{
179180
$this->object = $object;
180181
$this->metadata = \is_object($object)
@@ -184,7 +185,7 @@ protected function setObject($object)
184185
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
185186
}
186187

187-
protected function setProperty($object, $property)
188+
protected function setProperty(mixed $object, string $property)
188189
{
189190
$this->object = $object;
190191
$this->metadata = \is_object($object)
@@ -194,20 +195,20 @@ protected function setProperty($object, $property)
194195
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
195196
}
196197

197-
protected function setValue($value)
198+
protected function setValue(mixed $value)
198199
{
199200
$this->value = $value;
200201
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
201202
}
202203

203-
protected function setRoot($root)
204+
protected function setRoot(mixed $root)
204205
{
205206
$this->root = $root;
206207
$this->context = $this->createContext();
207208
$this->validator->initialize($this-&g 10000 t;context);
208209
}
209210

210-
protected function setPropertyPath($propertyPath)
211+
protected function setPropertyPath(string $propertyPath)
211212
{
212213
$this->propertyPath = $propertyPath;
213214
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
@@ -219,7 +220,7 @@ protected function expectNoValidate()
219220
$validator->expectNoValidate();
220221
}
221222

222-
protected function expectValidateAt($i, $propertyPath, $value, $group)
223+
protected function expectValidateAt(int $i, string $propertyPath, mixed $value, string|GroupSequence|array|null $group)
223224
{
224225
$validator = $this->context->getValidator()->inContext($this->context);
225226
$validator->expectValidation($i, $propertyPath, $value, $group, function ($passedConstraints) {
@@ -230,7 +231,7 @@ protected function expectValidateAt($i, $propertyPath, $value, $group)
230231
});
231232
}
232233

233-
protected function expectValidateValue(int $i, $value, array $constraints = [], $group = null)
234+
protected function expectValidateValue(int $i, mixed $value, Constraint|array $constraints = [], string|GroupSequence|array|null $group = null)
234235
{
235236
$contextualValidator = $this->context->getValidator()->inContext($this->context);
236237
$contextualValidator->expectValidation($i, '', $value, $group, function ($passedConstraints) use ($constraints) {
@@ -242,7 +243,7 @@ protected function expectValidateValue(int $i, $value, array $constraints = [],
242243
});
243244
}
244245

245-
protected function expectFailingValueValidation(int $i, $value, array $constraints, $group, ConstraintViolationInterface $violation)
246+
protected function expectFailingValueValidation(int $i, mixed $value, Constraint|array $constraints, string|GroupSequence|array|null $group, ConstraintViolationInterface $violation)
246247
{
247248
$contextualValidator = $this->context->getValidator()->inContext($this->context);
248249
$contextualValidator->expectValidation($i, '', $value, $group, function ($passedConstraints) use ($constraints) {
@@ -254,15 +255,15 @@ protected function expectFailingValueValidation(int $i, $value, array $constrain
254255
}, $violation);
255256
}
256257

257-
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null)
258+
protected function expectValidateValueAt(int $i, string $propertyPath, mixed $value, Constraint|array $constraints, string|GroupSequence|array|null $group = null)
258259
{
259260
$contextualValidator = $this->context->getValidator()->inContext($this->context);
260261
$contextualValidator->expectValidation($i, $propertyPath, $value, $group, function ($passedConstraints) use ($constraints) {
261262
Assert::assertEquals($constraints, $passedConstraints);
262263
});
263264
}
264265

265-
protected function expectViolationsAt($i, $value, Constraint $constraint)
266+
protected function expectViolationsAt(int $i, mixed $value, Constraint $constraint)
266267
{
267268
$context = $this->createContext();
268269

@@ -283,11 +284,9 @@ protected function assertNoViolation()
283284
}
284285

285286
/**
286-
* @param $message
287-
*
288287
* @return ConstraintViolationAssertion
289288
*/
290-
protected function buildViolation($message)
289+
protected function buildViolation(string|\Stringable $message)
291290
{
292291
return new ConstraintViolationAssertion($this->context, $message, $this->constraint);
293292
}
@@ -334,7 +333,7 @@ public function atPath(string $path)
334333
return $this;
335334
}
336335

337-
public function setParameter(string $key, $value)
336+
public function setParameter(string $key, string $value)
338337
{
339338
$this->parameters[$key] = $value;
340339

@@ -348,14 +347,14 @@ public function setParameters(array $parameters)
348347
return $this;
349348
}
350349

351-
public function setTranslationDomain($translationDomain)
350+
public function setTranslationDomain(?string $translationDomain)
352351
{
353352
// no-op for BC
354353

355354
return $this;
356355
}
357356

358-
public function setInvalidValue($invalidValue)
357+
public function setInvalidValue(mixed $invalidValue)
359358
{
< F438 code>360359
$this->invalidValue = $invalidValue;
361360

@@ -376,7 +375,7 @@ public function setCode(string $code)
376375
return $this;
377376
}
378377

379-
public function setCause($cause)
378+
public function setCause(mixed $cause)
380379
{
381380
$this->cause = $cause;
382381

@@ -445,11 +444,11 @@ public function __construct(ExecutionContextInterface $context)
445444
$this->context = $context;
446445
}
447446

448-
public function atPath($path)
447+
public function atPath(string $path)
449448
{
450449
}
451450

452-
public function doAtPath($path)
451+
public function doAtPath(string $path)
453452
{
454453
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
455454

@@ -462,11 +461,11 @@ public function doAtPath($path)
462461
return $this;
463462
}
464463

465-
public function validate($value, $constraints = null, $groups = null)
464+
public function validate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null)
466465
{
467466
}
468467

469-
public function doValidate($value, $constraints = null, $groups = null)
468+
public function doValidate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null)
470469
{
471470
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
472471

@@ -487,20 +486,20 @@ public function doValidate($value, $constraints = null, $groups = null)
487486
return $this;
488487
}
489488

490-
public function validateProperty($object, $propertyName, $groups = null)
489+
public function validateProperty(object $object, string $propertyName, string|GroupSequence|array|null $groups = null)
491490
{
492491
}
493492

494-
public function doValidateProperty($object, $propertyName, $groups = null)
493+
public function doValidateProperty(object $object, string $propertyName, string|GroupSequence|array|null $groups = null)
495494
{
496495
return $this;
497496
}
498497

499-
public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null)
498+
public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array|null $groups = null)
500499
{
501500
}
502501

503-
public function doValidatePropertyValue($objectOrClass, $propertyName, $value, $groups = null)
502+
public function doValidatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array|null $groups = null)
504503
{
505504
return $this;
506505
}
@@ -519,7 +518,7 @@ public function expectNoValidate()
519518
$this->expectNoValidate = true;
520519
}
521520

522-
public function expectValidation($call, $propertyPath, $value, $group, $constraints, ConstraintViolationInterface $violation = null)
521+
public function expectValidation(string $call, string $propertyPath, mixed $value, string|GroupSequence|array|null $group, callable $constraints, ConstraintViolationInterface $violation = null)
523522
{
524523
$this->expectedAtPath[$call] = $propertyPath;
525524
$this->expectedValidate[$call] = [$value, $group, $constraints, $violation];

src/Symfony/Component/Validator/Validator/ContextualValidatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function atPath(string $path);
3939
* {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
4040
*
4141
* @param mixed $value The value to validate
42-
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against
42+
* @param Constraint|Constraint[]|null $constraints The constraint(s) to validate against
4343
* @param string|GroupSequence|array<string|GroupSequence>|null $groups The validation groups to validate. If none is given, "Default" is assumed
4444
*
4545
* @return $this
4646
*/
47-
public function validate(mixed $value, Constraint|array $constraints = null, string|GroupSequence|array|null $groups = null);
47+
public function validate(mixed $value, Constraint|array|null $constraints = null, string|GroupSequence|array|null $groups = null);
4848

4949
/**
5050
* Validates a property of an object against the constraints specified

src/Symfony/Component/Validator/Violation/ConstraintViolationBuilder.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,9 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
3737
private $plural;
3838
private $constraint;
3939
private $code;
40-
41-
/**
42-
* @var mixed
43-
*/
4440
private $cause;
4541

46-
/**
47-
* @param string $message The error message as a string or a stringable object
48-
*/
49-
public function __construct(ConstraintViolationList $violations, Constraint $constraint, $message, array $parameters, mixed $root, ?string $propertyPath, mixed $invalidValue, TranslatorInterface $translator, string $translationDomain = null)
42+
public function __construct(ConstraintViolationList $violations, Constraint $constraint, string|\Stringable $message, array $parameters, mixed $root, ?string $propertyPath, mixed $invalidValue, TranslatorInterface $translator, string $translationDomain = null)
5043
{
5144
$this->violations = $violations;
5245
$this->message = $message;
@@ -102,7 +95,7 @@ public function setTranslationDomain(string $translationDomain)
10295
/**
10396
* {@inheritdoc}
10497
*/
105-
public function setInvalidValue($invalidValue)
98+
public function setInvalidValue(mixed $invalidValue)
10699
{
107100
$this->invalidValue = $invalidValue;
108101

@@ -132,7 +125,7 @@ public function setCode(?string $code)
132125
/**
133126
* {@inheritdoc}
134127
*/
135-
public function setCause($cause)
128+
public function setCause(mixed $cause)
136129
{
137130
$this->cause = $cause;
138131

src/Symfony/Component/VarDumper/Caster/ClassStub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ClassStub extends ConstStub
2424
* @param string $identifier A PHP identifier, e.g. a class, method, interface, etc. name
2525
* @param callable $callable The callable targeted by the identifier when it is ambiguous or not a real PHP identifier
2626
*/
27-
public function __construct(string $identifier, $callable = null)
27+
public function __construct(string $identifier, callable|array|string $callable = null)
2828
{
2929
$this->value = $identifier;
3030

@@ -87,7 +87,7 @@ public function __construct(string $identifier, $callable = null)
8787
}
8888
}
8989

90-
public static function wrapCallable($callable)
90+
public static function wrapCallable(mixed $callable)
9191
{
9292
if (\is_object($callable) || !\is_callable($callable)) {
9393
return $callable;

src/Symfony/Component/VarDumper/Caster/ConstStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class ConstStub extends Stub
2222
{
23-
public function __construct(string $name, $value = null)
23+
public function __construct(string $name, string|int|float $value = null)
2424
{
2525
$this->class = $name;
2626
$this->value = 1 < \func_num_args() ? $value : $name;

src/Symfony/Component/VarDumper/Caster/DOMCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function castLength($dom, array $a, Stub $stub, bool $isNested)
8282
return $a;
8383
}
8484

85-
public static function castImplementation($dom, array $a, Stub $stub, bool $isNested)
85+
public static function castImplementation(\DOMImplementation $dom, array $a, Stub $stub, bool $isNested)
8686
{
8787
$a += [
8888
Caster::PREFIX_VIRTUAL.'Core' => '1.0',

src/Symfony/Component/VarDumper/Caster/ResourceCaster.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
*/
2323
class ResourceCaster
2424
{
25-
/**
26-
* @param \CurlHandle|resource $h
27-
*
28-
* @return array
29-
*/
30-
public static function castCurl($h, array $a, Stub $stub, bool $isNested)
25+
public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNested)
3126
{
3227
return curl_getinfo($h);
3328
}

src/Symfony/Component/VarDumper/Caster/SplCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public static function castWeakReference(\WeakReference $c, array $a, Stub $stub
211211
return $a;
212212
}
213213

214-
private static function castSplArray($c, array $a, Stub $stub, bool $isNested): array
214+
private static function castSplArray(\ArrayObject|\ArrayIterator $c, array $a, Stub $stub, bool $isNested): array
215215
{
216216
$prefix< 10000 /span> = Caster::PREFIX_VIRTUAL;
217217
$flags = $c->getFlags();

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ abstract class AbstractCloner implements ClonerInterface
150150
'Symfony\Component\VarDumper\Caster\DsPairStub' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'],
151151

152152
'CurlHandle' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
153-
':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
154153

155154
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
156155
':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],

src/Symfony/Component/VarDumper/Cloner/Data.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,22 @@ public function __isset(string $key)
150150
/**
151151
* @return bool
152152
*/
153-
public function offsetExists($key)
153+
public function offsetExists(mixed $key)
154154
{
155155
return $this->__isset($key);
156156
}
157157

158-
public function offsetGet($key)
158+
public function offsetGet(mixed $key)
159159
{
160160
return $this->__get($key);
161161
}
162162

163-
public function offsetSet($key, $value)
163+
public function offsetSet(mixed $key, mixed $value)
164164
{
165165
throw new \BadMethodCallException(self::class.' objects are immutable.');
166166
}
167167

168-
public function offsetUnset($key)
168+
public function offsetUnset(mixed $key)
169169
{
170170
throw new \BadMethodCallException(self::class.' objects are immutable.');
171171
}

src/Symfony/Component/Workflow/Dumper/GraphvizDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function dotize(string $id): string
245245
/**
246246
* @internal
247247
*/
248-
protected function escape($value): string
248+
protected function escape(string|bool $value): string
249249
{
250250
return \is_bool($value) ? ($value ? '1' : '0') : addslashes($value);
251251
}

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function parse(string $value = null, int $flags = 0, array &$refer
116116
*
117117
* @throws DumpException When trying to dump PHP resource
118118
*/
119-
public static function dump($value, int $flags = 0): string
119+
public static function dump(mixed $value, int $flags = 0): string
120120
{
121121
switch (true) {
122122
case \is_resource($value):

0 commit comments

Comments
 (0)
0