diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 96f38dcc92..c3c837a412 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -203,11 +203,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface } /** - * 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 @@ -249,11 +245,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface } /** - * Validates the type of the value. - * - * @param mixed $value - * - * @throws InvalidTypeException + * {@inheritdoc} */ protected function validateType($value) { @@ -269,11 +261,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface } /** - * Normalizes the value. - * - * @param mixed $value The value to normalize - * - * @return mixed The normalized value + * {@inheritdoc} * * @throws InvalidConfigurationException */ @@ -355,12 +343,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface } /** - * 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 diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index bec08b0db6..61348387be 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -280,7 +280,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition ->treatNullLike(['enabled' => true]) ->beforeNormalization() ->ifArray() - ->then(function ($v) { + ->then(function (array $v) { $v['enabled'] = $v['enabled'] ?? true; return $v; diff --git a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php index 5db229dcca..0cf47c162c 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php @@ -37,7 +37,7 @@ class ExprBuilder */ public function always(\Closure $then = null) { - $this->ifPart = function ($v) { return true; }; + $this->ifPart = function () { return true; }; if (null !== $then) { $this->thenPart = $then; @@ -168,7 +168,7 @@ class ExprBuilder */ public function thenEmptyArray() { - $this->thenPart = function ($v) { return []; }; + $this->thenPart = function () { return []; }; return $this; } @@ -200,7 +200,7 @@ class ExprBuilder */ public function thenUnset() { - $this->thenPart = function ($v) { throw new UnsetKeyException('Unsetting key.'); }; + $this->thenPart = function () { throw new UnsetKeyException('Unsetting key.'); }; return $this; } diff --git a/src/Symfony/Component/Config/Definition/Builder/NumericNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/NumericNodeDefinition.php index 390b113656..c4bff1756f 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NumericNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/NumericNodeDefinition.php @@ -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 * @@ -45,7 +45,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition /** * Ensures that the value is bigger than the given reference. * - * @param mixed $min + * @param int|float $min * * @return $this * diff --git a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php index 29e4076f97..a6b6240c77 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php @@ -49,7 +49,7 @@ class XmlReferenceDumper // 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]; }); diff --git a/src/Symfony/Component/Config/Definition/EnumNode.php b/src/Symfony/Component/Config/Definition/EnumNode.php index 23fc508a78..822e6b57f1 100644 --- a/src/Symfony/Component/Config/Definition/EnumNode.php +++ b/src/Symfony/Component/Config/Definition/EnumNode.php @@ -38,6 +38,9 @@ class EnumNode extends ScalarNode return $this->values; } + /** + * {@inheritdoc} + */ protected function finalizeValue($value) { $value = parent::finalizeValue($value); diff --git a/src/Symfony/Component/Config/Definition/NumericNode.php b/src/Symfony/Component/Config/Definition/NumericNode.php index 19c96e8af7..50d137c2d7 100644 --- a/src/Symfony/Component/Config/Definition/NumericNode.php +++ b/src/Symfony/Component/Config/Definition/NumericNode.php @@ -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); diff --git a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php index 72d3578be7..0382223677 100644 --- a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php +++ b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php @@ -173,14 +173,7 @@ class PrototypedArrayNode extends ArrayNode } /** - * 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) { @@ -208,13 +201,8 @@ class PrototypedArrayNode extends ArrayNode } /** - * Normalizes the value. + * {@inheritdoc} * - * @param mixed $value The value to normalize - * - * @return mixed The normalized value - * - * @throws InvalidConfigurationException * @throws DuplicateKeyException */ protected function normalizeValue($value) @@ -282,15 +270,7 @@ class PrototypedArrayNode extends ArrayNode } /** - * 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) { diff --git a/src/Symfony/Component/Config/Tests/ConfigCacheTest.php b/src/Symfony/Component/Config/Tests/ConfigCacheTest.php index cfb2403a82..ff72302a46 100644 --- a/src/Symfony/Component/Config/Tests/ConfigCacheTest.php +++ b/src/Symfony/Component/Config/Tests/ConfigCacheTest.php @@ -38,7 +38,7 @@ class ConfigCacheTest extends TestCase /** * @dataProvider debugModes */ - public function testCacheIsNotValidIfNothingHasBeenCached($debug) + public function testCacheIsNotValidIfNothingHasBeenCached(bool $debug) { unlink($this->cacheFile); // remove tempnam() side effect $cache = new ConfigCache($this->cacheFile, $debug); @@ -60,7 +60,7 @@ class ConfigCacheTest extends TestCase /** * @dataProvider debugModes */ - public function testIsFreshWhenNoResourceProvided($debug) + public function testIsFreshWhenNoResourceProvided(bool $debug) { $cache = new ConfigCache($this->cacheFile, $debug); $cache->write('', []); @@ -89,7 +89,7 @@ class ConfigCacheTest extends TestCase $this->assertFalse($cache->isFresh()); } - public function debugModes() + public function debugModes(): array { return [ [true], diff --git a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php index 54a966f177..95f8480316 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php @@ -55,7 +55,7 @@ class ArrayNodeTest extends TestCase $node->normalize(['beta' => 'foo']); } - public function ignoreAndRemoveMatrixProvider() + public function ignoreAndRemoveMatrixProvider(): array { $unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"'); @@ -68,9 +68,11 @@ class ArrayNodeTest extends TestCase } /** + * @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)); @@ -85,7 +87,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getPreNormalizationTests */ - public function testPreNormalize($denormalized, $normalized) + public function testPreNormalize(array $denormalized, array $normalized) { $node = new ArrayNode('foo'); @@ -95,7 +97,7 @@ class ArrayNodeTest extends TestCase $this->assertSame($normalized, $r->invoke($node, $denormalized)); } - public function getPreNormalizationTests() + public function getPreNormalizationTests(): array { return [ [ @@ -120,7 +122,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getZeroNamedNodeExamplesData */ - public function testNodeNameCanBeZero($denormalized, $normalized) + public function testNodeNameCanBeZero(array $denormalized, array $normalized) { $zeroNode = new ArrayNode(0); $zeroNode->addChild(new ScalarNode('name')); @@ -137,7 +139,7 @@ class ArrayNodeTest extends TestCase $this->assertSame($normalized, $r->invoke($rootNode, $denormalized)); } - public function getZeroNamedNodeExamplesData() + public function getZeroNamedNodeExamplesData(): array { return [ [ @@ -168,7 +170,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getPreNormalizedNormalizedOrderedData */ - public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $normalized) + public function testChildrenOrderIsMaintainedOnNormalizeValue(array $prenormalized, array $normalized) { $scalar1 = new ScalarNode('1'); $scalar2 = new ScalarNode('2'); @@ -184,7 +186,7 @@ class ArrayNodeTest extends TestCase $this->assertSame($normalized, $r->invoke($node, $prenormalized)); } - public function getPreNormalizedNormalizedOrderedData() + public function getPreNormalizedNormalizedOrderedData(): array { return [ [ @@ -260,7 +262,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getDataWithIncludedExtraKeys */ - public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged) + public function testMergeWithoutIgnoringExtraKeys(array $prenormalizeds) { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('merge() expects a normalized config array.'); @@ -278,7 +280,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getDataWithIncludedExtraKeys */ - public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merged) + public function testMergeWithIgnoringAndRemovingExtraKeys(array $prenormalizeds) { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('merge() expects a normalized config array.'); @@ -296,7 +298,7 @@ class ArrayNodeTest extends TestCase /** * @dataProvider getDataWithIncludedExtraKeys */ - public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged) + public function testMergeWithIgnoringExtraKeys(array $prenormalizeds, array $merged) { $node = new ArrayNode('root'); $node->addChild(new ScalarNode('foo')); @@ -309,7 +311,7 @@ class ArrayNodeTest extends TestCase $this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds)); } - public function getDataWithIncludedExtraKeys() + public function getDataWithIncludedExtraKeys(): array { return [ [ diff --git a/src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php index ea2ed639ff..afe3cdf691 100644 --- a/src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/BaseNodeTest.php @@ -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]; @@ -41,7 +41,7 @@ class BaseNodeTest extends TestCase $this->assertSame($expected, $node->getPath()); } - public function providePath() + public function providePath(): array { return [ 'name only' => ['root', ['root']], diff --git a/src/Symfony/Component/Config/Tests/Definition/BooleanNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/BooleanNodeTest.php index 3a05e3efd8..bec3b5996d 100644 --- a/src/Symfony/Component/Config/Tests/Definition/BooleanNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/BooleanNodeTest.php @@ -20,7 +20,7 @@ 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)); @@ -28,10 +28,8 @@ class BooleanNodeTest extends TestCase /** * @dataProvider getValidValues - * - * @param bool $value */ - public function testValidNonEmptyValues($value) + public function testValidNonEmptyValues(bool $value) { $node = new BooleanNode('test'); $node->setAllowEmptyValue(false); @@ -39,7 +37,7 @@ class BooleanNodeTest extends TestCase $this->assertSame($value, $node->finalize($value)); } - public function getValidValues() + public function getValidValues(): array { return [ [false], @@ -57,7 +55,7 @@ class BooleanNodeTest extends TestCase $node->normalize($value); } - public function getInvalidValues() + public function getInvalidValues(): array { return [ [null], diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index 0e489ac910..0f111826d3 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -42,7 +42,7 @@ class ArrayNodeDefinitionTest extends TestCase /** * @dataProvider providePrototypeNodeSpecificCalls */ - public function testPrototypeNodeSpecificOption($method, $args) + public function testPrototypeNodeSpecificOption(string $method, array $args) { $this->expectException(InvalidDefinitionException::class); $node = new ArrayNodeDefinition('root'); @@ -52,7 +52,7 @@ class ArrayNodeDefinitionTest extends TestCase $node->getNode(); } - public function providePrototypeNodeSpecificCalls() + public function providePrototypeNodeSpecificCalls(): array { return [ ['defaultValue', [[]]], @@ -98,9 +98,11 @@ class ArrayNodeDefinitionTest extends TestCase } /** + * @param int|array|string|null $args + * * @dataProvider providePrototypedArrayNodeDefaults */ - public function testPrototypedArrayNodeDefault($args, $shouldThrowWhenUsingAttrAsKey, $shouldThrowWhenNotUsingAttrAsKey, $defaults) + public function testPrototypedArrayNodeDefault($args, bool $shouldThrowWhenUsingAttrAsKey, bool $shouldThrowWhenNotUsingAttrAsKey, array $defaults) { $node = new ArrayNodeDefinition('root'); $node @@ -132,7 +134,7 @@ class ArrayNodeDefinitionTest extends TestCase } } - public function providePrototypedArrayNodeDefaults() + public function providePrototypedArrayNodeDefaults(): array { return [ [null, true, false, [[]]], @@ -173,7 +175,7 @@ class ArrayNodeDefinitionTest extends TestCase /** * @dataProvider getEnableableNodeFixtures */ - public function testTrueEnableEnabledNode($expected, $config, $message) + public function testTrueEnableEnabledNode(array $expected, array $config, string $message) { $processor = new Processor(); $node = new ArrayNodeDefinition('root'); @@ -293,7 +295,7 @@ class ArrayNodeDefinitionTest extends TestCase $this->assertEquals($node->prototype('enum'), $node->enumPrototype()); } - public function getEnableableNodeFixtures() + public function getEnableableNodeFixtures(): array { return [ [['enabled' => true, 'foo' => 'bar'], [true], 'true enables an enableable node'], @@ -432,7 +434,10 @@ class ArrayNodeDefinitionTest extends TestCase $this->assertSame($expectedName, $this->getField($actualNode, 'name')); } - protected function getField($object, $field) + /** + * @param object $object + */ + protected function getField($object, string $field) { $reflection = new \ReflectionProperty($object, $field); $reflection->setAccessible(true); diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php index c634f08877..74ae972e54 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Config\Tests\Definition\Builder; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\ExprBuilder; +use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; @@ -36,13 +37,13 @@ class ExprBuilderTest extends TestCase $this->assertFinalizedValueIs('new_value', $test, ['key' => true]); $test = $this->getTestBuilder() - ->ifTrue(function ($v) { return true; }) + ->ifTrue(function () { return true; }) ->then($this->returnClosure('new_value')) ->end(); $this->assertFinalizedValueIs('new_value', $test); $test = $this->getTestBuilder() - ->ifTrue(function ($v) { return false; }) + ->ifTrue(function () { return false; }) ->then($this->returnClosure('new_value')) ->end(); $this->assertFinalizedValueIs('value', $test); @@ -150,7 +151,7 @@ class ExprBuilderTest extends TestCase /** * @dataProvider castToArrayValues */ - public function testCastToArrayExpression($configValue, $expectedValue) + public function testCastToArrayExpression($configValue, array $expectedValue) { $test = $this->getTestBuilder() ->castToArray() @@ -158,7 +159,7 @@ class ExprBuilderTest extends TestCase $this->assertFinalizedValueIs($expectedValue, $test, ['key' => $configValue]); } - public function castToArrayValues() + public function castToArrayValues(): iterable { yield ['value', ['value']]; yield [-3.14, [-3.14]]; @@ -219,20 +220,19 @@ class ExprBuilderTest extends TestCase /** * Close the validation process and finalize with the given config. * - * @param TreeBuilder $testBuilder The tree builder to finalize - * @param array $config The config you want to use for the finalization, if nothing provided - * a simple ['key'=>'value'] will be used + * @param array|null $config The config you want to use for the finalization, if nothing provided + * a simple ['key'=>'value'] will be used * * @return array The finalized config values */ - protected function finalizeTestBuilder($testBuilder, $config = null): array + protected function finalizeTestBuilder(NodeDefinition $nodeDefinition, ?array $config = null): array { - return $testBuilder + return $nodeDefinition ->end() ->end() ->end() ->buildTree() - ->finalize(null === $config ? ['key' => 'value'] : $config) + ->finalize($config ?? ['key' => 'value']) ; } @@ -243,7 +243,7 @@ class ExprBuilderTest extends TestCase */ protected function returnClosure($val): \Closure { - return function ($v) use ($val) { + return function () use ($val) { return $val; }; } @@ -251,12 +251,11 @@ class ExprBuilderTest extends TestCase /** * Assert that the given test builder, will return the given value. * - * @param mixed $value The value to test - * @param TreeBuilder $treeBuilder The tree builder to finalize - * @param mixed $config The config values that new to be finalized + * @param mixed $value The value to test + * @param mixed $config The config values that new to be finalized */ - protected function assertFinalizedValueIs($value, $treeBuilder, $config = null) + protected function assertFinalizedValueIs($value, NodeDefinition $nodeDefinition, $config = null) { - $this->assertEquals(['key' => $value], $this->finalizeTestBuilder($treeBuilder, $config)); + $this->assertEquals(['key' => $value], $this->finalizeTestBuilder($nodeDefinition, $config)); } } diff --git a/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php b/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php index 146917aaa7..f1871d4972 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php @@ -26,7 +26,7 @@ class YamlReferenceDumperTest extends TestCase $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration)); } - public function provideDumpAtPath() + public function provideDumpAtPath(): array { return [ 'Regular node' => ['scalar_true', <<assertSame(trim($expected), trim($dumper->dumpAtPath($configuration, $path))); } - private function getConfigurationAsString() + private function getConfigurationAsString(): string { return <<<'EOL' acme_root: diff --git a/src/Symfony/Component/Config/Tests/Definition/FloatNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/FloatNodeTest.php index 68ed8a7521..d675f47046 100644 --- a/src/Symfony/Component/Config/Tests/Definition/FloatNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/FloatNodeTest.php @@ -19,6 +19,8 @@ class FloatNodeTest extends TestCase { /** * @dataProvider getValidValues + * + * @param int|float $value */ public function testNormalize($value) { @@ -29,7 +31,7 @@ class FloatNodeTest extends TestCase /** * @dataProvider getValidValues * - * @param int $value + * @param int|float $value */ public function testValidNonEmptyValues($value) { @@ -39,7 +41,7 @@ class FloatNodeTest extends TestCase $this->assertSame($value, $node->finalize($value)); } - public function getValidValues() + public function getValidValues(): array { return [ [1798.0], @@ -63,7 +65,7 @@ class FloatNodeTest extends TestCase $node->normalize($value); } - public function getInvalidValues() + public function getInvalidValues(): array { return [ [null], diff --git a/src/Symfony/Component/Config/Tests/Definition/IntegerNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/IntegerNodeTest.php index c4dd57b8f4..7c843b38f3 100644 --- a/src/Symfony/Component/Config/Tests/Definition/IntegerNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/IntegerNodeTest.php @@ -20,7 +20,7 @@ class IntegerNodeTest extends TestCase /** * @dataProvider getValidValues */ - public function testNormalize($value) + public function testNormalize(int $value) { $node = new IntegerNode('test'); $this->assertSame($value, $node->normalize($value)); @@ -28,10 +28,8 @@ class IntegerNodeTest extends TestCase /** * @dataProvider getValidValues - * - * @param int $value */ - public function testValidNonEmptyValues($value) + public function testValidNonEmptyValues(int $value) { $node = new IntegerNode('test'); $node->setAllowEmptyValue(false); @@ -39,7 +37,7 @@ class IntegerNodeTest extends TestCase $this->assertSame($value, $node->finalize($value)); } - public function getValidValues() + public function getValidValues(): array { return [ [1798], @@ -58,7 +56,7 @@ class IntegerNodeTest extends TestCase $node->normalize($value); } - public function getInvalidValues() + public function getInvalidValues(): array { return [ [null], diff --git a/src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php b/src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php index 3fecac2e3e..0b497707e4 100644 --- a/src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/NormalizationTest.php @@ -51,7 +51,7 @@ class NormalizationTest extends TestCase $this->assertNormalized($tree, $denormalized, $normalized); } - public function getEncoderTests() + public function getEncoderTests(): array { $configs = []; @@ -120,7 +120,7 @@ class NormalizationTest extends TestCase $this->assertNormalized($tree, $denormalized, $normalized); } - public function getAnonymousKeysTests() + public function getAnonymousKeysTests(): array { $configs = []; @@ -151,7 +151,7 @@ class NormalizationTest extends TestCase $this->assertNormalized($this->getNumericKeysTestTree(), $denormalized, $normalized); } - public function getNumericKeysTests() + public function getNumericKeysTests(): array { $configs = []; @@ -233,10 +233,9 @@ class NormalizationTest extends TestCase self::assertSame($normalized, $tree->normalize($denormalized)); } - private function getNumericKeysTestTree() + private function getNumericKeysTestTree(): NodeInterface { - $tb = new TreeBuilder('root', 'array'); - $tree = $tb + return (new TreeBuilder('root', 'array')) ->getRootNode() ->children() ->node('thing', 'array') @@ -247,9 +246,6 @@ class NormalizationTest extends TestCase ->end() ->end() ->end() - ->buildTree() - ; - - return $tree; + ->buildTree(); } } diff --git a/src/Symfony/Component/Config/Tests/Definition/PrototypedArrayNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/PrototypedArrayNodeTest.php index 58d2408a71..b02d6ce6df 100644 --- a/src/Symfony/Component/Config/Tests/Definition/PrototypedArrayNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/PrototypedArrayNodeTest.php @@ -264,7 +264,7 @@ class PrototypedArrayNodeTest extends TestCase * * @dataProvider getDataForKeyRemovedLeftValueOnly */ - public function testMappedAttributeKeyIsRemovedLeftValueOnly($value, $children, $expected) + public function testMappedAttributeKeyIsRemovedLeftValueOnly($value, $children, array $expected) { $node = new PrototypedArrayNode('root'); $node->setKeyAttribute('id', true); @@ -280,7 +280,7 @@ class PrototypedArrayNodeTest extends TestCase $this->assertEquals($expected, $normalized); } - public function getDataForKeyRemovedLeftValueOnly() + public function getDataForKeyRemovedLeftValueOnly(): array { $scalarValue = new ScalarNode('value'); @@ -342,7 +342,7 @@ class PrototypedArrayNodeTest extends TestCase /** * @dataProvider getPrototypedArrayNodeDataToMerge */ - public function testPrototypedArrayNodeMerge($left, $right, $expected) + public function testPrototypedArrayNodeMerge(array $left, array $right, array $expected) { $node = new PrototypedArrayNode('options'); $node->setNormalizeKeys(false); @@ -354,7 +354,7 @@ class PrototypedArrayNodeTest extends TestCase self::assertSame($result, $expected); } - public function getPrototypedArrayNodeDataToMerge() + public function getPrototypedArrayNodeDataToMerge(): array { return [ // data to merged is a plain array diff --git a/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php index 0eb66963eb..0ddd1104fa 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php @@ -28,7 +28,7 @@ class ScalarNodeTest extends TestCase $this->assertSame($value, $node->normalize($value)); } - public function getValidValues() + public function getValidValues(): array { return [ [false], @@ -84,7 +84,7 @@ class ScalarNodeTest extends TestCase $node->normalize($value); } - public function getInvalidValues() + public function getInvalidValues(): array { return [ [[]], @@ -127,7 +127,7 @@ class ScalarNodeTest extends TestCase $this->assertSame($value, $node->finalize($value)); } - public function getValidNonEmptyValues() + public function getValidNonEmptyValues(): array { return [ [false], @@ -153,7 +153,7 @@ class ScalarNodeTest extends TestCase $node->finalize($value); } - public function getEmptyValues() + public function getEmptyValues(): array { return [ [null], diff --git a/src/Symfony/Component/Config/Tests/FileLocatorTest.php b/src/Symfony/Component/Config/Tests/FileLocatorTest.php index 44ef5ac9e3..b8419d9a1a 100644 --- a/src/Symfony/Component/Config/Tests/FileLocatorTest.php +++ b/src/Symfony/Component/Config/Tests/FileLocatorTest.php @@ -20,7 +20,7 @@ class FileLocatorTest extends TestCase /** * @dataProvider getIsAbsolutePathTests */ - public function testIsAbsolutePath($path) + public function testIsAbsolutePath(string $path) { $loader = new FileLocator([]); $r = new \ReflectionObject($loader); @@ -30,7 +30,7 @@ class FileLocatorTest extends TestCase $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path'); } - public function getIsAbsolutePathTests() + public function getIsAbsolutePathTests(): array { return [ ['/foo.xml'], diff --git a/src/Symfony/Component/Config/Tests/Fixtures/Builder/NodeBuilder.php b/src/Symfony/Component/Config/Tests/Fixtures/Builder/NodeBuilder.php index 26323e9805..5a0a8fe6f3 100644 --- a/src/Symfony/Component/Config/Tests/Fixtures/Builder/NodeBuilder.php +++ b/src/Symfony/Component/Config/Tests/Fixtures/Builder/NodeBuilder.php @@ -12,10 +12,11 @@ namespace Symfony\Component\Config\Tests\Fixtures\Builder; use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder; +use Symfony\Component\Config\Definition\Builder\NodeDefinition; class NodeBuilder extends BaseNodeBuilder { - public function barNode($name) + public function barNode($name): NodeDefinition { return $this->node($name, 'bar'); } @@ -23,9 +24,8 @@ class NodeBuilder extends BaseNodeBuilder protected function getNodeClass($type): string { switch ($type) { - case 'variable': - return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition'; case 'bar': + case 'variable': return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition'; default: return parent::getNodeClass($type); diff --git a/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php b/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php index 1270eb6a68..f6c53ceeeb 100644 --- a/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php +++ b/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php @@ -7,22 +7,22 @@ use Symfony\Component\Config\Definition\NodeInterface; class CustomNode implements NodeInterface { - public function getName() + public function getName(): string { return 'custom_node'; } - public function getPath() + public function getPath(): string { return 'custom'; } - public function isRequired() + public function isRequired(): bool { return false; } - public function hasDefaultValue() + public function hasDefaultValue(): bool { return true; } diff --git a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php index 023bbe0f31..9c74f6d60a 100644 --- a/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php @@ -165,22 +165,12 @@ class TestFileLoader extends FileLoader return $this->supports; } - public function addLoading($resource) + public function addLoading(string $resource): void { self::$loading[$resource] = true; } - public function removeLoading($resource) - { - unset(self::$loading[$resource]); - } - - public function clearLoading() - { - self::$loading = []; - } - - public function setSupports($supports) + public function setSupports(bool $supports): void { $this->supports = $supports; } diff --git a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php index 3de58f4be0..a114f214ab 100644 --- a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php @@ -35,7 +35,7 @@ class DirectoryResourceTest extends TestCase $this->removeDirectory($this->directory); } - protected function removeDirectory($directory) + protected function removeDirectory(string $directory): void { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $path) { diff --git a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php index af0c2cd2c9..64cfbf129a 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php @@ -64,7 +64,7 @@ class ReflectionClassResourceTest extends TestCase /** * @dataProvider provideHashedSignature */ - public function testHashedSignature($changeExpected, $changedLine, $changedCode, $setContext = null) + public function testHashedSignature(bool $changeExpected, int $changedLine, ?string $changedCode, ?\Closure $setContext = null) { if ($setContext) { $setContext(); @@ -117,43 +117,43 @@ EOPHP; } } - public function provideHashedSignature() + public function provideHashedSignature(): iterable { - yield [0, 0, "// line change\n\n"]; - yield [1, 0, '/** class docblock */']; - yield [1, 1, 'abstract class %s']; - yield [1, 1, 'final class %s']; - yield [1, 1, 'class %s extends Exception']; - yield [1, 1, 'class %s implements '.DummyInterface::class]; - yield [1, 3, 'const FOO = 456;']; - yield [1, 3, 'const BAR = 123;']; - yield [1, 4, '/** pub docblock */']; - yield [1, 5, 'protected $pub = [];']; - yield [1, 5, 'public $pub = [123];']; - yield [1, 6, '/** prot docblock */']; - yield [1, 7, 'private $prot;']; - yield [0, 8, '/** priv docblock */']; - yield [0, 9, 'private $priv = 123;']; - yield [1, 10, '/** pub docblock */']; - yield [1, 11, 'public function pub(...$arg) {}']; - yield [1, 11, 'public function pub($arg = null): Foo {}']; - yield [0, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"]; - yield [1, 12, '/** prot docblock */']; - yield [1, 13, 'protected function prot($a = [123]) {}']; - yield [0, 14, '/** priv docblock */']; - yield [0, 15, '']; + yield [false, 0, "// line change\n\n"]; + yield [true, 0, '/** class docblock */']; + yield [true, 1, 'abstract class %s']; + yield [true, 1, 'final class %s']; + yield [true, 1, 'class %s extends Exception']; + yield [true, 1, 'class %s implements '.DummyInterface::class]; + yield [true, 3, 'const FOO = 456;']; + yield [true, 3, 'const BAR = 123;']; + yield [true, 4, '/** pub docblock */']; + yield [true, 5, 'protected $pub = [];']; + yield [true, 5, 'public $pub = [123];']; + yield [true, 6, '/** prot docblock */']; + yield [true, 7, 'private $prot;']; + yield [false, 8, '/** priv docblock */']; + yield [false, 9, 'private $priv = 123;']; + yield [true, 10, '/** pub docblock */']; + yield [true, 11, 'public function pub(...$arg) {}']; + yield [true, 11, 'public function pub($arg = null): Foo {}']; + yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"]; + yield [true, 12, '/** prot docblock */']; + yield [true, 13, 'protected function prot($a = [123]) {}']; + yield [false, 14, '/** priv docblock */']; + yield [false, 15, '']; if (\PHP_VERSION_ID >= 70400) { // PHP7.4 typed properties without default value are // undefined, make sure this doesn't throw an error - yield [1, 5, 'public array $pub;']; - yield [0, 7, 'protected int $prot;']; - yield [0, 9, 'private string $priv;']; + yield [true, 5, 'public array $pub;']; + yield [false, 7, 'protected int $prot;']; + yield [false, 9, 'private string $priv;']; } - yield [1, 17, 'public function ccc($bar = 187) {}']; - yield [1, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}']; - yield [1, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }]; + yield [true, 17, 'public function ccc($bar = 187) {}']; + yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}']; + yield [true, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }]; } public function testEventSubscriber() diff --git a/src/Symfony/Component/Config/Tests/Resource/ResourceStub.php b/src/Symfony/Component/Config/Tests/Resource/ResourceStub.php index 959b00290e..4073566d19 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ResourceStub.php +++ b/src/Symfony/Component/Config/Tests/Resource/ResourceStub.php @@ -17,7 +17,7 @@ class ResourceStub implements SelfCheckingResourceInterface { private $fresh = true; - public function setFresh($isFresh) + public function setFresh(bool $isFresh): void { $this->fresh = $isFresh; } diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php index 481603763a..a7a8ae980d 100644 --- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php +++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php @@ -116,7 +116,7 @@ class XmlUtilsTest extends TestCase /** * @dataProvider getDataForConvertDomToArray */ - public function testConvertDomToArray($expected, $xml, $root = false, $checkPrefix = true) + public function testConvertDomToArray($expected, string $xml, bool $root = false, bool $checkPrefix = true) { $dom = new \DOMDocument(); $dom->loadXML($root ? $xml : ''.$xml.''); @@ -124,7 +124,7 @@ class XmlUtilsTest extends TestCase $this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement, $checkPrefix)); } - public function getDataForConvertDomToArray() + public function getDataForConvertDomToArray(): array { return [ [null, ''], @@ -155,7 +155,7 @@ class XmlUtilsTest extends TestCase $this->assertSame($expected, XmlUtils::phpize($value)); } - public function getDataForPhpize() + public function getDataForPhpize(): array { return [ ['', ''],