StreamReader::getContentsAsStream()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gocobachi\Compressy\Resource\Reader\Stream;
4
5
use Gocobachi\Compressy\Resource\Resource as ZippyResource;
6
use Gocobachi\Compressy\Resource\ResourceReader;
7
8
class StreamReader implements ResourceReader
9
{
10
    /**
11
     * @var ZippyResource
12
     */
13
    private $resource;
14
15
    /**
16
     * @param ZippyResource $resource
17
     */
18
    public function __construct(ZippyResource $resource)
19
    {
20
        $this->resource = $resource;
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function getContents()
27
    {
28
        return file_get_contents($this->resource->getOriginal());
29
    }
30
31
    /**
32
     * @return resource
33
     */
34
    public function getContentsAsStream()
35
    {
36
        $stream = is_resource($this->resource->getOriginal()) ?
0 ignored issues
show
introduced by
The condition is_resource($this->resource->getOriginal()) is always false.
Loading history...
37
            $this->resource->getOriginal() : @fopen($this->resource->getOriginal(), 'rb');
38
39
        return $stream;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $stream could also return false which is incompatible with the documented return type resource. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
40
    }
41
}
42