InstagramStream   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseHeaders() 0 3 1
A streamContextCreate() 0 3 1
A fileGetContents() 0 6 2
1
<?php
2
3
namespace Maztech\HttpClients;
4
5
/**
6
 * Class InstagramStream
7
 *
8
 * Abstraction for the procedural stream elements so that the functions can be
9
 * mocked and the implementation can be tested.
10
 *
11
 * @package Instagram
12
 */
13
class InstagramStream
14
{
15
    /**
16
     * @var resource Context stream resource instance
17
     */
18
    protected $stream;
19
20
    /**
21
     * @var array Response headers from the stream wrapper
22
     */
23
    protected $responseHeaders = [];
24
25
    /**
26
     * Make a new context stream reference instance
27
     *
28
     * @param array $options
29
     */
30
    public function streamContextCreate(array $options)
31
    {
32
        $this->stream = stream_context_create($options);
33
    }
34
35
    /**
36
     * The response headers from the stream wrapper
37
     *
38
     * @return array
39
     */
40
    public function getResponseHeaders()
41
    {
42
        return $this->responseHeaders;
43
    }
44
45
    /**
46
     * Send a stream wrapped request
47
     *
48
     * @param string $url
49
     *
50
     * @return mixed
51
     */
52
    public function fileGetContents($url)
53
    {
54
        $rawResponse = file_get_contents($url, false, $this->stream);
55
        $this->responseHeaders = $http_response_header ?: [];
56
57
        return $rawResponse;
58
    }
59
}
60