| Conditions | 26 |
| Paths | 20 |
| Total Lines | 106 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 39 | protected function performMigration() |
||
| 40 | { |
||
| 41 | $count = 0; |
||
|
|
|||
| 42 | $subDirs = $this->getSubDirectories(Director::baseFolder() . '/'); |
||
| 43 | $ymlFiles = []; |
||
| 44 | foreach ($subDirs as $subDir) { |
||
| 45 | $subDir = rtrim($subDir, '/') . '/'; |
||
| 46 | $fullSubDir = $subDir . '_config/'; |
||
| 47 | if (file_exists($fullSubDir)) { |
||
| 48 | $toAdds = $this->getYMLFiles($fullSubDir); |
||
| 49 | foreach ($toAdds as $toAdd) { |
||
| 50 | if (! in_array(basename($toAdd), $this->Config()->get('files_to_ignore'), true)) { |
||
| 51 | $ymlFiles[] = $toAdd; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | foreach ($ymlFiles as $fileName) { |
||
| 57 | $this->flushNowLine(); |
||
| 58 | $this->flushNow('STARTING TESTING: ' . $fileName . ''); |
||
| 59 | $this->flushNowLine(); |
||
| 60 | $count = 0; |
||
| 61 | $alreadySet = []; |
||
| 62 | if (! file_exists($fileName)) { |
||
| 63 | die(' Could not find ' . $fileName); |
||
| 64 | } |
||
| 65 | $fp = fopen($fileName, 'r'); |
||
| 66 | $hasLine = true; |
||
| 67 | while ($hasLine) { |
||
| 68 | $line = stream_get_line($fp, 1024 * 1024, "\n"); |
||
| 69 | if (! $line) { |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | ++$count; |
||
| 73 | $isProperty = false; |
||
| 74 | // $this->flushNow( '...'; |
||
| 75 | //skip lines that are indented |
||
| 76 | if (' ' === substr((string) $line, 0, 1)) { |
||
| 77 | $isProperty = true; |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($isProperty) { |
||
| 81 | $className = end($alreadySet); |
||
| 82 | if ($className && class_exists($className)) { |
||
| 83 | if (strpos($line, ':')) { |
||
| 84 | $myItems = explode(':', $line); |
||
| 85 | if (2 === count($myItems) && $myItems[0] && $myItems[1]) { |
||
| 86 | $property = trim($myItems[0]); |
||
| 87 | $property = trim($myItems[0], "'"); |
||
| 88 | $property = trim($myItems[0], '"'); |
||
| 89 | if (strpos($property, '\\')) { |
||
| 90 | if (! class_exists($property)) { |
||
| 91 | $this->flushNow(' |
||
| 92 | ERROR ' . $className . '.' . $property . ' may not exist as class name but looks like one.<br>'); |
||
| 93 | } |
||
| 94 | } elseif (strpos($property, '*')) { |
||
| 95 | $this->flushNow(' |
||
| 96 | ERROR ' . $className . '.' . $property . ' contains *.<br>'); |
||
| 97 | } elseif (! property_exists($className, $property)) { |
||
| 98 | $this->flushNow(' |
||
| 99 | ERROR ' . $className . '.' . $property . ' property could not be found<br>'); |
||
| 100 | } else { |
||
| 101 | $this->flushNow(' |
||
| 102 | SUCCESS ' . $className . '.' . $property . ''); |
||
| 103 | } |
||
| 104 | } else { |
||
| 105 | $this->flushNow(' |
||
| 106 | ' . $line . ' ... not two items<br>'); |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $this->flushNow(' |
||
| 110 | ' . $line . ' ... no colon<br>'); |
||
| 111 | } |
||
| 112 | } elseif ($className) { |
||
| 113 | $this->flushNow(' |
||
| 114 | COULD NOT FIND ' . $className . '<br>'); |
||
| 115 | } |
||
| 116 | } else { |
||
| 117 | if (! strpos($line, '\\')) { |
||
| 118 | continue; |
||
| 119 | } |
||
| 120 | if (strpos($line, '*')) { |
||
| 121 | continue; |
||
| 122 | } |
||
| 123 | $line = str_replace(':', '', (string) $line); |
||
| 124 | $line = trim($line); |
||
| 125 | if (isset($alreadySet[$line])) { |
||
| 126 | $this->flushNow(' |
||
| 127 | |||
| 128 | ERROR: Two mentions of ' . $line . '<br>'); |
||
| 129 | } else { |
||
| 130 | $alreadySet[$line] = $line; |
||
| 131 | if (! class_exists($line)) { |
||
| 132 | $this->flushNow(' |
||
| 133 | |||
| 134 | ERROR: Could not find class ' . $line . '<br>'); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | //not a class name |
||
| 139 | } |
||
| 140 | fclose($fp); |
||
| 141 | $this->flushNowLine(); |
||
| 142 | $this->flushNow('' . $count . ' lines'); |
||
| 143 | $this->flushNowLine(); |
||
| 144 | $count = 0; |
||
| 145 | } |
||
| 178 |