8000 minor #41630 [Config] Backport type declarations (derrabus) · symfony/symfony@510be7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 510be7a

Browse files
committed
minor #41630 [Config] Backport type declarations (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Config] Backport type declarations | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A This PR backports type declarations from #41575 where it's safe to do so. Commits ------- 46e18af [Config] Backport type declarations
2 parents 12f3e37 + 46e18af commit 510be7a

28 files changed

+144
-184
lines changed

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ public function addChild(NodeInterface $node)
203203
}
204204

205205
/**
206-
* Finalizes the value of this node.
207-
*
208-
* @param mixed $value
209-
*
210-
* @return mixed The finalised value
206+
* {@inheritdoc}
211207
*
212208
* @throws UnsetKeyException
213209
* @throws InvalidConfigurationException if the node doesn't have enough children
@@ -249,11 +245,7 @@ protected function finalizeValue($value)
249245
}
250246

251247
/**
252-
* Validates the type of the value.
253-
*
254-
* @param mixed $value
255-
*
256-
* @throws InvalidTypeException
248+
* {@inheritdoc}
257249
*/
258250
protected function validateType($value)
259251
{
@@ -269,11 +261,7 @@ protected function validateType($value)
269261
}
270262

271263
/**
272-
* Normalizes the value.
273-
*
274-
* @param mixed $value The value to normalize
275-
*
276-
* @return mixed The normalized value
264+
* {@inheritdoc}
277265
*
278266
* @throws InvalidConfigurationException
279267
*/
@@ -355,12 +343,7 @@ protected function remapXml($value)
355343
}
356344

357345
/**
358-
* Merges values together.
359-
*
360-
* @param mixed $leftSide The left side to merge
361-
* @param mixed $rightSide The right side to merge
362-
*
363-
* @return mixed The merged values
346+
* {@inheritdoc}
364347
*
365348
* @throws InvalidConfigurationException
366349
* @throws \RuntimeException

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function canBeEnabled()
280280
->treatNullLike(['enabled' => true])
281281
->beforeNormalization()
282282
->ifArray()
283-
->then(function ($v) {
283+
->then(function (array $v) {
284284
$v['enabled'] = $v['enabled'] ?? true;
285285

286286
return $v;

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

Copy file name to clipboard
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(NodeDefinition $node)
3737
*/
3838
public function always(\Closure $then = null)
3939
{
40-
$this->ifPart = function ($v) { return true; };
40+
$this->ifPart = function () { return true; };
4141

4242
if (null !== $then) {
4343
$this->thenPart = $then;
@@ -168,7 +168,7 @@ public function then(\Closure $closure)
168168
*/
169169
public function thenEmptyArray()
170170
{
171-
$this->thenPart = function ($v) { return []; };
171+
$this->thenPart = function () { return []; };
172172

173173
return $this;
174174
}
@@ -200,7 +200,7 @@ public function thenInvalid($message)
200200
*/
201201
public function thenUnset()
202202
{
203-
$this->thenPart = function ($v) { throw new UnsetKeyException('Unsetting key.'); };
203+
$this->thenPart = function () { throw new UnsetKeyException('Unsetting key.'); };
204204

205205
return $this;
206206
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
2626
/**
2727
* Ensures that the value is smaller than the given reference.
2828
*
29-
* @param mixed $max
29+
* @param int|float $max
3030
*
3131
* @return $this
3232
*
@@ -45,7 +45,7 @@ public function max($max)
4545
/**
4646
* Ensures that the value is bigger than the given reference.
4747
*
48-
* @param mixed $min
48+
* @param int|float $min
4949
*
5050
* @return $this
5151
*

src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function writeNode(NodeInterface $node, int $depth = 0, bool $root = fal
4949

5050
// xml remapping
5151
if ($node->getParent()) {
52-
$remapping = array_filter($node->getParent()->getXmlRemappings(), function ($mapping) use ($rootName) {
52+
$remapping = array_filter($node->getParent()->getXmlRemappings(), function (array $mapping) use ($rootName) {
5353
return $rootName === $mapping[1];
5454
});
5555

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function getValues()
3838
return $this->values;
3939
}
4040

41+
/**
42+
* {@inheritdoc}
43+
*/
4144
protected function finalizeValue($value)
4245
{
4346
$value = parent::finalizeValue($value);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class NumericNode extends ScalarNode
2323
protected $min;
2424
protected $max;
2525

26+
/**
27+
* @param int|float|null $min
28+
* @param int|float|null $max
29+
*/
2630
public function __construct(?string $name, NodeInterface $parent = null, $min = null, $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
2731
{
2832
parent::__construct($name, $parent, $pathSeparator);

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

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,7 @@ public function addChild(NodeInterface $node)
173173
}
174174

175175
/**
176-
* Finalizes the value of this node.
177-
*
178-
* @param mixed $value
179-
*
180-
* @return mixed The finalized value
181-
*
182-
* @throws UnsetKeyException
183-
* @throws InvalidConfigurationException if the node doesn't have enough children
176+
* {@inheritdoc}
184177
*/
185178
protected function finalizeValue($value)
186179
{
@@ -208,13 +201,8 @@ protected function finalizeValue($value)
208201
}
209202

210203
/**
211-
* Normalizes the value.
212-
*
213-
* @param mixed $value The value to normalize
214-
*
215-
* @return mixed The normalized value
204+
* {@inheritdoc}
216205
*
217-
* @throws InvalidConfigurationException
218206
* @throws DuplicateKeyException
219207
*/
220208
protected function normalizeValue($value)
@@ -282,15 +270,7 @@ protected function normalizeValue($value)
282270
}
283271

284272
/**
285-
* Merges values together.
286-
*
287-
* @param mixed $leftSide The left side to merge
288-
* @param mixed $rightSide The right side to merge
289-
*
290-
* @return mixed The merged values
291-
*
292-
* @throws InvalidConfigurationException
293-
* @throws \RuntimeException
273+
* {@inheritdoc}
294274
*/
295275
protected function mergeValues($leftSide, $rightSide)
296276
{

src/Symfony/Component/Config/Tests/ConfigCacheTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function tearDown(): void
3838
/**
3939
* @dataProvider debugModes
4040
*/
41-
public function testCacheIsNotValidIfNothingHasBeenCached($debug)
41+
public function testCacheIsNotValidIfNothingHasBeenCached(bool $debug)
4242
{
4343
unlink($this->cacheFile); // remove tempnam() side effect
4444
$cache = new ConfigCache($this->cacheFile, $debug);
@@ -60,7 +60,7 @@ public function testIsAlwaysFreshInProduction()
6060
/**
6161
* @dataProvider debugModes
6262
*/
63-
public function testIsFreshWhenNoResourceProvided($debug)
63+
public function testIsFreshWhenNoResourceProvided(bool $debug)
6464
{
6565
$cache = new ConfigCache($this->cacheFile, $debug);
6666
$cache->write('', []);
@@ -89,7 +89,7 @@ public function testStaleResourceInDebug()
8989
$this->assertFalse($cache->isFresh());
9090
}
9191

92-
public function debugModes()
92+
public function debugModes(): array
9393
{
9494
return [
9595
[true],

src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testNormalizeWithoutProposals()
5555
$node->normalize(['beta' => 'foo']);
5656
}
5757

58-
public function ignoreAndRemoveMatrixProvider()
58+
public function ignoreAndRemoveMatrixProvider(): array
5959
{
6060
$unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"');
6161

@@ -68,9 +68,11 @@ public function ignoreAndRemoveMatrixProvider()
6868
}
6969

7070
/**
71+
* @param array|\Exception $expected
72+
*
7173
* @dataProvider ignoreAndRemoveMatrixProvider
7274
*/
73-
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
75+
public function testIgnoreAndRemoveBehaviors(bool $ignore, bool $remove, $expected, string $message = '')
7476
{
7577
if ($expected instanceof \Exception) {
7678
$this->expectException(\get_class($expected));
@@ -85,7 +87,7 @@ public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $messa
8587
/**
8688
* @dataProvider getPreNormalizationTests
8789
*/
88-
public function testPreNormalize($denormalized, $normalized)
90+
public function testPreNormalize(array $denormalized, array $normalized)
8991
{
9092
$node = new ArrayNode('foo');
9193

@@ -95,7 +97,7 @@ public function testPreNormalize($denormalized, $normalized)
9597
$this->assertSame($normalized, $r->invoke($node, $denormalized));
9698
}
9799

98-
public function getPreNormalizationTests()
100+
public function getPreNormalizationTests(): array
99101
{
100102
return [
101103
[
@@ -120,7 +122,7 @@ public function getPreNormalizationTests()
120122
/**
121123
* @dataProvider getZeroNamedNodeExamplesData
122124
*/
123-
public function testNodeNameCanBeZero($denormalized, $normalized)
125+
public function testNodeNameCanBeZero(array $denormalized, array $normalized)
124126
{
125127
$zeroNode = new ArrayNode(0);
126128
$zeroNode->addChild(new ScalarNode('name'));
@@ -137,7 +139,7 @@ public function testNodeNameCanBeZero($denormalized, $normalized)
137139
$this->assertSame($normalized, $r->invoke($rootNode, $denormalized));
138140
}
139141

140-
public function getZeroNamedNodeExamplesData()
142+
public function getZeroNamedNodeExamplesData(): array
141143
{
142144
return [
143145
[
@@ -168,7 +170,7 @@ public function getZeroNamedNodeExamplesData()
168170
/**
169171
* @dataProvider getPreNormalizedNormalizedOrderedData
170172
*/
171-
public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $normalized)
173+
public function testChildrenOrderIsMaintainedOnNormalizeValue(array $prenormalized, array $normalized)
172174
{
173175
$scalar1 = new ScalarNode('1');
174176
$scalar2 = new ScalarNode('2');
@@ -184,7 +186,7 @@ public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $n
184186
$this->assertSame($normalized, $r->invoke($node, $prenormalized));
185187
}
186188

187-
public function getPreNormalizedNormalizedOrderedData()
189+
public function getPreNormalizedNormalizedOrderedData(): array
188190
{
189191
return [
190192
[
@@ -260,7 +262,7 @@ public function testSetDeprecated()
260262
/**
261263
* @dataProvider getDataWithIncludedExtraKeys
262264
*/
263-
public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged)
265+
public function testMergeWithoutIgnoringExtraKeys(array $prenormalizeds)
264266
{
265267
$this->expectException(\RuntimeException::class);
266268
$this->expectExceptionMessage('merge() expects a normalized config array.');
@@ -278,7 +280,7 @@ public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged)
278280
/**
279281
* @dataProvider getDataWithIncludedExtraKeys
280282
*/
281-
public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merged)
283+
public function testMergeWithIgnoringAndRemovingExtraKeys(array $prenormalizeds)
282284
{
283285
$this->expectException(\RuntimeException::class);
284286
$this->expectExceptionMessage('merge() expects a normalized config array.');
@@ -296,7 +298,7 @@ public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merg
296298
/**
297299
* @dataProvider getDataWithIncludedExtraKeys
298300
*/
299-
public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged)
301+
public function testMergeWithIgnoringExtraKeys(array $prenormalizeds, array $merged)
300302
{
301303
$node = new ArrayNode('root');
302304
$node->addChild(new ScalarNode('foo'));
@@ -309,7 +311,7 @@ public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged)
309311
$this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds));
310312
}
311313

312-
public function getDataWithIncludedExtraKeys()
314+
public function getDataWithIncludedExtraKeys(): array
313315
{
314316
return [
315317
[

src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BaseNodeTest extends TestCase
2020
/**
2121
* @dataProvider providePath
2222
*/
23-
public function testGetPathForChildNode($expected, array $params)
23+
public function testGetPathForChildNode(string $expected, array $params)
2424
{
2525
$constructorArgs = [];
2626
$constructorArgs[] = $params[0];
@@ -41,7 +41,7 @@ public function testGetPathForChildNode($expected, array $params)
4141
$this->assertSame($expected, $node->getPath());
4242
}
4343

44< F438 /td>-
public function providePath()
44+
public function providePath(): array
4545
{
4646
return [
4747
'name only' => ['root', ['root']],

src/Symfony/Component/Config/Tests/Definition/BooleanNodeTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,24 @@ class BooleanNodeTest extends TestCase
2020
/**
2121
* @dataProvider getValidValues
2222
*/
23-
public function testNormalize($value)
23+
public function testNormalize(bool $value)
2424
{
2525
$node = new BooleanNode('test');
2626
$this->assertSame($value, $node->normalize($value));
2727
}
2828

2929
/**
3030
* @dataProvider getValidValues
31-
*
32-
* @param bool $value
3331
*/
34-
public function testValidNonEmptyValues($value)
32+
public function testValidNonEmptyValues(bool $value)
3533
{
3634
$node = new BooleanNode('test');
3735
$node->setAllowEmptyValue(false);
3836

3937
$this->assertSame($value, $node->finalize($value));
4038
}
4139

42-
public function getValidValues()
40+
public function getValidValues(): array
4341
{
4442
return [
4543
[false],
@@ -57,7 +55,7 @@ public function testNormalizeThrowsExceptionOnInvalidValues($value)
5755
$node->normalize($value);
5856
}
5957

60-
public 4DBB function getInvalidValues()
58+
public function getInvalidValues(): array
6159
{
6260
return [
6361
[null],

0 commit comments

Comments
 (0)
0