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 |
||
19 | class Series extends Controller |
||
20 | { |
||
21 | /** |
||
22 | * Behaviours implemented by the controller |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | public $implement = [ |
||
27 | FormController::class, |
||
28 | ListController::class, |
||
29 | RelationController::class |
||
30 | ]; |
||
31 | |||
32 | public $formConfig = 'config_form.yaml'; |
||
33 | public $listConfig = 'config_list.yaml'; |
||
34 | public $relationConfig = 'config_relation.yaml'; |
||
35 | |||
36 | /** |
||
37 | * Series constructor |
||
38 | */ |
||
39 | public function __construct() |
||
45 | |||
46 | /** |
||
47 | * Controller "update" action used for updating existing model records. |
||
48 | * This action takes a record identifier (primary key of the model) |
||
49 | * to locate the record used for sourcing the existing form values. |
||
50 | * |
||
51 | * @param int $recordId Record identifier |
||
|
|||
52 | * @param string $context Form context |
||
53 | * @return void |
||
54 | */ |
||
55 | View Code Duplication | public function update($recordId = null, $context = null) |
|
67 | |||
68 | /** |
||
69 | * Remove multiple tags |
||
70 | * |
||
71 | * @return mixed |
||
72 | */ |
||
73 | View Code Duplication | public function onBulkDelete() |
|
89 | } |
||
90 |
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.