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 SessionCacheEngine implements CacheEngineInterface |
||
8 | { |
||
9 | |||
10 | protected $prefix = null; |
||
11 | |||
12 | /** |
||
13 | * SessionCacheEngine constructor. |
||
14 | * |
||
15 | * @param string $prefix |
||
16 | */ |
||
17 | public function __construct($prefix = 'cache') |
||
21 | |||
22 | |||
23 | protected function checkSession() |
||
29 | |||
30 | protected function keyName($key) |
||
34 | |||
35 | public function append($key, $str) |
||
48 | |||
49 | View Code Duplication | public function get($key, $ttl = 0) |
|
61 | |||
62 | public function lock($key) |
||
68 | |||
69 | View Code Duplication | public function release($key) |
|
79 | |||
80 | public function set($key, $object, $ttl = 0) |
||
87 | |||
88 | public function unlock($key) |
||
94 | |||
95 | public function isAvailable() |
||
104 | } |
||
105 |
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: