| Conditions | 11 |
| Paths | 384 |
| Total Lines | 77 |
| 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 |
||
| 51 | public function createMigrationConfigurationService( |
||
| 52 | ContainerBuilder $container, |
||
| 53 | string $connectionName, |
||
| 54 | string $serviceId, |
||
| 55 | string $filename = null |
||
| 56 | ): void { |
||
| 57 | if (!$container->has(Configuration::class)) { |
||
| 58 | $container->register(Configuration::class) |
||
| 59 | ->setAbstract(true) |
||
| 60 | ->setPublic(true) |
||
| 61 | ->setArguments([null]) |
||
| 62 | ->addMethodCall('setContainer', [new Reference('service_container')]); |
||
| 63 | } |
||
| 64 | |||
| 65 | $configuration = $this->createTemporaryConfiguration($container, $this->getConnection(), $filename); |
||
| 66 | |||
| 67 | $serviceConfiguration = new ChildDefinition(Configuration::class); |
||
| 68 | |||
| 69 | $this->migrationConfigurationsServices[] = [$serviceConfiguration, $configuration]; |
||
| 70 | |||
| 71 | $serviceConfiguration->replaceArgument( |
||
| 72 | 0, |
||
| 73 | new Reference(sprintf('doctrine.dbal.%s_connection', $connectionName)) |
||
| 74 | ); |
||
| 75 | |||
| 76 | if ($configuration->getMigrationsNamespace()) { |
||
| 77 | $serviceConfiguration->addMethodCall( |
||
| 78 | 'setMigrationsNamespace', |
||
| 79 | [$configuration->getMigrationsNamespace()] |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($configuration->getMigrationsTableName()) { |
||
| 84 | $serviceConfiguration->addMethodCall( |
||
| 85 | 'setMigrationsTableName', |
||
| 86 | [$configuration->getMigrationsTableName()] |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($configuration->getMigrationsColumnName()) { |
||
| 91 | $serviceConfiguration->addMethodCall( |
||
| 92 | 'setMigrationsColumnName', |
||
| 93 | [$configuration->getMigrationsColumnName()] |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($configuration->getName()) { |
||
| 98 | $serviceConfiguration->addMethodCall('setName', [$configuration->getName()]); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($configuration->getMigrationsDirectory()) { |
||
| 102 | $directory = $configuration->getMigrationsDirectory(); |
||
| 103 | $pathPlaceholders = ['kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir']; |
||
| 104 | foreach ($pathPlaceholders as $parameter) { |
||
| 105 | $kernelDir = realpath($container->getParameter($parameter)); |
||
| 106 | if (0 === strpos(realpath($directory), $kernelDir)) { |
||
| 107 | $directory = str_replace($kernelDir, "%{$parameter}%", $directory); |
||
| 108 | break; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $serviceConfiguration->addMethodCall( |
||
| 113 | 'setMigrationsDirectory', |
||
| 114 | [$directory] |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | $serviceConfiguration->addMethodCall('configure', []); |
||
| 119 | |||
| 120 | if ($configuration->areMigrationsOrganizedByYear()) { |
||
| 121 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYear', [true]); |
||
| 122 | } elseif ($configuration->areMigrationsOrganizedByYearAndMonth()) { |
||
| 123 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYearAndMonth', [true]); |
||
| 124 | } |
||
| 125 | |||
| 126 | $container->setDefinition($serviceId, $serviceConfiguration); |
||
| 127 | } |
||
| 128 | |||
| 230 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.