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 |
||
| 27 | class Member extends HttpApi |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Returns a paginated list of members of the mailing list. |
||
| 31 | * |
||
| 32 | * @param string $address Address of the mailing list |
||
| 33 | * @param int $limit Maximum number of records to return (optional: 100 by default) |
||
| 34 | * @param bool|null $subscribed `true` to lists subscribed, `false` for unsubscribed. list all if null |
||
| 35 | * |
||
| 36 | * @return IndexResponse |
||
| 37 | * |
||
| 38 | * @throws \Exception |
||
| 39 | */ |
||
| 40 | 3 | public function index(string $address, int $limit = 100, bool $subscribed = null) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Shows a single member of the mailing list. |
||
| 62 | * |
||
| 63 | * @param string $list Address of the mailing list |
||
| 64 | * @param string $address Address of the member |
||
| 65 | * |
||
| 66 | * @return ShowResponse |
||
| 67 | * |
||
| 68 | * @throws \Exception |
||
| 69 | */ |
||
| 70 | public function show(string $list, string $address) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Creates (or updates) a member of the mailing list. |
||
| 82 | * |
||
| 83 | * @param string $list Address of the mailing list |
||
| 84 | * @param string $address Address for the member |
||
| 85 | * @param string $name Name for the member (optional) |
||
| 86 | * @param array $vars Array of field => value pairs to store additional data |
||
| 87 | * @param bool $subscribed `true` to add as subscribed (default), `false` as unsubscribed |
||
| 88 | * @param bool $upsert `true` to update member if present, `false` to raise error in case of a duplicate member (default) |
||
| 89 | * |
||
| 90 | * @return CreateResponse |
||
| 91 | * |
||
| 92 | * @throws \Exception |
||
| 93 | */ |
||
| 94 | 3 | public function create(string $list, string $address, string $name = null, array $vars = [], bool $subscribed = true, bool $upsert = false) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Adds multiple members (up to 1000) to the mailing list. |
||
| 118 | * |
||
| 119 | * @param string $list Address of the mailing list |
||
| 120 | * @param array $members Array of members, each item should be either a single string address or an array of member properties |
||
| 121 | * @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates |
||
| 122 | * |
||
| 123 | * @return UpdateResponse |
||
| 124 | * |
||
| 125 | * @throws \Exception |
||
| 126 | */ |
||
| 127 | 3 | public function createMultiple(string $list, array $members, $upsert = false) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * Updates a member on the mailing list. |
||
| 182 | * |
||
| 183 | * @param string $list Address of the mailing list |
||
| 184 | * @param string $address Address of the member |
||
| 185 | * @param array $parameters Array of key => value pairs to update |
||
| 186 | * |
||
| 187 | * @return UpdateResponse |
||
| 188 | * |
||
| 189 | * @throws \Exception |
||
| 190 | */ |
||
| 191 | 2 | public function update(string $list, string $address, array $parameters = []) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Removes a member from the mailing list. |
||
| 231 | * |
||
| 232 | * @param string $list Address of the mailing list |
||
| 233 | * @param string $address Address of the member |
||
| 234 | * |
||
| 235 | * @return DeleteResponse |
||
| 236 | * |
||
| 237 | * @throws \Exception |
||
| 238 | */ |
||
| 239 | 1 | View Code Duplication | public function delete(string $list, string $address) |
| 248 | } |
||
| 249 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.