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 |
||
| 6 | class Tickets extends Resource |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @param array $ticket Array of deal properties. |
||
| 10 | * @return mixed |
||
| 11 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 12 | */ |
||
| 13 | function create(array $ticket) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param int $id The deal id. |
||
| 24 | * @param array $ticket The deal properties to update. |
||
| 25 | * @return mixed |
||
| 26 | */ |
||
| 27 | function update($id, array $ticket) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param array $params |
||
| 38 | * |
||
| 39 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 40 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 41 | */ |
||
| 42 | View Code Duplication | function getAll(array $params = []){ |
|
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * @param int $id |
||
| 53 | * @return mixed |
||
| 54 | */ |
||
| 55 | function delete($id) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param int $id |
||
| 64 | * @return mixed |
||
| 65 | */ |
||
| 66 | function getById($id) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param array $params Optional parameters ['timestamp', 'changeType', 'objectId'] |
||
| 75 | * @return mixed |
||
| 76 | */ |
||
| 77 | View Code Duplication | function getChangelog(array $params = []) |
|
| 84 | |||
| 85 | } |
||
| 86 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.