Skip to content

[Config] Backport type declarations #41630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,7 @@ public function addChild(NodeInterface $node)
}

/**
* Finalizes the value of this node.
*
* @param mixed $value
*
* @return mixed The finalised value
* {@inheritdoc}
*
* @throws UnsetKeyException
* @throws InvalidConfigurationException if the node doesn't have enough children
Expand Down Expand Up @@ -249,11 +245,7 @@ protected function finalizeValue($value)
}

/**
* Validates the type of the value.
*
* @param mixed $value
*
* @throws InvalidTypeException
* {@inheritdoc}
*/
protected function validateType($value)
{
Expand All @@ -269,11 +261,7 @@ protected function validateType($value)
}

/**
* Normalizes the value.
*
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
* {@inheritdoc}
*
* @throws InvalidConfigurationException
*/
Expand Down Expand Up @@ -355,12 +343,7 @@ protected function remapXml($value)
}

/**
* Merges values together.
*
* @param mixed $leftSide The left side to merge
* @param mixed $rightSide The right side to merge
*
* @return mixed The merged values
* {@inheritdoc}
*
* @throws InvalidConfigurationException
* @throws \RuntimeException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function canBeEnabled()
->treatNullLike(['enabled' => true])
->beforeNormalization()
->ifArray()
->then(function ($v) {
->then(function (array $v) {
$v['enabled'] = $v['enabled'] ?? true;

return $v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(NodeDefinition $node)
*/
public function always(\Closure $then = null)
{
$this->ifPart = function ($v) { return true; };
$this->ifPart = function () { return true; };

if (null !== $then) {
$this->thenPart = $then;
Expand Down Expand Up @@ -168,7 +168,7 @@ public function then(\Closure $closure)
*/
public function thenEmptyArray()
{
$this->thenPart = function ($v) { return []; };
$this->thenPart = function () { return []; };

return $this;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ public function thenInvalid($message)
*/
public function thenUnset()
{
$this->thenPart = function ($v) { throw new UnsetKeyException('Unsetting key.'); };
$this->thenPart = function () { throw new UnsetKeyException('Unsetting key.'); };

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
/**
* Ensures that the value is smaller than the given reference.
*
* @param mixed $max
* @param int|float $max
*
* @return $this
*
Expand All @@ -45,7 +45,7 @@ public function max($max)
/**
* Ensures that the value is bigger than the given reference.
*
* @param mixed $min
* @param int|float $min
*
* @return $this
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function writeNode(NodeInterface $node, int $depth = 0, bool $root = fal

// xml remapping
if ($node->getParent()) {
$remapping = array_filter($node->getParent()->getXmlRemappings(), function ($mapping) use ($rootName) {
$remapping = array_filter($node->getParent()->getXmlRemappings(), function (array $mapping) use ($rootName) {
return $rootName === $mapping[1];
});

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Config/Definition/EnumNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function getValues()
return $this->values;
}

/**
* {@inheritdoc}
*/
protected function finalizeValue($value)
{
$value = parent::finalizeValue($value);
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Config/Definition/NumericNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class NumericNode extends ScalarNode
protected $min;
protected $max;

/**
* @param int|float|null $min
* @param int|float|null $max
*/
public function __construct(?string $name, NodeInterface $parent = null, $min = null, $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
{
parent::__construct($name, $parent, $pathSeparator);
Expand Down
26 changes: 3 additions & 23 deletions src/Symfony/Component/Config/Definition/PrototypedArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,7 @@ public function addChild(NodeInterface $node)
}

/**
* Finalizes the value of this node.
*
* @param mixed $value
*
* @return mixed The finalized value
*
* @throws UnsetKeyException
* @throws InvalidConfigurationException if the node doesn't have enough children
* {@inheritdoc}
*/
protected function finalizeValue($value)
{
Expand Down Expand Up @@ -208,13 +201,8 @@ protected function finalizeValue($value)
}

/**
* Normalizes the value.
*
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
* {@inheritdoc}
*
* @throws InvalidConfigurationException
* @throws DuplicateKeyException
*/
protected function normalizeValue($value)
Expand Down Expand Up @@ -282,15 +270,7 @@ protected function normalizeValue($value)
}

/**
* Merges values together.
*
* @param mixed $leftSide The left side to merge
* @param mixed $rightSide The right side to merge
*
* @return mixed The merged values
*
* @throws InvalidConfigurationException
* @throws \RuntimeException
* {@inheritdoc}
*/
protected function mergeValues($leftSide, $rightSide)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Tests/ConfigCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function tearDown(): void
/**
* @dataProvider debugModes
*/
public function testCacheIsNotValidIfNothingHasBeenCached($debug)
public function testCacheIsNotValidIfNothingHasBeenCached(bool $debug)
{
unlink($this->cacheFile); // remove tempnam() side effect
$cache = new ConfigCache($this->cacheFile, $debug);
Expand All @@ -60,7 +60,7 @@ public function testIsAlwaysFreshInProduction()
/**
* @dataProvider debugModes
*/
public function testIsFreshWhenNoResourceProvided($debug)
public function testIsFreshWhenNoResourceProvided(bool $debug)
{
$cache = new ConfigCache($this->cacheFile, $debug);
$cache->write('', []);
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testStaleResourceInDebug()
$this->assertFalse($cache->isFresh());
}

public function debugModes()
public function debugModes(): array
{
return [
[true],
Expand Down
26 changes: 14 additions & 12 deletions src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testNormalizeWithoutProposals()
$node->normalize(['beta' => 'foo']);
}

public function ignoreAndRemoveMatrixProvider()
public function ignoreAndRemoveMatrixProvider(): array
{
$unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"');

Expand All @@ -68,9 +68,11 @@ public function ignoreAndRemoveMatrixProvider()
}

/**
* @param array|\Exception $expected
*
* @dataProvider ignoreAndRemoveMatrixProvider
*/
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
public function testIgnoreAndRemoveBehaviors(bool $ignore, bool $remove, $expected, string $message = '')
{
if ($expected instanceof \Exception) {
$this->expectException(\get_class($expected));
Expand All @@ -85,7 +87,7 @@ public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $messa
/**
* @dataProvider getPreNormalizationTests
*/
public function testPreNormalize($denormalized, $normalized)
public function testPreNormalize(array $denormalized, array $normalized)
{
$node = new ArrayNode('foo');

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

public function getPreNormalizationTests()
public function getPreNormalizationTests(): array
{
return [
[
Expand All @@ -120,7 +122,7 @@ public function getPreNormalizationTests()
/**
* @dataProvider getZeroNamedNodeExamplesData
*/
public function testNodeNameCanBeZero($denormalized, $normalized)
public function testNodeNameCanBeZero(array $denormalized, array $normalized)
{
$zeroNode = new ArrayNode(0);
$zeroNode->addChild(new ScalarNode('name'));
Expand All @@ -137,7 +139,7 @@ public function testNodeNameCanBeZero($denormalized, $normalized)
$this->assertSame($normalized, $r->invoke($rootNode, $denormalized));
}

public function getZeroNamedNodeExamplesData()
public function getZeroNamedNodeExamplesData(): array
{
return [
[
Expand Down Expand Up @@ -168,7 +170,7 @@ public function getZeroNamedNodeExamplesData()
/**
* @dataProvider getPreNormalizedNormalizedOrderedData
*/
public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $normalized)
public function testChildrenOrderIsMaintainedOnNormalizeValue(array $prenormalized, array $normalized)
{
$scalar1 = new ScalarNode('1');
$scalar2 = new ScalarNode('2');
Expand All @@ -184,7 +186,7 @@ public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $n
$this->assertSame($normalized, $r->invoke($node, $prenormalized));
}

public function getPreNormalizedNormalizedOrderedData()
public function getPreNormalizedNormalizedOrderedData(): array
{
return [
[
Expand Down Expand Up @@ -260,7 +262,7 @@ public function testSetDeprecated()
/**
* @dataProvider getDataWithIncludedExtraKeys
*/
public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged)
public function testMergeWithoutIgnoringExtraKeys(array $prenormalizeds)
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('merge() expects a normalized config array.');
Expand All @@ -278,7 +280,7 @@ public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged)
/**
* @dataProvider getDataWithIncludedExtraKeys
*/
public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merged)
public function testMergeWithIgnoringAndRemovingExtraKeys(array $prenormalizeds)
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('merge() expects a normalized config array.');
Expand All @@ -296,7 +298,7 @@ public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merg
/**
* @dataProvider getDataWithIncludedExtraKeys
*/
public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged)
public function testMergeWithIgnoringExtraKeys(array $prenormalizeds, array $merged)
{
$node = new ArrayNode('root');
$node->addChild(new ScalarNode('foo'));
Expand All @@ -309,7 +311,7 @@ public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged)
$this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds));
}

public function getDataWithIncludedExtraKeys()
public function getDataWithIncludedExtraKeys(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BaseNodeTest extends TestCase
/**
* @dataProvider providePath
*/
public function testGetPathForChildNode($expected, array $params)
public function testGetPathForChildNode(string $expected, array $params)
{
$constructorArgs = [];
$constructorArgs[] = $params[0];
Expand All @@ -41,7 +41,7 @@ public function testGetPathForChildNode($expected, array $params)
$this->assertSame($expected, $node->getPath());
}

public function providePath()
public function providePath(): array
{
return [
'name only' => ['root', ['root']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,24 @@ class BooleanNodeTest extends TestCase
/**
* @dataProvider getValidValues
*/
public function testNormalize($value)
public function testNormalize(bool $value)
{
$node = new BooleanNode('test');
$this->assertSame($value, $node->normalize($value));
}

/**
* @dataProvider getValidValues
*
* @param bool $value
*/
public function testValidNonEmptyValues($value)
public function testValidNonEmptyValues(bool $value)
{
$node = new BooleanNode('test');
$node->setAllowEmptyValue(false);

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

public function getValidValues()
public function getValidValues(): array
{
return [
[false],
Expand All @@ -57,7 +55,7 @@ public function testNormalizeThrowsExceptionOnInvalidValues($value)
$node->normalize($value);
}

public function getInvalidValues()
public function getInvalidValues(): array
{
return [
[null],
Expand Down
Loading