Passed
Push — gh-pages ( 22b0fe...eb2d91 )
by
unknown
12:27 queued 10:15
created

StreamAbstract   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 135
rs 10
wmc 17

16 Methods

Rating   Name   Duplication   Size   Complexity  
A isSeekable() 0 2 1
A write() 0 2 1
A read() 0 2 1
A isReadable() 0 2 1
A getMetadata() 0 2 1
A getSize() 0 2 1
A tell() 0 2 1
A seek() 0 2 1
A getContents() 0 2 1
A eof() 0 2 1
A rewind() 0 2 1
A isWritable() 0 2 1
A __destruct() 0 2 1
A detach() 0 2 1
A close() 0 3 2
A __toString() 0 2 1
1
<?php
2
/**
3
 * Class StreamAbstract
4
 *
5
 * @created      21.12.2018
6
 * @author       smiley <[email protected]>
7
 * @copyright    2018 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\HTTP\Psr7;
12
13
use Psr\Http\Message\StreamInterface;
14
15
use const SEEK_SET;
16
17
abstract class StreamAbstract implements StreamInterface{
18
19
	/**
20
	 * @var \Psr\Http\Message\StreamInterface|resource|null
21
	 */
22
	protected $stream = null;
23
24
	/**
25
	 * Closes the stream when the destructed
26
	 *
27
	 * @return void
28
	 */
29
	public function __destruct(){
30
		$this->close();
31
	}
32
33
	/**
34
	 * @inheritDoc
35
	 * @codeCoverageIgnore
36
	 */
37
	public function __toString(){
38
		return (string)$this->stream;
39
	}
40
41
	/**
42
	 * @inheritDoc
43
	 */
44
	public function close(){
45
		if($this->stream instanceof StreamInterface){
46
			$this->stream->close();
47
		}
48
	}
49
50
	/**
51
	 * @inheritDoc
52
	 * @codeCoverageIgnore
53
	 */
54
	public function detach(){
55
		return $this->stream->detach();
0 ignored issues
show
Bug introduced by
The method detach() does not exist on null. ( Ignorable by Annotation )

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

55
		return $this->stream->/** @scrutinizer ignore-call */ detach();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
	}
57
58
	/**
59
	 * @inheritDoc
60
	 * @codeCoverageIgnore
61
	 */
62
	public function getSize():?int{
63
		return $this->stream->getSize();
64
	}
65
66
	/**
67
	 * @inheritDoc
68
	 * @codeCoverageIgnore
69
	 */
70
	public function tell():int{
71
		return $this->stream->tell();
72
	}
73
74
	/**
75
	 * @inheritDoc
76
	 * @codeCoverageIgnore
77
	 */
78
	public function eof():bool{
79
		return $this->stream->eof();
80
	}
81
82
	/**
83
	 * @inheritDoc
84
	 * @codeCoverageIgnore
85
	 */
86
	public function isSeekable():bool{
87
		return $this->stream->isSeekable();
88
	}
89
90
	/**
91
	 * @inheritDoc
92
	 * @codeCoverageIgnore
93
	 */
94
	public function seek($offset, $whence = SEEK_SET):void{
95
		$this->stream->seek($offset, $whence);
96
	}
97
98
	/**
99
	 * @inheritDoc
100
	 * @codeCoverageIgnore
101
	 */
102
	public function rewind():void{
103
		$this->stream->rewind();
104
	}
105
106
	/**
107
	 * @inheritDoc
108
	 * @codeCoverageIgnore
109
	 */
110
	public function isWritable():bool{
111
		return $this->stream->isWritable();
112
	}
113
114
	/**
115
	 * @inheritDoc
116
	 * @codeCoverageIgnore
117
	 */
118
	public function write($string):int{
119
		return $this->stream->write($string);
120
	}
121
122
	/**
123
	 * @inheritDoc
124
	 * @codeCoverageIgnore
125
	 */
126
	public function isReadable():bool{
127
		return $this->stream->isReadable();
128
	}
129
130
	/**
131
	 * @inheritDoc
132
	 * @codeCoverageIgnore
133
	 */
134
	public function read($length):string{
135
		return $this->stream->read($length);
136
	}
137
138
	/**
139
	 * @inheritDoc
140
	 * @codeCoverageIgnore
141
	 */
142
	public function getContents():string{
143
		return $this->stream->getContents();
144
	}
145
146
	/**
147
	 * @inheritDoc
148
	 * @codeCoverageIgnore
149
	 */
150
	public function getMetadata($key = null){
151
		return $this->stream->getMetadata($key);
152
	}
153
154
}
155