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 namespace Anomaly\Streams\Platform\Model; |
||
20 | class EloquentCriteria |
||
21 | { |
||
22 | |||
23 | use Hookable; |
||
24 | use DispatchesJobs; |
||
25 | |||
26 | /** |
||
27 | * Safe builder methods. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $disabled = [ |
||
32 | 'delete', |
||
33 | 'update', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * The query builder. |
||
38 | * |
||
39 | * @var Builder|\Illuminate\Database\Query\Builder |
||
40 | */ |
||
41 | protected $query; |
||
42 | |||
43 | /** |
||
44 | * Set the get method. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $method; |
||
49 | |||
50 | /** |
||
51 | * Create a new EntryCriteria instance. |
||
52 | * |
||
53 | * @param Builder $query |
||
54 | * @param string $method |
||
55 | */ |
||
56 | public function __construct(Builder $query, $method = 'get') |
||
61 | |||
62 | /** |
||
63 | * Get the paginated entries. |
||
64 | * |
||
65 | * @param array $columns |
||
66 | * @return Collection|Presenter|EntryPresenter |
||
67 | */ |
||
68 | public function paginate($perPage = 15, array $columns = ['*']) |
||
72 | |||
73 | /** |
||
74 | * Get the entries. |
||
75 | * |
||
76 | * @param array $columns |
||
77 | * @return Collection|Presenter|EntryPresenter |
||
78 | */ |
||
79 | public function get(array $columns = ['*']) |
||
83 | |||
84 | /** |
||
85 | * Get the aggregate sum. |
||
86 | * |
||
87 | * @param array $columns |
||
88 | * @return int |
||
89 | */ |
||
90 | public function sum(array $columns = ['*']) |
||
94 | |||
95 | /** |
||
96 | * Get the entry count. |
||
97 | * |
||
98 | * @param array $columns |
||
99 | * @return int |
||
100 | */ |
||
101 | public function count(array $columns = ['*']) |
||
105 | |||
106 | /** |
||
107 | * Find an entry. |
||
108 | * |
||
109 | * @param $identifier |
||
110 | * @param array $columns |
||
111 | * @return Presenter|EntryPresenter |
||
112 | */ |
||
113 | public function find($identifier, array $columns = ['*']) |
||
117 | |||
118 | /** |
||
119 | * Find an entry by column value. |
||
120 | * |
||
121 | * @param $column |
||
122 | * @param $value |
||
123 | * @param array $columns |
||
124 | * @return Presenter|EntryPresenter |
||
125 | */ |
||
126 | public function findBy($column, $value, array $columns = ['*']) |
||
132 | |||
133 | /** |
||
134 | * Return the first entry. |
||
135 | * |
||
136 | * @param array $columns |
||
137 | * @return EloquentModel|EntryInterface |
||
138 | */ |
||
139 | public function first(array $columns = ['*']) |
||
143 | |||
144 | /** |
||
145 | * Return whether the method is safe or not. |
||
146 | * |
||
147 | * @param $name |
||
148 | * @return bool |
||
149 | */ |
||
150 | protected function methodIsSafe($name) |
||
154 | |||
155 | /** |
||
156 | * Route through __call. |
||
157 | * |
||
158 | * @param $name |
||
159 | * @return Builder|null |
||
160 | */ |
||
161 | function __get($name) |
||
165 | |||
166 | /** |
||
167 | * Call the method on the query. |
||
168 | * |
||
169 | * @param $name |
||
170 | * @param $arguments |
||
171 | * @return Builder|null |
||
172 | */ |
||
173 | function __call($name, $arguments) |
||
201 | |||
202 | /** |
||
203 | * Return the string. |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | public function __toString() |
||
211 | } |
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: