8000 [Config] Add parameter types · symfony/symfony@f0f3e50 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0f3e50

Browse files
committed
[Config] Add parameter types
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent f1372e4 commit f0f3e50

File tree

75 files changed

+271
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+271
-388
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(LoaderResolverInterface $resolver, array $defaultOpt
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function load($resource, string $type = null)
45+
public function load(mixed $resource, string $type = null)
4646
{
4747
if ($this->loading) {
4848
// This can happen if a fatal error occurs in parent::load().

src/Symfony/Component/Config/Definition/ArrayNode.php

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
3232
protected $removeExtraKeys = true;
3333
protected $normalizeKeys = true;
3434

35-
public function setNormalizeKeys($normalizeKeys)
35+
public function setNormalizeKeys(bool $normalizeKeys)
3636
{
37-
$this->normalizeKeys = (bool) $normalizeKeys;
37+
$this->normalizeKeys = $normalizeKeys;
3838
}
3939

4040
/**
@@ -46,7 +46,7 @@ public function setNormalizeKeys($normalizeKeys)
4646
* If you have a mixed key like foo-bar_moo, it will not be altered.
4747
* The key will also not be altered if the target key already exists.
4848
*/
49-
protected function preNormalize($value)
49+
protected function preNormalize(mixed $value)
5050
{
5151
if (!$this->normalizeKeys || !\is_array($value)) {
5252
return $value;
@@ -195,16 +195,12 @@ public function addChild(NodeInterface $node)
195195
}
196196

197197
/**
198-
* Finalizes the value of this node.
199-
*
200-
* @param mixed $value
201-
*
202-
* @return mixed The finalised value
198+
* {@inheritdoc}
203199
*
204200
* @throws UnsetKeyException
205201
* @throws InvalidConfigurationException if the node doesn't have enough children
206202
*/
207-
protected function finalizeValue($value)
203+
protected function finalizeValue(mixed $value)
208204
{
209205
if (false === $value) {
210206
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
@@ -248,13 +244,9 @@ protected function finalizeValue($value)
248244
}
249245

250246
/**
251-
* Validates the type of the value.
252-
*
253-
* @param mixed $value
254-
*
255-
* @throws InvalidTypeException
247+
* {@inheritdoc}
256248
*/
257-
protected function validateType($value)
249+
protected function validateType(mixed $value)
258250
{
259251
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
260252
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
@@ -268,15 +260,11 @@ protected function validateType($value)
268260
}
269261

270262
/**
271-
* Normalizes the value.
272-
*
273-
* @param mixed $value The value to normalize
274-
*
275-
* @return mixed The normalized value
263+
* {@inheritdoc}
276264
*
277265
* @throws InvalidConfigurationException
278266
*/
279-
protected function normalizeValue($value)
267+
protected function normalizeValue(mixed $value)
280268
{
281269
if (false === $value) {
282270
return $value;
@@ -352,17 +340,12 @@ protected function remapXml(array $value)
352340
}
353341

354342
/**
355-
* Merges values together.
356-
*
357-
* @param mixed $leftSide The left side to merge
358-
* @param mixed $rightSide The right side to merge
359-
*
360-
* @return mixed The merged values
343+
* {@inheritdoc}
361344
*
362345
* @throws InvalidConfigurationException
363346
* @throws \RuntimeException
364347
*/
365-
protected function mergeValues($leftSide, $rightSide)
348+
protected function mergeValues(mixed $leftSide, mixed $rightSide)
366349
{
367350
if (false === $rightSide) {
368351
// if this is still false after the last config has been merged the

src/Symfony/Component/Config/Definition/BaseNode.php

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public static function resetPlaceholders(): void
9797
self::$placeholders = [];
9898
}
9999

100-
public function setAttribute(string $key, $value)
100+
public function setAttribute(string $key, mixed $value)
101101
{
102102
$this->attributes[$key] = $value;
103103
}
104104

105105
/**
106106
* @return mixed
107107
*/
108-
public function getAttribute(string $key, $default = null)
108+
public function getAttribute(string $key, mixed $default = null)
109109
{
110110
return $this->attributes[$key] ?? $default;
111111
}
@@ -156,10 +156,8 @@ public function getInfo()
156156

157157
/**
158158
* Sets the example configuration for this node.
159-
*
160-
* @param string|array $example
161159
*/
162-
public function setExample($example)
160+
public function setExample(string | array $example)
163161
{
164162
$this->setAttribute('example', $example);
165163
}
@@ -176,19 +174,14 @@ public function getExample()
176174

177175
/**
178176
* Adds an equivalent value.
179-
*
180-
* @param mixed $originalValue
181-
* @param mixed $equivalentValue
182177
*/
183-
public function addEquivalentValue($originalValue, $equivalentValue)
178+
public function addEquivalentValue(mixed $originalValue, mixed $equivalentValue)
184179
{
185180
$this->equivalentValues[] = [$originalValue, $equivalentValue];
186181
}
187182

188183
/**
189184
* Set this node as required.
190-
*
191-
* @param bool $boolean Required node
192185
*/
193186
public function setRequired(bool $boolean)
194187
{
@@ -296,7 +289,7 @@ public function getPath()
296289
/**
297290
* {@inheritdoc}
298291
*/
299-
final public function merge($leftSide, $rightSide)
292+
final public function merge(mixed $leftSide, mixed $rightSide)
300293
{
301294
if (!$this->allowOverwrite) {
302295
throw new ForbiddenOverwriteException(sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
@@ -337,7 +330,7 @@ final public function merge($leftSide, $rightSide)
337330
/**
338331
* {@inheritdoc}
339332
*/
340-
final public function normalize($value)
333+
final public function normalize(mixed $value)
341334
{
342335
$value = $this->preNormalize($value);
343336

@@ -377,11 +370,9 @@ final public function normalize($value)
377370
/**
378371
* Normalizes the value before any other normalization is applied.
379372
*
380-
* @param mixed $value
381-
*
382373
* @return mixed The normalized array value
383374
*/
384-
protected function preNormalize($value)
375+
protected function preNormalize(mixed $value)
385376
{
386377
return $value;
387378
}
@@ -399,7 +390,7 @@ public function getParent()
399390
/**
400391
* {@inheritdoc}
401392
*/
402-
final public function finalize($value)
393+
final public function finalize(mixed $value)
403394
{
404395
if ($value !== $placeholders = self::resolvePlaceholderValue($value)) {
405396
foreach ($placeholders as $placeholder) {
@@ -440,39 +431,30 @@ final public function finalize($value)
440431
/**
441432
* Validates the type of a Node.
442433
*
443-
* @param mixed $value The value to validate
444-
*
445434
* @throws InvalidTypeException when the value is invalid
446435
*/
447-
abstract protected function validateType($value);
436+
abstract protected function validateType(mixed $value);
448437

449438
/**
450439
* Normalizes the value.
451440
*
452-
* @param mixed $value The value to normalize
453-
*
454441
* @return mixed The normalized value
455442
*/
456-
abstract protected function normalizeValue($value);
443+
abstract protected function normalizeValue(mixed $value);
457444

458445
/**
459446
* Merges two values together.
460447
*
461-
* @param mixed $leftSide
462-
* @param mixed $rightSide
463-
*
464448
* @return mixed The merged value
465449
*/
466-
abstract protected function mergeValues($leftSide, $rightSide);
450+
abstract protected function mergeValues(mixed $leftSide, mixed $rightSide);
467451

468452
/**
469453
* Finalizes a value.
470454
*
471-
* @param mixed $value The value to finalize
472-
*
473455
* @return mixed The finalized value
474456
*/
475-
abstract protected function finalizeValue($value);
457+
abstract protected function finalizeValue(mixed $value);
476458

477459
/**
478460
* Tests if placeholder values are allowed for this node.
@@ -498,7 +480,7 @@ protected function getValidPlaceholderTypes(): array
498480
return [];
499481
}
500482

501-
private static function resolvePlaceholderValue($value)
483+
private static function resolvePlaceholderValue(mixed $value)
502484
{
503485
if (\is_string($value)) {
504486
if (isset(self::$placeholders[$value])) {
@@ -515,7 +497,7 @@ private static function resolvePlaceholderValue($value)
515497
return $value;
516498
}
517499

518-
private function doValidateType($value): void
500+
private function doValidateType(mixed $value): void
519501
{
520502
if (null !== $this->handlingPlaceholder && !$this->allowPlaceholders()) {
521503
$e = new InvalidTypeException(sprintf('A dynamic value is not compatible with a "%s" node type at path "%s".', static::class, $this->getPath()));

src/Symfony/Component/Config/Definition/BooleanNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BooleanNode extends ScalarNode
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
protected function validateType($value)
26+
protected function validateType(mixed $value)
2727
{
2828
if (!\is_bool($value)) {
2929
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
@@ -39,7 +39,7 @@ protected function validateType($value)
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
protected function isValueEmpty($value)
42+
protected function isValueEmpty(mixed $value)
4343
{
4444
// a boolean value cannot be empty
4545
return false;

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ public function addDefaultsIfNotSet()
150150
*
151151
* This method is applicable to prototype nodes only.
152152
*
153-
* @param int|string|array|null $children The number of children|The child name|The children names to be added
153+
* @param int|array|string|null $children The number of children|The child name|The children names to b 97AE e added
154154
*
155155
* @return $this
156156
*/
157-
public function addDefaultChildrenIfNoneSet($children = null)
157+
public function addDefaultChildrenIfNoneSet(int | array | string | null $children = null)
158158
{
159159
$this->addDefaultChildren = $children;
160160

@@ -276,7 +276,7 @@ public function canBeEnabled()
276276
->treatNullLike(['enabled' => true])
277277
->beforeNormalization()
278278
->ifArray()
279-
->then(function ($v) {
279+
->then(function (array $v) {
280280
$v['enabled'] = $v['enabled'] ?? true;
281281

282282
return $v;

0 commit comments

Comments
 (0)
0