| Conditions | 11 |
| Paths | 20 |
| Total Lines | 49 |
| Code Lines | 32 |
| 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 |
||
| 38 | public function configure(ConfigurableObjectInterface $config) |
||
| 39 | { |
||
| 40 | $this->object = $config; |
||
| 41 | $configurationDir = $this->configurationDir; |
||
| 42 | if ($configurationDir === null) { |
||
| 43 | $testParts = explode(DIRECTORY_SEPARATOR, realpath(__DIR__.'/../../..')); |
||
| 44 | $isVendor = array_pop($testParts) == 'vendor'; |
||
| 45 | |||
| 46 | if ($isVendor) { |
||
| 47 | $path = realpath(__DIR__ . '/../../../../..'); // Get out of the Magium directories |
||
| 48 | } else { |
||
| 49 | $path = realpath(__DIR__ . '/../../..'); |
||
| 50 | } |
||
| 51 | |||
| 52 | $count = 0; |
||
| 53 | while ($count++ < 10) { |
||
| 54 | $filename = "{$path}/configuration"; |
||
| 55 | $realpath = realpath($filename); |
||
| 56 | if ($realpath !== false && is_dir($realpath)) { |
||
| 57 | // The equality check is due to case-insensitive file systems *ahem* Windows and OS X HFS+ |
||
| 58 | $directories = glob(realpath($filename.'/../').'/*', GLOB_ONLYDIR); |
||
| 59 | foreach ($directories as $directory) { |
||
| 60 | $directory = realpath($directory); |
||
| 61 | $parts = explode(DIRECTORY_SEPARATOR, $directory); |
||
| 62 | $lastPart = array_pop($parts); |
||
| 63 | if ($lastPart == 'configuration') { |
||
| 64 | $configurationDir = $realpath; |
||
| 65 | break 2; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | $path .= '/../'; |
||
| 70 | $path = realpath($path); // More for debugging clarity. |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!is_dir($configurationDir)) return; |
||
| 75 | |||
| 76 | $classes = $this->introspectClass($config); |
||
| 77 | |||
| 78 | foreach ($classes as $class) { |
||
| 79 | $configurationFile = $class . '.php'; |
||
| 80 | $configurationFile = $configurationDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $configurationFile); |
||
| 81 | |||
| 82 | if (file_exists($configurationFile)) { |
||
| 83 | include $configurationFile; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 89 |