Completed
Push — master ( 4ee661...cccce7 )
by Ryuichi
03:25 queued 01:53
created

FileReader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 30
loc 30
rs 10
c 0
b 0
f 0
wmc 3

How to fix   Duplicated Code   

Duplicated Code

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
2
namespace WebStream\IO\Reader;
3
4
use WebStream\IO\FileInputStream;
5
6
/**
7
 * FileReader
8
 * @author Ryuichi TANAKA.
9
 * @since 2016/02/05
10
 * @version 0.7
11
 */
12
class FileReader extends InputStreamReader
13
{
14
    /**
15
     * @var int バッファリングサイズ
16
     */
17
    private $bufferSize;
18
19
    /**
20
     * constructor
21
     * @param mixed $file ファイルオブジェクトまたはファイルパス
22
     * @param int $bufferSize バッファリングサイズ
23
     */
24
    public function __construct($file, int $bufferSize = 8192)
25
    {
26
        parent::__construct(new FileInputStream($file));
27
        $this->bufferSize = $bufferSize;
28
    }
29
30
    /**
31
     * ファイルを読み込む
32
     * @return string ファイル内容
33
     */
34
    public function read()
35
    {
36
        $out = "";
37
        while (($data = $this->stream->read($this->bufferSize)) !== null) {
38
            $out .= $data;
39
        }
40
41
        return $out;
42
    }
43
}
44