InputStream::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebStream\IO;
3
4
use WebStream\Exception\Extend\IOException;
5
6
/**
7
 * InputStream
8
 * ftellの戻り値仕様により32ビット数値を返すため2GB以上のファイルを読み込むと動かなくなる
9
 * C言語のftell仕様依存
10
 * @author Ryuichi TANAKA.
11
 * @since 2016/02/05
12
 * @version 0.7
13
 */
14
abstract class InputStream
15
{
16
    /**
17
     * @var mixed 入力ストリーム
18
     */
19
    protected $stream;
20
21
    /**
22
     * @var int 現在のポインタ位置
23
     */
24
    protected $cursorPosition;
25
26
    /**
27
     * @var int markしたポインタ位置
28
     */
29
    protected $markedPosition;
30
31
    /**
32
     * constructor
33
     * @param mixed $stream 入力ストリーム
34
     */
35
    public function __construct($stream)
36
    {
37
        $this->stream = $stream;
38
        $this->cursorPosition = 0;
39
        $this->markedPosition = 0;
40
    }
41
42
    /**
43
     * destructor
44
     */
45
    public function __destruct()
46
    {
47
        $this->close();
48
    }
49
50
    /**
51
     * 入力ストリームを閉じる
52
     */
53
    abstract public function close();
54
55
    /**
56
     * 入力ストリームからデータを読み込む
57
     * 引数に数値を指定した場合、指定数値バイトだけ読み込む
58
     * @param int length 読み込みバイト数
0 ignored issues
show
Bug introduced by
The type WebStream\IO\length was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
     * @return string 読み込みデータ
60
     * @throws InvalidArgumentException
61
     * @throws IOException
62
     */
63
    abstract public function read($length = null);
64
65
    /**
66
     * 入力ストリームから指定バイト数後方へポインタを移動する
67
     * @param int $pos 後方への移動バイト数(負数の場合は前方へ移動)
68
     * @return int $skipNum 移動したバイト数、移動に失敗した場合-1
69
     */
70
    public function skip(int $pos)
0 ignored issues
show
Unused Code introduced by
The parameter $pos is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
    public function skip(/** @scrutinizer ignore-unused */ int $pos)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        return -1;
73
    }
74
75
    /**
76
     * EOFかどうか返却する
77
     * @return bool EOFならtrue、EOF以外またはリードエラーの場合はfalse
78
     */
79
    abstract public function eof();
80
81
    /**
82
     * 入力ストリームの現在位置にmarkを設定する
83
     * @param int マークするバイト位置
0 ignored issues
show
Documentation Bug introduced by
The doc comment マークするバイト位置 at position 0 could not be parsed: Unknown type name 'マークするバイト位置' at position 0 in マークするバイト位置.
Loading history...
84
     * @throws IOException
85
     */
86
    public function mark()
87
    {
88
        if (!$this->isMarkSupported()) {
89
            throw new IOException(get_class($this) . " does not support mark.");
90
        }
91
92
        if ($this->stream === null) {
93
            return null;
94
        }
95
96
        $this->markedPosition = $this->cursorPosition;
97
    }
98
99
    /**
100
     * 最後にmarkされた位置に再配置する
101
     * @throws IOException
102
     */
103
    public function reset()
104
    {
105
        if (!$this->isMarkSupported()) {
106
            throw new IOException(get_class($this) . " does not support mark and reset.");
107
        }
108
109
        if ($this->stream === null) {
110
            return null;
111
        }
112
113
        // mark位置を初期値に戻す
114
        $this->cursorPosition = $this->markedPosition;
115
        $this->markedPosition = 0;
116
    }
117
118
    /**
119
     * mark機能をサポートしているかどうか
120
     * @return boolean マークをサポートしていればtrue
121
     */
122
    public function isMarkSupported()
123
    {
124
        return false;
125
    }
126
}
127