| Conditions | 10 |
| Paths | 512 |
| Total Lines | 30 |
| Code Lines | 20 |
| 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 namespace EvolutionCMS\Legacy; |
||
| 32 | public function initAndWriteLog( |
||
| 33 | $msg = "", |
||
| 34 | $internalKey = "", |
||
| 35 | $username = "", |
||
| 36 | $action = "", |
||
| 37 | $itemid = "", |
||
| 38 | $itemname = "" |
||
| 39 | ) { |
||
| 40 | $modx = evolutionCMS(); |
||
| 41 | $this->entry['msg'] = $msg; // writes testmessage to the object |
||
| 42 | $this->entry['action'] = empty($action) ? $modx->manager->action : $action; // writes the action to the object |
||
| 43 | |||
| 44 | // User Credentials |
||
| 45 | $this->entry['internalKey'] = $internalKey == "" ? $modx->getLoginUserID() : $internalKey; |
||
| 46 | $this->entry['username'] = $username == "" ? $modx->getLoginUserName() : $username; |
||
| 47 | |||
| 48 | $this->entry['itemId'] = (empty($itemid) && isset($_REQUEST['id'])) ? (int)$_REQUEST['id'] : $itemid; // writes the id to the object |
||
| 49 | if ($this->entry['itemId'] == 0) { |
||
| 50 | $this->entry['itemId'] = "-"; |
||
| 51 | } // to stop items having id 0 |
||
| 52 | |||
| 53 | $this->entry['itemName'] = ($itemname == "" && isset($_SESSION['itemname'])) ? $_SESSION['itemname'] : $itemname; // writes the id to the object |
||
| 54 | if ($this->entry['itemName'] == "") { |
||
| 55 | $this->entry['itemName'] = "-"; |
||
| 56 | } // to stop item name being empty |
||
| 57 | |||
| 58 | $this->writeToLog(); |
||
| 59 | |||
| 60 | return; |
||
| 61 | } |
||
| 62 | |||
| 123 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: