Completed
Push — master ( 2e5bdd...9e2471 )
by Ryuichi
05:26
created

FileReader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
cbo 3
dl 0
loc 32
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
lcom 1
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