| Total Complexity | 9 |
| Total Lines | 81 |
| Duplicated Lines | 100 % |
| Changes | 0 | ||
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 |
||
| 12 | class InputStreamReader |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var InputStream 入力ストリーム |
||
| 16 | */ |
||
| 17 | protected $stream; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * constructor |
||
| 21 | * @param InputStream $stream 入力ストリーム |
||
| 22 | */ |
||
| 23 | public function __construct(InputStream $stream) |
||
| 24 | { |
||
| 25 | $this->stream = $stream; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * destructor |
||
| 30 | */ |
||
| 31 | public function __destruct() |
||
| 32 | { |
||
| 33 | $this->close(); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * 読み込んでいる入力ストリームを閉じる |
||
| 38 | */ |
||
| 39 | public function close() |
||
| 40 | { |
||
| 41 | $this->stream->close(); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * 入力ストリームからデータを読み込む |
||
| 46 | * @return string 読み込みデータ |
||
| 47 | */ |
||
| 48 | public function read() |
||
| 49 | { |
||
| 50 | $args = func_get_args(); |
||
| 51 | $length = count($args) === 1 ? $args[0] : null; |
||
| 52 | |||
| 53 | return $this->stream->read($length); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * 入力ストリームから行単位でデータを読み込む |
||
| 58 | * 末尾に改行コードは含まない |
||
| 59 | * @return string 読み込みデータ |
||
| 60 | */ |
||
| 61 | public function readLine() |
||
| 62 | { |
||
| 63 | return $this->stream->readLine(); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * 入力ストリームから指定バイト数後方へポインタを移動する |
||
| 68 | * @param int $pos 後方への移動バイト数(負数の場合は前方へ移動) |
||
| 69 | * @return int $skipNum 移動したバイト数、移動に失敗した場合-1 |
||
| 70 | */ |
||
| 71 | public function skip(int $pos) |
||
| 72 | { |
||
| 73 | return $this->stream->skip($pos); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * 最後にmarkされた位置に再配置する |
||
| 78 | * @throws IOException |
||
| 79 | */ |
||
| 80 | public function reset() |
||
| 81 | { |
||
| 82 | $this->stream->reset(); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * 入力ストリームの現在位置にmarkを設定する |
||
| 87 | * @param int マークするバイト位置 |
||
| 88 | * @throws IOException |
||
| 89 | */ |
||
| 90 | public function mark() |
||
| 91 | { |
||
| 92 | $this->stream->mark(); |
||
| 93 | } |
||
| 95 |