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 namespace Anomaly\Streams\Platform\Entry; |
||
| 15 | class EntryPresenter extends EloquentPresenter |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The resource object. |
||
| 20 | * This is for IDE hinting. |
||
| 21 | * |
||
| 22 | * @var EntryInterface|EloquentModel |
||
| 23 | */ |
||
| 24 | protected $object; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Return the date string for created at. |
||
| 28 | * |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public function createdAtDate() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Return the datetime string for created at. |
||
| 40 | * |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | public function createdAtDatetime() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Return the date string for updated at. |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | public function updatedAtDate() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Return the datetime string for updated at. |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | public function updatedAtDatetime() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Return a label. |
||
| 76 | * |
||
| 77 | * @param $text |
||
| 78 | * @param string $context |
||
| 79 | * @param string $size |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function label($text = null, $context = null, $size = null) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Return the edit URL. |
||
| 110 | * |
||
| 111 | * @return string |
||
| 112 | */ |
||
| 113 | View Code Duplication | public function editUrl() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Return the edit link. |
||
| 135 | * |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | public function editLink() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Return the view URL. |
||
| 145 | * |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | View Code Duplication | public function viewUrl() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Return the view link. |
||
| 170 | * |
||
| 171 | * @return string |
||
| 172 | */ |
||
| 173 | public function viewLink() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * When accessing a property of a decorated entry |
||
| 180 | * object first check to see if the key represents |
||
| 181 | * a streams field. If it does then return the field |
||
| 182 | * type's presenter object. Otherwise handle normally. |
||
| 183 | * |
||
| 184 | * @param $key |
||
| 185 | * @return mixed |
||
| 186 | */ |
||
| 187 | public function __get($key) |
||
| 213 | } |
||
| 214 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: