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 |
||
| 20 | class Search extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Search issues. |
||
| 24 | * |
||
| 25 | * @param string $owner The name of the owner of the repository. |
||
| 26 | * @param string $repo The name of the repository. |
||
| 27 | * @param string $state The state - open or closed. |
||
| 28 | * @param string $keyword The search term. |
||
| 29 | * |
||
| 30 | * @return object |
||
| 31 | * |
||
| 32 | * @since 1.0 |
||
| 33 | * @throws \UnexpectedValueException |
||
| 34 | * @deprecated The legacy API is deprecated |
||
| 35 | */ |
||
| 36 | public function issues($owner, $repo, $state, $keyword) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Search repositories. |
||
| 54 | * |
||
| 55 | * Find repositories by keyword. Note, this legacy method does not follow |
||
| 56 | * the v3 pagination pattern. |
||
| 57 | * This method returns up to 100 results per page and pages can be fetched |
||
| 58 | * using the start_page parameter. |
||
| 59 | * |
||
| 60 | * @param string $keyword The search term. |
||
| 61 | * @param string $language Filter results by language https://github.com/languages |
||
| 62 | * @param integer $startPage Page number to fetch |
||
| 63 | * |
||
| 64 | * @return object |
||
| 65 | * |
||
| 66 | * @since 1.0 |
||
| 67 | * @deprecated The legacy API is deprecated |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function repositories($keyword, $language = '', $startPage = 0) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Search users. |
||
| 85 | * |
||
| 86 | * Find users by keyword. |
||
| 87 | * |
||
| 88 | * @param string $keyword The search term. |
||
| 89 | * @param integer $startPage Page number to fetch |
||
| 90 | * |
||
| 91 | * @return object |
||
| 92 | * |
||
| 93 | * @since 1.0 |
||
| 94 | * @deprecated The legacy API is deprecated |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function users($keyword, $startPage = 0) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Email search. |
||
| 111 | * |
||
| 112 | * This API call is added for compatibility reasons only. There’s no guarantee |
||
| 113 | * that full email searches will always be available. The @ character in the |
||
| 114 | * address must be left unencoded. Searches only against public email addresses |
||
| 115 | * (as configured on the user’s GitHub profile). |
||
| 116 | * |
||
| 117 | * @param string $email The email address(es). |
||
| 118 | * |
||
| 119 | * @return object |
||
| 120 | * |
||
| 121 | * @since 1.0 |
||
| 122 | * @deprecated The legacy API is deprecated |
||
| 123 | */ |
||
| 124 | public function email($email) |
||
| 134 | } |
||
| 135 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.