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