| 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 |
||
| 57 | public function createMigrationConfigurationService( |
||
| 58 | ContainerBuilder $container, |
||
| 59 | string $connectionName, |
||
| 60 | string $serviceId, |
||
| 61 | string $filename = null |
||
| 62 | ): void { |
||
| 63 | if (!$container->has(Configuration::class)) { |
||
| 64 | $container->register(Configuration::class) |
||
| 65 | ->setAbstract(true) |
||
| 66 | ->setPublic(true) |
||
| 67 | ->setArguments([null]) |
||
| 68 | ->addMethodCall('setContainer', [new Reference('service_container')]); |
||
| 69 | } |
||
| 70 | |||
| 71 | $configuration = $this->createTemporaryConfiguration($container, $this->getConnection(), $filename); |
||
| 72 | |||
| 73 | $serviceConfiguration = new ChildDefinition(Configuration::class); |
||
| 74 | |||
| 75 | $this->migrationConfigurationsServices[] = [$serviceConfiguration, $configuration]; |
||
| 76 | |||
| 77 | $serviceConfiguration->replaceArgument( |
||
| 78 | 0, |
||
| 79 | new Reference(sprintf('doctrine.dbal.%s_connection', $connectionName)) |
||
| 80 | ); |
||
| 81 | |||
| 82 | if ($configuration->getMigrationsNamespace()) { |
||
| 83 | $serviceConfiguration->addMethodCall( |
||
| 84 | 'setMigrationsNamespace', |
||
| 85 | [$configuration->getMigrationsNamespace()] |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($configuration->getMigrationsTableName()) { |
||
| 90 | $serviceConfiguration->addMethodCall( |
||
| 91 | 'setMigrationsTableName', |
||
| 92 | [$configuration->getMigrationsTableName()] |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($configuration->getMigrationsColumnName()) { |
||
| 97 | $serviceConfiguration->addMethodCall( |
||
| 98 | 'setMigrationsColumnName', |
||
| 99 | [$configuration->getMigrationsColumnName()] |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($configuration->getName()) { |
||
| 104 | $serviceConfiguration->addMethodCall('setName', [$configuration->getName()]); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($configuration->getMigrationsDirectory()) { |
||
| 108 | $directory = $configuration->getMigrationsDirectory(); |
||
| 109 | $pathPlaceholders = ['kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir']; |
||
| 110 | foreach ($pathPlaceholders as $parameter) { |
||
| 111 | $kernelDir = realpath($container->getParameter($parameter)); |
||
| 112 | if (0 === strpos(realpath($directory), $kernelDir)) { |
||
| 113 | $directory = str_replace($kernelDir, "%{$parameter}%", $directory); |
||
| 114 | break; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $serviceConfiguration->addMethodCall( |
||
| 119 | 'setMigrationsDirectory', |
||
| 120 | [$directory] |
||
| 121 | ); |
||
| 122 | } |
||
| 123 | |||
| 124 | $serviceConfiguration->addMethodCall('configure', []); |
||
| 125 | |||
| 126 | if ($configuration->areMigrationsOrganizedByYear()) { |
||
| 127 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYear', [true]); |
||
| 128 | } elseif ($configuration->areMigrationsOrganizedByYearAndMonth()) { |
||
| 129 | $serviceConfiguration->addMethodCall('setMigrationsAreOrganizedByYearAndMonth', [true]); |
||
| 130 | } |
||
| 131 | |||
| 132 | $container->setDefinition($serviceId, $serviceConfiguration); |
||
| 133 | } |
||
| 134 | |||
| 241 |
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.