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 |
||
| 10 | class StringInputStream extends InputStream |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var int 文字列長 |
||
| 14 | */ |
||
| 15 | private $length; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * construct |
||
| 19 | * @param string $str 文字列 |
||
| 20 | */ |
||
| 21 | public function __construct(string $str) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * 入力ストリームを閉じる |
||
| 33 | */ |
||
| 34 | public function close() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * 入力ストリームからデータを読み込む |
||
| 41 | * 引数に数値を指定した場合、指定数値バイトだけ読み込む |
||
| 42 | * @param int length 読み込みバイト数 |
||
| 43 | * @return string 読み込みデータ |
||
| 44 | */ |
||
| 45 | public function read($length = null) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function skip(int $pos) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * 入力ストリームの現在位置にmarkを設定する |
||
| 96 | */ |
||
| 97 | public function mark() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * 最後にmarkされた位置に再配置する |
||
| 104 | */ |
||
| 105 | public function reset() |
||
| 109 | |||
| 110 | public function eof() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * {@inheritdoc} |
||
| 117 | */ |
||
| 118 | public function isMarkSupported() |
||
| 122 | } |
||
| 123 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..