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 |
||
7 | class Connection extends \Illuminate\Database\Connection |
||
8 | { |
||
9 | /** |
||
10 | * The Cassandra keyspace |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $keyspace; |
||
15 | |||
16 | /** |
||
17 | * The Cassandra cluster |
||
18 | * |
||
19 | * @var \Cassandra\Cluster |
||
20 | */ |
||
21 | protected $cluster; |
||
22 | |||
23 | /** |
||
24 | * The Cassandra connection handler. |
||
25 | * |
||
26 | * @var \Cassandra\Session |
||
27 | */ |
||
28 | protected $session; |
||
29 | |||
30 | /** |
||
31 | * Create a new database connection instance. |
||
32 | * |
||
33 | * @param array $config |
||
34 | */ |
||
35 | public function __construct(array $config) |
||
56 | |||
57 | /** |
||
58 | * Begin a fluent query against a database table. |
||
59 | * |
||
60 | * @param string $table |
||
61 | * @return Query\Builder |
||
62 | */ |
||
63 | public function table($table) |
||
71 | |||
72 | /** |
||
73 | * Get a schema builder instance for the connection. |
||
74 | * |
||
75 | * @return Schema\Builder |
||
76 | */ |
||
77 | public function getSchemaBuilder() |
||
81 | |||
82 | /** |
||
83 | * return Cassandra cluster. |
||
84 | * |
||
85 | * @return \Cassandra\Cluster |
||
86 | */ |
||
87 | public function getCassandraCluster() |
||
91 | |||
92 | /** |
||
93 | * return Cassandra Session. |
||
94 | * |
||
95 | * @return \Cassandra\Session |
||
96 | */ |
||
97 | public function getCassandraSession() |
||
101 | |||
102 | /** |
||
103 | * Return the Cassandra keyspace |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getKeyspace() |
||
111 | |||
112 | /** |
||
113 | * Create a new Cassandra cluster object. |
||
114 | * |
||
115 | * @param string $dsn |
||
116 | * @param array $config |
||
117 | * @param array $options |
||
118 | * @return \Cassandra\Cluster |
||
119 | */ |
||
120 | protected function createCluster($dsn, array $config, array $options) |
||
161 | |||
162 | /** |
||
163 | * Disconnect from the underlying Cassandra connection. |
||
164 | */ |
||
165 | public function disconnect() |
||
169 | |||
170 | /** |
||
171 | * Get the PDO driver name. |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getDriverName() |
||
179 | |||
180 | /** |
||
181 | * Run a select statement against the database. |
||
182 | * |
||
183 | * @param string $query |
||
184 | * @param array $bindings |
||
185 | * @param bool $useReadPdo |
||
186 | * @return array |
||
187 | */ |
||
188 | View Code Duplication | public function select($query, $bindings = [], $useReadPdo = true) |
|
200 | |||
201 | /** |
||
202 | * Execute an SQL statement and return the boolean result. |
||
203 | * |
||
204 | * @param string $query |
||
205 | * @param array $bindings |
||
206 | * @return bool |
||
207 | */ |
||
208 | View Code Duplication | public function statement($query, $bindings = []) |
|
220 | |||
221 | /** |
||
222 | * Because Cassandra is an eventually consistent database, it's not possible to obtain |
||
223 | * the affected count for statements so we're just going to return 0, based on the idea |
||
224 | * that if the query fails somehow, an exception will be thrown |
||
225 | * |
||
226 | * @param string $query |
||
227 | * @param array $bindings |
||
228 | * @return int |
||
229 | */ |
||
230 | View Code Duplication | public function affectingStatement($query, $bindings = []) |
|
244 | |||
245 | /** |
||
246 | * @inheritdoc |
||
247 | */ |
||
248 | protected function getDefaultPostProcessor() |
||
252 | |||
253 | /** |
||
254 | * @inheritdoc |
||
255 | */ |
||
256 | protected function getDefaultQueryGrammar() |
||
260 | |||
261 | /** |
||
262 | * @inheritdoc |
||
263 | */ |
||
264 | protected function getDefaultSchemaGrammar() |
||
268 | |||
269 | /** |
||
270 | * Dynamically pass methods to the connection. |
||
271 | * |
||
272 | * @param string $method |
||
273 | * @param array $parameters |
||
274 | * @return mixed |
||
275 | */ |
||
276 | public function __call($method, $parameters) |
||
280 | } |
||
281 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.