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

FileWriter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 25
ccs 5
cts 6
cp 0.8333
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 3 1
A __construct() 0 9 3
1
<?php
2
3
namespace WebStream\IO\Writer;
4
5
use WebStream\IO\FileOutputStream;
6
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...
7
8
/**
9
 * FileWriter
10
 * @author Ryuichi TANAKA.
11
 * @since 2016/02/24
12
 * @version 0.7
13
 */
14
class FileWriter extends OutputStreamWriter
15
{
16
    /**
17
     * constructor
18
     * @param mixed $file ファイルオブジェクトまたはファイルパス
19
     */
20 3
    public function __construct($file, bool $isAppend = false, int $bufferSize = null)
21
    {
22 3
        parent::__construct(new FileOutputStream($file, $isAppend));
23
24
        // fwriteのデフォルトバッファリングサイズは8KBなので、指定無しの場合は8KBになる
25
        // また、同じストリームに対して出力を行うプロセスが複数ある場合、8KBごとに停止する
26
        // see: http://php.net/manual/ja/function.stream-set-write-buffer.php
27 3
        if ($bufferSize !== null && stream_set_write_buffer($this->stream, $bufferSize) !== 0) {
0 ignored issues
show
Bug introduced by
$this->stream of type WebStream\IO\OutputStream is incompatible with the type resource expected by parameter $stream of stream_set_write_buffer(). ( Ignorable by Annotation )

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

27
        if ($bufferSize !== null && stream_set_write_buffer(/** @scrutinizer ignore-type */ $this->stream, $bufferSize) !== 0) {
Loading history...
28
            throw new IOException("Failed to change the buffer size.");
29
        }
30
    }
31
32
    /**
33
     * ファイルに書き込む
34
     * @param mixed $data 書き込みデータ
35
     */
36 3
    public function write($data)
37
    {
38 3
        $this->stream->write($data);
39
    }
40
}
41