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 |
||
| 35 | class FlashNotifier extends Nette\Object |
||
| 36 | 1 | { |
|
| 37 | /** |
||
| 38 | * @var SessionStorage |
||
| 39 | */ |
||
| 40 | protected $sessionStorage; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var Localization\ITranslator |
||
| 44 | */ |
||
| 45 | protected $translator; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param SessionStorage $sessionStorage |
||
| 49 | * @param Localization\ITranslator $translator |
||
| 50 | */ |
||
| 51 | public function __construct(SessionStorage $sessionStorage, Localization\ITranslator $translator = NULL) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Flash a success message |
||
| 59 | * |
||
| 60 | 1 | * @param string $message |
|
| 61 | * @param string|null $title |
||
| 62 | * |
||
| 63 | * @return Entities\IMessage |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function success($message, $title = NULL) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Flash an information message |
||
| 75 | 1 | * |
|
| 76 | * @param string $message |
||
| 77 | * @param string|null $title |
||
| 78 | * |
||
| 79 | * @return Entities\IMessage |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function info($message, $title = NULL) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * Flash a warning message |
||
| 91 | * |
||
| 92 | * @param string $message |
||
| 93 | * @param string|null $title |
||
| 94 | * |
||
| 95 | * @return Entities\IMessage |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function warning($message, $title = NULL) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Flash an error message |
||
| 107 | * |
||
| 108 | * @param string $message |
||
| 109 | * @param string|null $title |
||
| 110 | * |
||
| 111 | * @return Entities\IMessage |
||
| 112 | */ |
||
| 113 | View Code Duplication | public function error($message, $title = NULL) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Add an "important" flash to the session |
||
| 123 | * |
||
| 124 | * @return $this |
||
| 125 | */ |
||
| 126 | public function important() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Flash an overlay modal |
||
| 135 | * |
||
| 136 | * @param string $message |
||
| 137 | * @param string $title |
||
| 138 | * |
||
| 139 | * @return Entities\IMessage |
||
| 140 | */ |
||
| 141 | public function overlay($message, $title = NULL) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param string $message |
||
| 160 | * @param string $level |
||
| 161 | * @param string $title |
||
| 162 | * @param boolean $overlay |
||
| 163 | * @param int|null $count |
||
| 164 | * @param array $parameters |
||
| 165 | * |
||
| 166 | * @return Entities\IMessage |
||
| 167 | */ |
||
| 168 | public function message($message, $level = 'info', $title = NULL, $overlay = FALSE, $count = NULL, array $parameters = []) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Flash a general message |
||
| 175 | * |
||
| 176 | * @param string $message |
||
| 177 | * @param string $level |
||
| 178 | * @param string $title |
||
| 179 | * @param boolean $overlay |
||
| 180 | * @param int|null $count |
||
| 181 | * @param array $parameters |
||
| 182 | * |
||
| 183 | * @return Entities\IMessage |
||
| 184 | */ |
||
| 185 | public function setMessage($message, $level = 'info', $title = NULL, $overlay = FALSE, $count = NULL, array $parameters = []) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param Entities\IMessage $flash |
||
| 252 | * @param Entities\IMessage[] $messages |
||
| 253 | * |
||
| 254 | * @return bool |
||
| 255 | */ |
||
| 256 | private function checkUnique(Entities\IMessage $flash, array $messages) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param array $attributes |
||
| 269 | * @param string $type |
||
| 270 | * @param mixed $default |
||
| 271 | * |
||
| 272 | * @return mixed |
||
| 273 | */ |
||
| 274 | private function checkForAttribute(array $attributes, $type, $default) |
||
| 308 | } |
||
| 309 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.