| Conditions | 12 |
| Paths | 126 |
| Total Lines | 68 |
| Code Lines | 35 |
| 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 |
||
| 54 | public static function handle_manipulation($manipulation) |
||
| 55 | { |
||
| 56 | // First, extract any state that is in the manipulation itself |
||
| 57 | foreach ($manipulation as $table => $details) { |
||
| 58 | if (!isset($manipulation[$table]['class'])) { |
||
| 59 | $manipulation[$table]['class'] = DataObject::getSchema()->tableClass($table); |
||
| 60 | } |
||
| 61 | $manipulation[$table]['state'] = array(); |
||
| 62 | } |
||
| 63 | |||
| 64 | SearchVariant::call('extractManipulationState', $manipulation); |
||
| 65 | |||
| 66 | // Then combine the manipulation back into object field sets |
||
| 67 | |||
| 68 | $writes = array(); |
||
| 69 | |||
| 70 | foreach ($manipulation as $table => $details) { |
||
| 71 | if (!isset($details['id'])) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $id = $details['id']; |
||
| 76 | $state = $details['state']; |
||
| 77 | $class = $details['class']; |
||
| 78 | $command = $details['command']; |
||
| 79 | $fields = isset($details['fields']) ? $details['fields'] : array(); |
||
| 80 | |||
| 81 | $base = DataObject::getSchema()->baseDataClass($class); |
||
| 82 | $key = "$id:$base:".serialize($state); |
||
| 83 | |||
| 84 | $statefulids = array(array('id' => $id, 'state' => $state)); |
||
| 85 | |||
| 86 | // Is this the first table for this particular object? Then add an item to $writes |
||
| 87 | if (!isset($writes[$key])) { |
||
| 88 | $writes[$key] = array( |
||
| 89 | 'base' => $base, |
||
| 90 | 'class' => $class, |
||
| 91 | 'id' => $id, |
||
| 92 | 'statefulids' => $statefulids, |
||
| 93 | 'command' => $command, |
||
| 94 | 'fields' => array() |
||
| 95 | ); |
||
| 96 | } // Otherwise update the class label if it's more specific than the currently recorded one |
||
| 97 | elseif (is_subclass_of($class, $writes[$key]['class'])) { |
||
| 98 | $writes[$key]['class'] = $class; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Update the fields |
||
| 102 | foreach ($fields as $field => $value) { |
||
| 103 | $writes[$key]['fields']["$class:$field"] = $value; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | // Trim non-delete records without fields |
||
| 108 | foreach (array_keys($writes) as $key) { |
||
| 109 | if ($writes[$key]['command'] !== 'delete' && empty($writes[$key]['fields'])) { |
||
| 110 | unset($writes[$key]); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | // Then extract any state that is needed for the writes |
||
| 115 | |||
| 116 | SearchVariant::call('extractManipulationWriteState', $writes); |
||
| 117 | |||
| 118 | // Submit all of these writes to the search processor |
||
| 119 | |||
| 120 | static::process_writes($writes); |
||
| 121 | } |
||
| 122 | |||
| 180 |
This check marks private properties in classes that are never used. Those properties can be removed.