1313use Symfony \Component \DependencyInjection \ContainerInterface ;
1414use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
1515
16+ use function assert ;
1617use function error_get_last ;
18+ use function is_bool ;
1719use function is_dir ;
20+ use function is_int ;
21+ use function is_string ;
1822use function mkdir ;
1923use function preg_match ;
2024use function preg_quote ;
@@ -31,7 +35,7 @@ public static function configureMigrations(ContainerInterface $container, Config
3135 $ dir = $ configuration ->getMigrationsDirectory ();
3236
3337 if ($ dir === null ) {
34- $ dir = $ container-> getParameter ( 'doctrine_migrations.dir_name ' );
38+ $ dir = self :: getStringParameter ( $ container, 'doctrine_migrations.dir_name ' );
3539
3640 if (! is_dir ($ dir ) && ! @mkdir ($ dir , 0777 , true ) && ! is_dir ($ dir )) {
3741 $ error = error_get_last ();
@@ -53,7 +57,10 @@ public static function configureMigrations(ContainerInterface $container, Config
5357 continue ;
5458 }
5559
56- $ dir = str_replace ('% ' . $ pathPlaceholder . '% ' , $ container ->getParameter ($ pathPlaceholder ), $ dir );
60+ $ dir = str_replace ('% ' . $ pathPlaceholder . '% ' , self ::getStringParameter (
61+ $ container ,
62+ $ pathPlaceholder
63+ ), $ dir );
5764 }
5865
5966 if (! is_dir ($ dir ) && ! @mkdir ($ dir , 0777 , true ) && ! is_dir ($ dir )) {
@@ -70,22 +77,32 @@ public static function configureMigrations(ContainerInterface $container, Config
7077 }
7178
7279 if ($ configuration ->getMigrationsNamespace () === null ) {
73- $ configuration ->setMigrationsNamespace ($ container ->getParameter ('doctrine_migrations.namespace ' ));
80+ $ configuration ->setMigrationsNamespace (self ::getStringParameter (
81+ $ container ,
82+ 'doctrine_migrations.namespace '
83+ ));
7484 }
7585
7686 if ($ configuration ->getName () === null ) {
77- $ configuration ->setName ($ container ->getParameter ('doctrine_migrations.name ' ));
87+ $ configuration ->setName (self ::getStringParameter (
88+ $ container ,
89+ 'doctrine_migrations.name '
90+ ));
7891 }
7992
8093 // For backward compatibility, need use a table from parameters for overwrite the default configuration
8194 if (! ($ configuration instanceof AbstractFileConfiguration) || $ configuration ->getMigrationsTableName () === '' ) {
82- $ configuration ->setMigrationsTableName ($ container-> getParameter ( 'doctrine_migrations.table_name ' ));
95+ $ configuration ->setMigrationsTableName (self :: getStringParameter ( $ container, 'doctrine_migrations.table_name ' ));
8396 }
8497
85- $ configuration ->setMigrationsColumnName ($ container ->getParameter ('doctrine_migrations.column_name ' ));
86- $ configuration ->setMigrationsColumnLength ($ container ->getParameter ('doctrine_migrations.column_length ' ));
87- $ configuration ->setMigrationsExecutedAtColumnName ($ container ->getParameter ('doctrine_migrations.executed_at_column_name ' ));
88- $ configuration ->setAllOrNothing ($ container ->getParameter ('doctrine_migrations.all_or_nothing ' ));
98+ $ configuration ->setMigrationsColumnName (self ::getStringParameter ($ container , 'doctrine_migrations.column_name ' ));
99+ $ columnLength = $ container ->getParameter ('doctrine_migrations.column_length ' );
100+ assert (is_int ($ columnLength ));
101+ $ configuration ->setMigrationsColumnLength ($ columnLength );
102+ $ configuration ->setMigrationsExecutedAtColumnName (self ::getStringParameter ($ container , 'doctrine_migrations.executed_at_column_name ' ));
103+ $ allOrNothing = $ container ->getParameter ('doctrine_migrations.all_or_nothing ' );
104+ assert (is_bool ($ allOrNothing ));
105+ $ configuration ->setAllOrNothing ($ allOrNothing );
89106
90107 // Migrations is not register from configuration loader
91108 if (! ($ configuration instanceof AbstractFileConfiguration)) {
@@ -97,7 +114,9 @@ public static function configureMigrations(ContainerInterface $container, Config
97114 }
98115
99116 if ($ configuration ->getCustomTemplate () === null ) {
100- $ configuration ->setCustomTemplate ($ container ->getParameter ('doctrine_migrations.custom_template ' ));
117+ $ customTemplate = $ container ->getParameter ('doctrine_migrations.custom_template ' );
118+ assert (is_string ($ customTemplate ) || $ customTemplate === null );
119+ $ configuration ->setCustomTemplate ($ customTemplate );
101120 }
102121
103122 $ organizeMigrations = $ container ->getParameter ('doctrine_migrations.organize_migrations ' );
@@ -137,4 +156,12 @@ private static function injectContainerToMigrations(ContainerInterface $containe
137156 $ migration ->setContainer ($ container );
138157 }
139158 }
159+
160+ private static function getStringParameter (ContainerInterface $ container , string $ name ): string
161+ {
162+ $ value = $ container ->getParameter ($ name );
163+ assert (is_string ($ value ));
164+
165+ return $ value ;
166+ }
140167}
0 commit comments