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

Skip to content

Commit 9fada46

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

Some content is hidden

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

60 files changed

+143
-225
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: 7 additions & 7 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;
@@ -200,7 +200,7 @@ public function addChild(NodeInterface $node)
200200
* @throws UnsetKeyException
201201
* @throws InvalidConfigurationException if the node doesn't have enough children
202202
*/
203-
protected function finalizeValue($value)
203+
protected function finalizeValue(mixed $value)
204204
{
205205
if (false === $value) {
206206
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
@@ -246,7 +246,7 @@ protected function finalizeValue($value)
246246
/**
247247
* {@inheritdoc}
248248
*/
249-
protected function validateType($value)
249+
protected function validateType(mixed $value)
250250
{
251251
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
252252
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
@@ -264,7 +264,7 @@ protected function validateType($value)
264264
*
265265
* @throws InvalidConfigurationException
266266
*/
267-
protected function normalizeValue($value)
267+
protected function normalizeValue(mixed $value)
268268
{
269269
if (false === $value) {
270270
return $value;
@@ -345,7 +345,7 @@ protected function remapXml(array $value)
345345
* @throws InvalidConfigurationException
346346
* @throws \RuntimeException
347347
*/
348-
protected function mergeValues($leftSide, $rightSide)
348+
protected function mergeValues(mixed $leftSide, mixed $rightSide)
349349
{
350350
if (false === $rightSide) {
351351
// 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function addDefaultsIfNotSet()
154154
*
155155
* @return $this
156156
*/
157-
public function addDefaultChildrenIfNoneSet($children = null)
157+
public function addDefaultChildrenIfNoneSet(int|string|array|null $children = null)
158158
{
159159
$this->addDefaultChildren = $children;
160160

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function always(\Closure $then = null)
5656
public function ifTrue(\Closure $closure = null)
5757
{
5858
if (null === $closure) {
59-
$closure = function ($v) { return true === $v; };
59+
$closure = function (mixed $v) { return true === $v; };
6060
}
6161

6262
$this->ifPart = $closure;
@@ -71,7 +71,7 @@ public function ifTrue(\Closure $closure = null)
7171
*/
7272
public function ifString()
7373
{
74-
$this->ifPart = function ($v) { return \is_string($v); };
74+
$this->ifPart = function (mixed $v) { return \is_string($v); };
7575

7676
return $this;
7777
}
@@ -83,7 +83,7 @@ public function ifString()
8383
*/
8484
public function ifNull()
8585
{
86-
$this->ifPart = function ($v) { return null === $v; };
86+
$this->ifPart = function (mixed $v) { return null === $v; };
8787

8888
return $this;
8989
}
@@ -95,7 +95,7 @@ public function ifNull()
9595
*/
9696
public function ifEmpty()
9797
{
98-
$this->ifPart = function ($v) { return empty($v); };
98+
$this->ifPart = function (mixed $v) { return empty($v); };
9999

100100
return $this;
101101
}
@@ -107,7 +107,7 @@ public function ifEmpty()
107107
*/
108108
public function ifArray()
109109
{
110-
$this->ifPart = function ($v) { return \is_array($v); };
110+
$this->ifPart = function (mixed $v) { return \is_array($v); };
111111

112112
return $this;
113113
}
@@ -119,7 +119,7 @@ public function ifArray()
119119
*/
120120
public function ifInArray(array $array)
121121
{
122-
$this->ifPart = function ($v) use ($array) { return \in_array($v, $array, true); };
122+
$this->ifPart = function (mixed $v) use ($array) { return \in_array($v, $array, true); };
123123

124124
return $this;
125125
}
@@ -131,7 +131,7 @@ public function ifInArray(array $array)
131131
*/
132132
public function ifNotInArray(array $array)
133133
{
134-
$this->ifPart = function ($v) use ($array) { return !\in_array($v, $array, true); };
134+
$this->ifPart = function (mixed $v) use ($array) { return !\in_array($v, $array, true FA33 ); };
135135

136136
return $this;
137137
}
@@ -143,8 +143,8 @@ public function ifNotInArray(array $array)
143143
*/
144144
public function castToArray()
145145
{
146-
$this->ifPart = function ($v) { return !\is_array($v); };
147-
$this->thenPart = function ($v) { return [$v]; };
146+
$this->ifPart = function (mixed $v) { return !\is_array($v); };
147+
$this->thenPart = function (mixed $v) { return [$v]; };
148148

149149
return $this;
150150
}
@@ -184,7 +184,7 @@ public function thenEmptyArray()
184184
*/
185185
public function thenInvalid(string $message)
186186
{
187-
$this->thenPart = function ($v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };
187+
$this->thenPart = function (mixed $v) use ($message) { throw new \InvalidArgumentException(sprintf($message, json_encode($v))); };
188188

189189
return $this;
190190
}
@@ -235,7 +235,7 @@ public static function buildExpressions(array $expressions)
235235
if ($expr instanceof self) {
236236
$if = $expr->ifPart;
237237
$then = $expr->thenPart;
238-
$expressions[$k] = function ($v) use ($if, $then) {
238+
$expressions[$k] = function (mixed $v) use ($if, $then) {
239239
return $if($v) ? $then($v) : $v;
240240
};
241241
}

0 commit comments

Comments
 (0)
0