Completed
Push — master ( 64b5cb...614d47 )
by Dev
02:59
created

ResponseFromCache::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace PiedWeb\Curl;
4
5
class ResponseFromCache extends Response
6
{
7
    /** @var string */
8
    protected $url;
9
10
    /**
11
     * @param string $filePath
12
     * @param mixed  $headers  could be a string (the separator between headers and content or FALSE
13
     */
14 3
    public function __construct(
15
        string $filePathOrContent,
16
        ?string $url = null,
17
        array $info = [],
18
        $headers = PHP_EOL.PHP_EOL
19
    ) {
20 3
        $content = file_exists($filePathOrContent) ? file_get_contents($filePathOrContent) : $filePathOrContent;
21
22 3
        if (!$content) {
23
            throw new \Exception($filePath.' doesn\'t exist');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $filePath does not exist. Did you maybe mean $filePathOrContent?
Loading history...
24
        }
25
26 3
        if (false !== $headers) {
27 3
            list($this->headers, $this->content) = explode($headers, $content, 2);
28
        } else {
29
            $this->content = $content;
30
        }
31
32 3
        $this->info = $info;
33 3
        $this->url = $url;
34 3
    }
35
36 3
    public function getRequest()
37
    {
38 3
        return null;
39
    }
40
41
    public function getUrl()
42
    {
43
        return $this->url;
44
    }
45
46
    public function getEffectiveUrl()
47
    {
48
        return $this->url;
49
    }
50
51
    public function getStatusCode()
52
    {
53
        if (isset($this->headers)) {
54
            $headers = $this->getHeaders();
55
            list($http, $status) = explode(' ', $headers[0], 2);
56
57
            return $status;
58
        }
59
60
        return $this->getInfo('http_code');
61
    }
62
63 3
    public function getContentType()
64
    {
65 3
        if (isset($this->headers)) {
66 3
            $headers = $this->getHeaders();
67 3
            if (isset($headers['content-type'])) {
68
                return $headers['content-type'];
69
            }
70
        }
71
72 3
        return $this->getInfo('content_type');
73
    }
74
}
75