Skip to content

Commit 44b7148

Browse files
committed
Resolve symfony/config:5.1 deprecation with setDeprecated method
inspired by doctrine/DoctrineBundle@ca38c08
1 parent 5efa29d commit 44b7148

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

DependencyInjection/Configuration.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\Bundle\MigrationsBundle\DependencyInjection;
66

77
use ReflectionClass;
8+
use Symfony\Component\Config\Definition\BaseNode;
89
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
910
use Symfony\Component\Config\Definition\ConfigurationInterface;
1011
use function constant;
@@ -43,7 +44,7 @@ public function getConfigTreeBuilder() : TreeBuilder
4344
$rootNode
4445
->children()
4546
->scalarNode('name')
46-
->setDeprecated('The "%node%" option is deprecated.')
47+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated.'))
4748
->defaultValue('Application Migrations')
4849
->end()
4950

@@ -91,27 +92,27 @@ public function getConfigTreeBuilder() : TreeBuilder
9192

9293
->scalarNode('dir_name')
9394
->defaultValue('%kernel.root_dir%/DoctrineMigrations')->cannotBeEmpty()
94-
->setDeprecated('The "%node%" option is deprecated. Use "migrations_paths" instead.')
95+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "migrations_paths" instead.'))
9596
->end()
9697
->scalarNode('namespace')
9798
->defaultValue('Application\Migrations')->cannotBeEmpty()
98-
->setDeprecated('The "%node%" option is deprecated. Use "migrations_paths" instead.')
99+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "migrations_paths" instead.'))
99100
->end()
100101
->scalarNode('table_name')
101102
->defaultValue('migration_versions')->cannotBeEmpty()
102-
->setDeprecated('The "%node%" option is deprecated. Use "storage.table_storage.table_name" instead.')
103+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "storage.table_storage.table_name" instead.'))
103104
->end()
104105
->scalarNode('column_name')
105106
->defaultValue('version')
106-
->setDeprecated('The "%node%" option is deprecated. Use "storage.table_storage.version_column_name" instead.')
107+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "storage.table_storage.version_column_name" instead.'))
107108
->end()
108109
->scalarNode('column_length')
109110
->defaultValue(14)
110-
->setDeprecated('The "%node%" option is deprecated. Use "storage.table_storage.version_column_length" instead.')
111+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "storage.table_storage.version_column_length" instead.'))
111112
->end()
112113
->scalarNode('executed_at_column_name')
113114
->defaultValue('executed_at')
114-
->setDeprecated('The "%node%" option is deprecated. Use "storage.table_storage.executed_at_column_name" instead.')
115+
->setDeprecated(...$this->getParamDeprecationMsg('The "%node%" option is deprecated. Use "storage.table_storage.executed_at_column_name" instead.'))
115116
->end()
116117
->scalarNode('all_or_nothing')->defaultValue(false)->end()
117118
->scalarNode('custom_template')->defaultValue(null)->end()
@@ -167,4 +168,27 @@ private function getOrganizeMigrationsModes() : array
167168

168169
return $namesArray;
169170
}
171+
172+
/**
173+
* Returns the correct deprecation param's as an array for setDeprecated.
174+
*
175+
* Symfony/Config v5.1 introduces a deprecation notice when calling
176+
* setDeprecation() with less than 3 args and the getDeprecation method was
177+
* introduced at the same time. By checking if getDeprecation() exists,
178+
* we can determine the correct param count to use when calling setDeprecated.
179+
*
180+
* @return string[]
181+
*/
182+
private function getParamDeprecationMsg(string $message) : array
183+
{
184+
if (method_exists(BaseNode::class, 'getDeprecation')) {
185+
return [
186+
'doctrine/doctrine-migrations-bundle',
187+
'2.2',
188+
$message,
189+
];
190+
}
191+
192+
return [$message];
193+
}
170194
}

0 commit comments

Comments
 (0)