| Conditions | 13 |
| Paths | 25 |
| Total Lines | 52 |
| 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 |
||
| 32 | public function run($request) |
||
| 33 | { |
||
| 34 | ini_set('max_execution_time', 3000); |
||
| 35 | $tables = DB::query('SHOW tables'); |
||
| 36 | $unique = array(); |
||
|
|
|||
| 37 | $arrayOfReplacements = Config::inst()->get("DataIntegrityTestUTF8", "replacement_array"); |
||
| 38 | foreach ($tables as $table) { |
||
| 39 | $table = array_pop($table); |
||
| 40 | DB::query("ALTER TABLE \"$table\" CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"); |
||
| 41 | DB::alteration_message("<h2>Resetting $table to utf8</h2>"); |
||
| 42 | $this->flushNow(); |
||
| 43 | $originatingClass = str_replace("_Live", "", $table); |
||
| 44 | if (class_exists($originatingClass) && !class_exists($table)) { |
||
| 45 | } else { |
||
| 46 | $originatingClass = $table; |
||
| 47 | } |
||
| 48 | if (class_exists($originatingClass)) { |
||
| 49 | $fields = Config::inst()->get($originatingClass, "db", $uninherited = 1); |
||
| 50 | if ($fields && count($fields)) { |
||
| 51 | $unusedFields = array(); |
||
| 52 | foreach ($fields as $fieldName => $type) { |
||
| 53 | $usedFieldsChanged = array("CHECKING $table.$fieldName : "); |
||
| 54 | if (substr($type, 0, 4) == "HTML") { |
||
| 55 | foreach ($arrayOfReplacements as $from => $to) { |
||
| 56 | DB::query("UPDATE \"$table\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '$from', '$to');"); |
||
| 57 | $count = DB::getConn()->affectedRows(); |
||
| 58 | $toWord = $to; |
||
| 59 | if ($to == '') { |
||
| 60 | $toWord = '[NOTHING]'; |
||
| 61 | } |
||
| 62 | $usedFieldsChanged[] = "$count Replacements <strong>$from</strong> with <strong>$toWord</strong>"; |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | $unusedFields[] = $fieldName; |
||
| 66 | } |
||
| 67 | if (count($usedFieldsChanged)) { |
||
| 68 | DB::alteration_message(implode("<br /> - ", $usedFieldsChanged)); |
||
| 69 | $this->flushNow(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | if (count($unusedFields)) { |
||
| 73 | DB::alteration_message("Skipped the following fields: ".implode(",", $unusedFields)); |
||
| 74 | } |
||
| 75 | } else { |
||
| 76 | DB::alteration_message("No fields for $originatingClass"); |
||
| 77 | } |
||
| 78 | } else { |
||
| 79 | DB::alteration_message("Skipping $originatingClass - class can not be found"); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | DB::alteration_message("<hr /><hr /><hr /><hr /><hr /><hr /><hr />COMPLETED<hr /><hr /><hr /><hr /><hr /><hr /><hr />"); |
||
| 83 | } |
||
| 84 | |||
| 96 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.