Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 38 | 1 | class FlashNotifier extends Nette\Object |
|
| 39 | { |
||
| 40 | /** |
||
| 41 | * @var Storage\IStorage |
||
| 42 | */ |
||
| 43 | protected $storage; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var Localization\ITranslator |
||
| 47 | */ |
||
| 48 | protected $translator; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param Storage\IStorage $storage |
||
| 52 | * @param Localization\ITranslator $translator |
||
| 53 | */ |
||
| 54 | public function __construct( |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Flash a success message |
||
| 64 | * |
||
| 65 | * @param string $message |
||
| 66 | * @param string|NULL $title |
||
| 67 | * |
||
| 68 | * @return Entities\IMessage |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function success($message, $title = NULL) : Entities\IMessage |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Flash an information message |
||
| 80 | * |
||
| 81 | * @param string $message |
||
| 82 | * @param string|NULL $title |
||
| 83 | * |
||
| 84 | * @return Entities\IMessage |
||
| 85 | */ |
||
| 86 | View Code Duplication | public function info($message, $title = NULL) : Entities\IMessage |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Flash a warning message |
||
| 96 | * |
||
| 97 | * @param string $message |
||
| 98 | * @param string|NULL $title |
||
| 99 | * |
||
| 100 | * @return Entities\IMessage |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function warning($message, $title = NULL) : Entities\IMessage |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Flash an error message |
||
| 112 | * |
||
| 113 | * @param string $message |
||
| 114 | * @param string|NULL $title |
||
| 115 | * |
||
| 116 | * @return Entities\IMessage |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function error($message, $title = NULL) : Entities\IMessage |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Add an "important" flash to the session |
||
| 128 | * |
||
| 129 | * @return void |
||
| 130 | */ |
||
| 131 | public function important() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Flash an overlay modal |
||
| 138 | * |
||
| 139 | * @param string $message |
||
| 140 | * @param string|NULL $title |
||
| 141 | * |
||
| 142 | * @return Entities\IMessage |
||
| 143 | */ |
||
| 144 | public function overlay($message, $title = NULL) : Entities\IMessage |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param string $message |
||
| 163 | * @param string $level |
||
| 164 | * @param string|NULL $title |
||
| 165 | * @param boolean $overlay |
||
| 166 | * @param int|NULL $count |
||
| 167 | * @param array $parameters |
||
| 168 | * |
||
| 169 | * @return Entities\IMessage |
||
| 170 | */ |
||
| 171 | public function message($message, $level = 'info', $title = NULL, $overlay = FALSE, $count = NULL, array $parameters = []) : Entities\IMessage |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Flash a general message |
||
| 178 | * |
||
| 179 | * @param string $message |
||
| 180 | * @param string $level |
||
| 181 | * @param string|NULL $title |
||
| 182 | * @param boolean $overlay |
||
| 183 | * @param int|NULL $count |
||
| 184 | * @param array $parameters |
||
| 185 | * |
||
| 186 | * @return Entities\IMessage |
||
| 187 | */ |
||
| 188 | public function setMessage($message, $level = 'info', $title = NULL, $overlay = FALSE, $count = NULL, array $parameters = []) : Entities\IMessage |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @param Entities\IMessage $flash |
||
| 255 | * @param Entities\IMessage[] $messages |
||
| 256 | * |
||
| 257 | * @return bool |
||
| 258 | */ |
||
| 259 | private function checkUnique(Entities\IMessage $flash, array $messages) : bool |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param array $attributes |
||
| 272 | * @param string $type |
||
| 273 | * @param mixed $default |
||
| 274 | * |
||
| 275 | * @return mixed |
||
| 276 | */ |
||
| 277 | private function checkForAttribute(array $attributes, string $type, $default) |
||
| 311 | } |
||
| 312 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.