Passed
Push — master ( 35a69c...54bf96 )
by Ryuichi
01:46
created

InputStream::mark()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
1
<?php
2
3
namespace WebStream\IO;
4
5
use WebStream\Exception\Extend\IOException;
0 ignored issues
show
Bug introduced by
The type WebStream\Exception\Extend\IOException 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...
6
7
/**
8
 * InputStream
9
 * ftellの戻り値仕様により32ビット数値を返すため2GB以上のファイルを読み込むと動かなくなる
10
 * C言語のftell仕様依存
11
 * @author Ryuichi TANAKA.
12
 * @since 2016/02/05
13
 * @version 0.7
14
 */
15
abstract class InputStream
16
{
17
    /**
18
     * @var mixed 入力ストリーム
19
     */
20
    protected $stream;
21
22
    /**
23
     * @var int 現在のポインタ位置
24
     */
25
    protected $cursorPosition;
26
27
    /**
28
     * @var int markしたポインタ位置
29
     */
30
    protected $markedPosition;
31
32
    /**
33
     * constructor
34
     * @param mixed $stream 入力ストリーム
35
     */
36 11
    public function __construct($stream)
37
    {
38 11
        $this->stream = $stream;
39 11
        $this->cursorPosition = 0;
40 11
        $this->markedPosition = 0;
41
    }
42
43
    /**
44
     * destructor
45
     */
46 11
    public function __destruct()
47
    {
48 11
        $this->close();
49
    }
50
51
    /**
52
     * 入力ストリームを閉じる
53
     */
54
    abstract public function close();
55
56
    /**
57
     * 入力ストリームからデータを読み込む
58
     * 引数に数値を指定した場合、指定数値バイトだけ読み込む
59
     * @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...
60
     * @return string 読み込みデータ
61
     * @throws InvalidArgumentException
62
     * @throws IOException
63
     */
64
    abstract public function read($length = null);
65
66
    /**
67
     * 入力ストリームから行単位でデータを読み込む
68
     * 末尾に改行コードは含まない
69
     * @return string 読み込みデータ
70
     */
71
    abstract public function readLine();
72
73
    /**
74
     * 入力ストリームから指定バイト数後方へポインタを移動する
75
     * @param int $pos 後方への移動バイト数(負数の場合は前方へ移動)
76
     * @return int $skipNum 移動したバイト数、移動に失敗した場合-1
77
     */
78
    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

78
    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...
79
    {
80
        return -1;
81
    }
82
83
    /**
84
     * EOFかどうか返却する
85
     * @return bool EOFならtrue、EOF以外またはリードエラーの場合はfalse
86
     */
87
    abstract public function eof();
88
89
    /**
90
     * 入力ストリームの現在位置にmarkを設定する
91
     * @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...
92
     * @throws IOException
93
     */
94 2
    public function mark()
95
    {
96 2
        if (!$this->isMarkSupported()) {
97
            throw new IOException(get_class($this) . " does not support mark.");
98
        }
99
100 2
        if ($this->stream === null) {
101
            return null;
102
        }
103
104 2
        $this->markedPosition = $this->cursorPosition;
105
    }
106
107
    /**
108
     * 最後にmarkされた位置に再配置する
109
     * @throws IOException
110
     */
111 2
    public function reset()
112
    {
113 2
        if (!$this->isMarkSupported()) {
114
            throw new IOException(get_class($this) . " does not support mark and reset.");
115
        }
116
117 2
        if ($this->stream === null) {
118
            return null;
119
        }
120
121
        // mark位置を初期値に戻す
122 2
        $this->cursorPosition = $this->markedPosition;
123 2
        $this->markedPosition = 0;
124
    }
125
126
    /**
127
     * mark機能をサポートしているかどうか
128
     * @return boolean マークをサポートしていればtrue
129
     */
130
    public function isMarkSupported()
131
    {
132
        return false;
133
    }
134
}
135