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 |
||
23 | class FieldsTable extends \samsoncms\api\field\Table implements RenderInterface |
||
24 | { |
||
25 | /** Name of the rows variable in index view */ |
||
26 | const ROWS_VIEW_VARIABLE = 'rows'; |
||
27 | |||
28 | /** Name of the row prefix for variable in row view */ |
||
29 | const ROW_VIEW_VARIABLE = 'row'; |
||
30 | |||
31 | /** @var string|callable Block view file or callback */ |
||
32 | protected $indexView = 'index'; |
||
33 | |||
34 | /** @var string|callable Row view file or callback */ |
||
35 | protected $rowView = 'row'; |
||
36 | |||
37 | /** @var ViewInterface */ |
||
38 | protected $renderer; |
||
39 | |||
40 | /** |
||
41 | * GeneralInfo constructor. |
||
42 | * |
||
43 | * @param QueryInterface $query |
||
44 | * @param ViewInterface $renderer |
||
45 | * @param int[] $navigationID Collection of entity navigation identifiers |
||
46 | * @param int $entityID Entity identifier |
||
47 | * @param string|null $locale Table localization |
||
48 | */ |
||
49 | public function __construct(QueryInterface $query, ViewInterface $renderer, $navigationID, $entityID, $locale = null) |
||
56 | |||
57 | /** |
||
58 | * Set index view path. |
||
59 | * @param string|callable $indexView Index view path or callback |
||
60 | * @return $this Chaining |
||
61 | */ |
||
62 | public function indexView($indexView) |
||
67 | /** |
||
68 | * Set row view path. |
||
69 | * @param string|callable $rowView Row view path or callback |
||
70 | * @return $this Chaining |
||
71 | */ |
||
72 | public function rowView($rowView) |
||
77 | |||
78 | /** |
||
79 | * Render table row. |
||
80 | * |
||
81 | * @param Row $row Collection of column values. |
||
82 | * |
||
83 | * @return string Rendered HTML |
||
84 | */ |
||
85 | public function renderRow(Row $row) |
||
89 | |||
90 | /** |
||
91 | * Render table row. |
||
92 | * |
||
93 | * @param string $items Collection of rendered rows. |
||
94 | * |
||
95 | * @return string Rendered HTML |
||
96 | */ |
||
97 | public function renderIndex($items) |
||
103 | |||
104 | /** @return string Rendered HTML for fields table */ |
||
105 | public function render() |
||
126 | |||
127 | /** |
||
128 | * Prepare fields table for rendering in the view. |
||
129 | * |
||
130 | * @param string|null $prefix Prefix to be added to view variables |
||
131 | * @param array $restricted Collection of fields to be restricted |
||
132 | * |
||
133 | * @return array Collection of view variables for rendering |
||
134 | */ |
||
135 | public function toView($prefix = null, array $restricted = array()) |
||
139 | } |
||
140 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: