Skip to content
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

fix symfony/config deprecation #1153

Merged
merged 8 commits into from Apr 3, 2020
26 changes: 25 additions & 1 deletion DependencyInjection/Configuration.php
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\EntityManager;
use ReflectionClass;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -91,7 +92,7 @@ private function addDbalSection(ArrayNodeDefinition $node) : void
->end()
->children()
->scalarNode('class')->isRequired()->end()
->booleanNode('commented')->setDeprecated()->end()
->booleanNode('commented')->setDeprecated(...$this->getCommentedParamDeprecationMsg())->end()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if return value of $this->getCommentedParamDeprecationMsg() is [], I believe using ... will cause ArgumentCountError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed - for config versions before 5.1, a message is provided. Attempted to return null for < 5.1 but that triggered a TypeError in an even earlier version before setDeprecated() allowed ?string

->end()
->end()
->end()
Expand Down Expand Up @@ -689,4 +690,27 @@ private function getAutoGenerateModes() : array
'values' => $valuesArray,
];
}

/**
* Returns the correct deprecation param's as an array for setDeprecated.
*
* Symfony/Config v5.1 introduces a deprecation notice when calling
* setDeprecation() with less than 3 args and the getDeprecation method was
* introduced at the same time. By checking if getDeprecation() exists,
* we can determine the correct param count to use when calling setDeprecated.
*/
private function getCommentedParamDeprecationMsg() : array
{
$message = 'The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.';

if (method_exists(BaseNode::class, 'getDeprecation')) {
return [
'doctrine/doctrine-bundle',
'2.0',
$message,
];
}

return [$message];
}
}