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 |
||
| 17 | class AppConfig { |
||
| 18 | |||
| 19 | private $defaults = [ |
||
| 20 | 'wopi_url' => '', |
||
| 21 | 'timeout' => 15, |
||
| 22 | 'watermark_text' => '{userId}', |
||
| 23 | 'watermark_allGroupsList' => [], |
||
| 24 | 'watermark_allTagsList' => [], |
||
| 25 | 'watermark_linkTagsList' => [], |
||
| 26 | |||
| 27 | ]; |
||
| 28 | |||
| 29 | const WATERMARK_APP_NAMESPACE = 'files'; |
||
| 30 | |||
| 31 | const APP_SETTING_TYPES = [ |
||
| 32 | 'watermark_allGroupsList' => 'array', |
||
| 33 | 'watermark_allTagsList' => 'array', |
||
| 34 | 'watermark_linkTagsList' => 'array' |
||
| 35 | ]; |
||
| 36 | |||
| 37 | /** @var IConfig */ |
||
| 38 | private $config; |
||
| 39 | |||
| 40 | public function __construct(IConfig $config) { |
||
| 43 | |||
| 44 | public function getAppNamespace($key) { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get a value by key |
||
| 53 | * @param string $key |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getAppValue($key) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param $key |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | public function getAppValueArray($key) { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Set a value by key |
||
| 78 | * @param string $key |
||
| 79 | * @param string $value |
||
| 80 | * @return void |
||
| 81 | */ |
||
| 82 | public function setAppValue($key, $value) { |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Get all app settings |
||
| 88 | * @return array |
||
| 89 | */ |
||
| 90 | public function getAppSettings() { |
||
| 109 | |||
| 110 | } |
||
| 111 |
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: