| Conditions | 10 |
| Paths | 27 |
| Total Lines | 60 |
| Code Lines | 39 |
| 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 |
||
| 114 | public function humanizedChanges($from, $to) |
||
| 115 | { |
||
| 116 | if (!$from) { |
||
| 117 | return _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.UPLOADEDFILE', "Uploaded file"); |
||
| 118 | } |
||
| 119 | |||
| 120 | $fromRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $from); |
||
| 121 | $toRecord = Versioned::get_version($this->owner->class, $this->owner->ID, $to); |
||
| 122 | |||
| 123 | $diff = new DataDifferencer($fromRecord, $toRecord); |
||
| 124 | $changes = $diff->changedFieldNames(); |
||
| 125 | |||
| 126 | $k = array_search('LastEdited', $changes); |
||
| 127 | |||
| 128 | if ($k !== false) { |
||
| 129 | unset($changes[$k]); |
||
| 130 | } |
||
| 131 | |||
| 132 | $output = array(); |
||
| 133 | |||
| 134 | foreach ($changes as $change) { |
||
| 135 | $human = $change; |
||
| 136 | |||
| 137 | if ($change == "ParentID") { |
||
| 138 | // updated folder ID |
||
| 139 | $human = _t( |
||
| 140 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdminFile.MOVEDFOLDER', |
||
| 141 | "Moved file" |
||
| 142 | ); |
||
| 143 | } elseif ($change == 'Title') { |
||
| 144 | $human = _t( |
||
| 145 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdminFile.RENAMEDTITLE', |
||
| 146 | "Updated title to " |
||
| 147 | ) . $fromRecord->Title; |
||
| 148 | } elseif ($change == 'Name') { |
||
| 149 | $human = _t( |
||
| 150 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdminFile.RENAMEDFILE', |
||
| 151 | "Renamed file to " |
||
| 152 | ) . $fromRecord->Filename; |
||
| 153 | } elseif ($change == 'File') { |
||
| 154 | // check to make sure the files are actually different |
||
| 155 | if ($fromRecord->getHash() != $toRecord->getHash()) { |
||
| 156 | $human = _t( |
||
| 157 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdminFile.RENAMEDFILE', |
||
| 158 | "Replaced file" |
||
| 159 | ); |
||
| 160 | } else { |
||
| 161 | $human = false; |
||
| 162 | } |
||
| 163 | } else { |
||
| 164 | $human = false; |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($human) { |
||
| 168 | $output[] = $human; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | return implode(", ", $output); |
||
| 173 | } |
||
| 174 | |||
| 226 |
This check marks private properties in classes that are never used. Those properties can be removed.