Skip to content

[Config] Remove deprecated code #41303

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
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.0
---

* Remove `BaseNode::getDeprecationMessage()`

5.3.0
-----

Expand Down
46 changes: 4 additions & 42 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,8 @@ public function setRequired(bool $boolean)
* You can use %node% and %path% placeholders in your message to display,
* respectively, the node name and its complete path
*/
public function setDeprecated(?string $package/*, string $version, string $message = 'The child node "%node%" at path "%path%" is deprecated.' */)
public function setDeprecated(string $package, string $version, string $message = 'The child node "%node%" at path "%path%" is deprecated.')
{
$args = \func_get_args();

if (\func_num_args() < 2) {
trigger_deprecation('symfony/config', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);

if (!isset($args[0])) {
trigger_deprecation('symfony/config', '5.1', 'Passing a null message to un-deprecate a node is deprecated.');

$this->deprecation = [];

return;
}

$message = (string) $args[0];
$package = $version = '';
} else {
$package = (string) $args[0];
$version = (string) $args[1];
$message = (string) ($args[2] ?? 'The child node "%node%" at path "%path%" is deprecated.');
}

$this->deprecation = [
'package' => $package,
'version' => $version,
Expand Down Expand Up @@ -281,33 +260,16 @@ public function isDeprecated()
return (bool) $this->deprecation;
}

/**
* Returns the deprecated message.
*
* @param string $node the configuration node name
* @param string $path the path of the node
*
* @return string
*
* @deprecated since Symfony 5.1, use "getDeprecation()" instead.
*/
public function getDeprecationMessage(string $node, string $path)
{
trigger_deprecation('symfony/config', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__);

return $this->getDeprecation($node, $path)['message'];
}

/**
* @param string $node The configuration node name
* @param string $path The path of the node
*/
public function getDeprecation(string $node, string $path): array
{
return [
'package' => $this->deprecation['package'] ?? '',
'version' => $this->deprecation['version'] ?? '',
'message' => strtr($this->deprecation['message'] ?? '', ['%node%' => $node, '%path%' => $path]),
'package' => $this->deprecation['package'],
'version' => $this->deprecation['version'],
'message' => strtr($this->deprecation['message'], ['%node%' => $node, '%path%' => $path]),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,8 @@ public function isRequired()
*
* @return $this
*/
public function setDeprecated(/* string $package, string $version, string $message = 'The child node "%node%" at path "%path%" is deprecated.' */)
public function setDeprecated(string $package, string $version, string $message = 'The child node "%node%" at path "%path%" is deprecated.')
{
$args = \func_get_args();

if (\func_num_args() < 2) {
trigger_deprecation('symfony/config', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);

$message = $args[0] ?? 'The child node "%node%" at path "%path%" is deprecated.';
$package = $version = '';
} else {
$package = (string) $args[0];
$version = (string) $args[1];
$message = (string) ($args[2] ?? 'The child node "%node%" at path "%path%" is deprecated.');
}

$this->deprecation = [
'package' => $package,
'version' => $version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@
*/
class FileLoaderImportCircularReferenceException extends LoaderLoadException
{
public function __construct(array $resources, ?int $code = 0, \Throwable $previous = null)
public function __construct(array $resources, int $code = 0, \Throwable $previous = null)
{
if (null === $code) {
trigger_deprecation('symfony/config', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__);

$code = 0;
}

$message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]);

\Exception::__construct($message, $code, $previous);
Expand Down
10 changes: 2 additions & 8 deletions src/Symfony/Component/Config/Exception/LoaderLoadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ class LoaderLoadException extends \Exception
/**
* @param string $resource The resource that could not be imported
* @param string|null $sourceResource The original resource importing the new resource
* @param int|null $code The error code
* @param int $code The error code
* @param \Throwable|null $previous A previous exception
* @param string|null $type The type of resource
*/
public function __construct(string $resource, string $sourceResource = null, ?int $code = 0, \Throwable $previous = null, string $type = null)
public function __construct(string $resource, string $sourceResource = null, int $code = 0, \Throwable $previous = null, string $type = null)
{
if (null === $code) {
trigger_deprecation('symfony/config', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__);

$code = 0;
}

$message = '';
if ($previous) {
// Include the previous exception, to help the user see what might be the underlying cause
Expand Down
34 changes: 0 additions & 34 deletions src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
namespace Symfony\Component\Config\Tests\Definition;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;
use Symfony\Component\Config\Definition\ScalarNode;

class ArrayNodeTest extends TestCase
{
use ExpectDeprecationTrait;

public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
{
$this->expectException(InvalidTypeException::class);
Expand Down Expand Up @@ -263,37 +260,6 @@ public function testSetDeprecated()
$this->assertTrue($deprecationTriggered, '->finalize() should trigger if the deprecated node is set');
}

/**
* @group legacy
*/
public function testUnDeprecateANode()
{
$this->expectDeprecation('Since symfony/config 5.1: The signature of method "Symfony\Component\Config\Definition\BaseNode::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
$this->expectDeprecation('Since symfony/config 5.1: Passing a null message to un-deprecate a node is deprecated.');

$node = new ArrayNode('foo');
$node->setDeprecated('"%node%" is deprecated');
$node->setDeprecated(null);

$this->assertFalse($node->isDeprecated());
}

/**
* @group legacy
*/
public function testSetDeprecatedWithoutPackageAndVersion()
{
$this->expectDeprecation('Since symfony/config 5.1: The signature of method "Symfony\Component\Config\Definition\BaseNode::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');

$node = new ArrayNode('foo');
$node->setDeprecated('"%node%" is deprecated');

$deprecation = $node->getDeprecation($node->getName(), $node->getPath());
$this->assertSame('"foo" is deprecated', $deprecation['message']);
$this->assertSame('', $deprecation['package']);
$this->assertSame('', $deprecation['version']);
}

/**
* @dataProvider getDataWithIncludedExtraKeys
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Config\Tests\Definition\Builder;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
Expand All @@ -24,8 +23,6 @@

class ArrayNodeDefinitionTest extends TestCase
{
use ExpectDeprecationTrait;

public function testAppendingSomeNode()
{
$parent = new ArrayNodeDefinition('root');
Expand Down Expand Up @@ -349,27 +346,6 @@ public function testSetDeprecated()
$this->assertSame('1.1', $deprecation['version']);
}

/**
* @group legacy
*/
public function testSetDeprecatedWithoutPackageAndVersion()
{
$this->expectDeprecation('Since symfony/config 5.1: The signature of method "Symfony\Component\Config\Definition\Builder\NodeDefinition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
$node = new ArrayNodeDefinition('root');
$node
->children()
->arrayNode('foo')->setDeprecated('The "%path%" node is deprecated.')->end()
->end()
;
$deprecatedNode = $node->getNode()->getChildren()['foo'];

$this->assertTrue($deprecatedNode->isDeprecated());
$deprecation = $deprecatedNode->getDeprecation($deprecatedNode->getName(), $deprecatedNode->getPath());
$this->assertSame('The "root.foo" node is deprecated.', $deprecation['message']);
$this->assertSame('', $deprecation['package']);
$this->assertSame('', $deprecation['version']);
}

public function testCannotBeEmptyOnConcreteNode()
{
$this->expectException(InvalidDefinitionException::class);
Expand Down