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 |
||
10 | class Deals extends PaginatedListResource |
||
11 | { |
||
12 | /** {@inheritdoc} */ |
||
13 | protected function getEndpoint() |
||
17 | |||
18 | /** |
||
19 | * @param int $page |
||
20 | * @param DealStage $stage defaults to DealStage::INCOMING |
||
|
|||
21 | * |
||
22 | * @return Page |
||
23 | */ |
||
24 | View Code Duplication | public function all($page = 1, DealStage $stage = null) |
|
33 | |||
34 | /** {@inheritdoc} */ |
||
35 | View Code Duplication | public function create(DetachedResource $resource, array $fieldNames = [], $useKey = true) |
|
50 | } |
||
51 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.