| Conditions | 10 |
| Paths | 15 |
| Total Lines | 40 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 66 | protected function summaryAndSearchableCheck() |
||
| 67 | { |
||
| 68 | $values = []; |
||
| 69 | //check all classes |
||
| 70 | foreach ($this->objectClassNames as $objectClassName) { |
||
| 71 | if (count($this->onlyRunFor) && ! in_array($objectClassName, $this->onlyRunFor, true)) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $summaryFields = Config::inst()->get($objectClassName, 'summary_fields'); |
||
| 76 | // $searchableFields = Config::inst()->get($objectClassName, 'searchable_fields'); |
||
| 77 | if (! empty($summaryFields)) { |
||
| 78 | $dbFields = array_keys(Config::inst()->get($objectClassName, 'db')); |
||
| 79 | if (count($dbFields) > 5) { |
||
| 80 | $recommended = array_intersect($dbFields, $summaryFields); |
||
| 81 | if (count($recommended) < 2) { |
||
| 82 | $recommended = $dbFields; |
||
| 83 | } |
||
| 84 | } else { |
||
| 85 | $recommended = $dbFields; |
||
| 86 | } |
||
| 87 | if (count($recommended) > 0) { |
||
| 88 | foreach ($recommended as $k => $v) { |
||
| 89 | if (in_array($v, $this->Config()->no_searchable_fields, true)) { |
||
| 90 | unset($recommended[$k]); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | $values[$objectClassName] = $objectClassName . ':' . |
||
| 94 | "\n searchable_fields:\n - " . |
||
| 95 | implode("\n - ", $recommended) |
||
| 96 | . "\n\n"; |
||
| 97 | $this->flushNow('... Error in ' . $objectClassName . ' there are summary fields, but no searchable fields', 'error'); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | // $this->flushNow('... OK', 'created'); |
||
| 101 | } |
||
| 102 | echo '<pre>'; |
||
| 103 | echo "\n# Autocreated from: Sunnysideup-MigrateData-Tasks-CheckDataObjectStatics\n\n"; |
||
| 104 | echo implode('', $values); |
||
| 105 | echo '</pre>'; |
||
| 106 | } |
||
| 108 |