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 |
||
| 21 | class Collection extends \samsoncms\api\query\Entity |
||
| 22 | { |
||
| 23 | /** Name of the items variable in index view */ |
||
| 24 | const ITEMS_VIEW_VARIABLE = 'items'; |
||
| 25 | |||
| 26 | /** Name of the item prefix for variable in item view */ |
||
| 27 | const ITEM_VIEW_VARIABLE = 'item'; |
||
| 28 | |||
| 29 | /** @var string|callable Block view file or callback */ |
||
| 30 | protected $indexView; |
||
| 31 | |||
| 32 | /** @var string|callable Item view file or callback */ |
||
| 33 | protected $itemView ; |
||
| 34 | |||
| 35 | /** @var string|callable Empty view file or callback */ |
||
| 36 | protected $emptyView = 'www/empty'; |
||
| 37 | |||
| 38 | /** @var ViewInterface View render object */ |
||
| 39 | protected $renderer; |
||
| 40 | |||
| 41 | /** @var int Count of entities on one page */ |
||
| 42 | protected $pageSize; |
||
| 43 | |||
| 44 | /** @var int Current page number */ |
||
| 45 | protected $pageNumber; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Collection constructor. |
||
| 49 | * |
||
| 50 | * @param ViewInterface $renderer Instance for rendering views |
||
| 51 | * @param QueryInterface $query Instance for querying database |
||
| 52 | * @param string|null $locale Localization language |
||
| 53 | */ |
||
| 54 | public function __construct(ViewInterface $renderer, QueryInterface $query = null, $locale = null) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Set index view path. |
||
| 63 | * @param string|callable $indexView Index view path or callback |
||
| 64 | * @return $this Chaining |
||
| 65 | */ |
||
| 66 | public function indexView($indexView) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Set item view path. |
||
| 74 | * @param string|callable $itemView Item view path or callback |
||
| 75 | * @return $this Chaining |
||
| 76 | */ |
||
| 77 | public function itemView($itemView) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Set empty view path. |
||
| 86 | * @param string|callable $emptyView Empty view path or callback |
||
| 87 | * @return $this Chaining |
||
| 88 | */ |
||
| 89 | public function emptyView($emptyView) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Render Entity collection item. |
||
| 97 | * |
||
| 98 | * @param Entity $item SamsonCMS entity for rendering |
||
| 99 | * |
||
| 100 | * @return string Rendered HTML |
||
| 101 | */ |
||
| 102 | public function renderItem(Entity $item) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Render empty collection item. |
||
| 112 | * |
||
| 113 | * @return string Rendered HTML |
||
| 114 | */ |
||
| 115 | public function renderEmpty() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Render Entity collection index. |
||
| 122 | * |
||
| 123 | * @param string $items Collection of rendered items |
||
| 124 | * |
||
| 125 | * @return string Rendered HTML |
||
| 126 | */ |
||
| 127 | public function renderIndex($items) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Set pagination for SamsonCMS query. |
||
| 136 | * |
||
| 137 | * @param int $pageNumber Result page number |
||
| 138 | * @param int|null $pageSize Results page size |
||
| 139 | * @return $this Chaining |
||
| 140 | */ |
||
| 141 | public function pager($pageNumber, $pageSize = null) |
||
| 148 | |||
| 149 | /** @return string Rendered HTML for fields table */ |
||
| 150 | public function output() |
||
| 183 | } |
||
| 184 |
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: