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 |
||
| 19 | class FtpFilesystem extends Filesystem |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | public $host; |
||
| 25 | /** |
||
| 26 | * @var integer |
||
| 27 | */ |
||
| 28 | public $port; |
||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | public $username; |
||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | public $password; |
||
| 37 | /** |
||
| 38 | * @var boolean |
||
| 39 | */ |
||
| 40 | public $ssl; |
||
| 41 | /** |
||
| 42 | * @var integer |
||
| 43 | */ |
||
| 44 | public $timeout; |
||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | public $root; |
||
| 49 | /** |
||
| 50 | * @var integer |
||
| 51 | */ |
||
| 52 | public $permPrivate; |
||
| 53 | /** |
||
| 54 | * @var integer |
||
| 55 | */ |
||
| 56 | public $permPublic; |
||
| 57 | /** |
||
| 58 | * @var boolean |
||
| 59 | */ |
||
| 60 | public $passive; |
||
| 61 | /** |
||
| 62 | * @var integer |
||
| 63 | */ |
||
| 64 | public $transferMode; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @inheritdoc |
||
| 68 | */ |
||
| 69 | public function init() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return Ftp |
||
| 84 | */ |
||
| 85 | View Code Duplication | protected function prepareAdapter() |
|
| 109 | } |
||
| 110 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.