Conditions | 15 |
Paths | 197 |
Total Lines | 91 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
164 | private function configureDoctrineMigrationsCheck(ContainerBuilder $container, array $params) |
||
165 | { |
||
166 | if (!$container->hasDefinition('liip_monitor.check.doctrine_migrations') || !isset($params['groups'])) { |
||
167 | return; |
||
168 | } |
||
169 | |||
170 | // ------- |
||
171 | // This part must be in sync with Doctrine\DBAL\Migrations\Tools\Console\Helper\ConfigurationHelper::loadConfig |
||
172 | $map = array( |
||
173 | 'xml' => '\XmlConfiguration', |
||
174 | 'yaml' => '\YamlConfiguration', |
||
175 | 'yml' => '\YamlConfiguration', |
||
176 | 'php' => '\ArrayConfiguration', |
||
177 | 'json' => '\JsonConfiguration' |
||
178 | ); |
||
179 | // -------- |
||
180 | |||
181 | foreach ($params['groups'] as $groupName => $groupChecks) { |
||
182 | if (!isset($groupChecks['doctrine_migrations'])) { |
||
183 | continue; |
||
184 | } |
||
185 | |||
186 | $services = []; |
||
187 | foreach ($groupChecks['doctrine_migrations'] as $key => $config) { |
||
188 | $filename = $container->getParameterBag()->resolveValue($config['configuration_file']); |
||
189 | $info = pathinfo($filename); |
||
190 | // check we can support this file type |
||
191 | if (empty($map[$info['extension']])) { |
||
192 | throw new \InvalidArgumentException('Given config file type is not supported'); |
||
193 | } |
||
194 | |||
195 | $class = 'Doctrine\DBAL\Migrations\Configuration'; |
||
196 | $class .= $map[$info['extension']]; |
||
197 | // ------- |
||
198 | |||
199 | /** @var AbstractFileConfiguration $configuration */ |
||
200 | $connection = new Connection([], new Driver()); |
||
201 | $configuration = new $class($connection); // needed for correct migration loading |
||
202 | $configuration->load($filename); |
||
203 | |||
204 | $serviceConfiguration = |
||
205 | new DefinitionDecorator('liip_monitor.check.doctrine_migrations.abstract_configuration'); |
||
206 | $serviceConfiguration->replaceArgument( |
||
207 | 0, |
||
208 | new Reference(sprintf('doctrine.dbal.%s_connection', $config['connection'])) |
||
209 | ); |
||
210 | |||
211 | if ($configuration->getMigrationsNamespace()) { |
||
212 | $serviceConfiguration->addMethodCall('setMigrationsNamespace', [$configuration->getMigrationsNamespace()]); |
||
213 | } |
||
214 | |||
215 | if ($configuration->getMigrationsTableName()) { |
||
216 | $serviceConfiguration->addMethodCall('setMigrationsTableName', [$configuration->getMigrationsTableName()]); |
||
217 | } |
||
218 | |||
219 | if ($configuration->getMigrationsColumnName()) { |
||
220 | $serviceConfiguration->addMethodCall('setMigrationsColumnName', [$configuration->getMigrationsColumnName()]); |
||
221 | } |
||
222 | |||
223 | if ($configuration->getName()) { |
||
224 | $serviceConfiguration->addMethodCall('setName', [$configuration->getName()]); |
||
225 | } |
||
226 | |||
227 | if ($configuration->getMigrationsDirectory()) { |
||
228 | $serviceConfiguration->addMethodCall('setMigrationsDirectory', [$configuration->getMigrationsDirectory()]); |
||
229 | } |
||
230 | |||
231 | /** @var AbstractFileConfiguration $diff */ |
||
232 | $versions = $this->getPredefinedMigrations($configuration, $connection); |
||
233 | if ($versions) { |
||
|
|||
234 | $serviceConfiguration->addMethodCall('registerMigrations', [$versions]); |
||
235 | } |
||
236 | |||
237 | $serviceConfiguration->addMethodCall('configure', []); |
||
238 | |||
239 | if ($configuration->areMigrationsOrganizedByYear()) { |
||
240 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYear', [true]); |
||
241 | } elseif ($configuration->areMigrationsOrganizedByYearAndMonth()) { |
||
242 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYearAndMonth', [true]); |
||
243 | } |
||
244 | |||
245 | $serviceId = sprintf('liip_monitor.check.doctrine_migrations.configuration.%s.%s', $groupName, $key); |
||
246 | $container->setDefinition($serviceId, $serviceConfiguration); |
||
247 | |||
248 | $services[$key] = $serviceId; |
||
249 | } |
||
250 | |||
251 | $parameter = sprintf('%s.check.%s.%s', $this->getAlias(), 'doctrine_migrations', $groupName); |
||
252 | $container->setParameter($parameter, $services); |
||
253 | } |
||
254 | } |
||
255 | |||
282 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.