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