| Conditions | 12 |
| Paths | 4 |
| Total Lines | 42 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 76 | public function purge_step($old_state) |
||
| 77 | { |
||
| 78 | global $phpbb_root_path; |
||
| 79 | |||
| 80 | $database = $phpbb_root_path . 'store/messenger.db'; |
||
| 81 | if (is_file($database)) { |
||
| 82 | unlink($database); |
||
| 83 | } |
||
| 84 | |||
| 85 | $messengerDir = $phpbb_root_path . 'store/messenger'; |
||
| 86 | if (is_dir($messengerDir)) { |
||
| 87 | $objects = scandir($messengerDir); |
||
| 88 | foreach ($objects as $object) { |
||
| 89 | if ($object != '.' && $object != '..') { |
||
| 90 | if (filetype($messengerDir . "/" . $object) == "dir") { |
||
| 91 | $dir = $messengerDir . "/" . $object; |
||
| 92 | $subObjects = scandir($dir); |
||
| 93 | if(count($subObjects) > 0) { |
||
| 94 | foreach($subObjects as $subObject) { |
||
| 95 | if($subObject != '.' && $subObject != '..') { |
||
| 96 | if(filetype($dir . '/' . $subObject) != 'dir') { |
||
| 97 | unlink($dir . '/' . $subObject); |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | } |
||
| 105 | rmdir($messengerDir . "/" . $object); |
||
| 106 | } else { |
||
| 107 | unlink($messengerDir . "/" . $object); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | reset($objects); |
||
| 112 | rmdir($messengerDir); |
||
| 113 | } |
||
| 114 | |||
| 115 | return parent::purge_step($old_state); |
||
| 116 | |||
| 117 | } |
||
| 118 | |||
| 120 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state