Request   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 22 1
A getStatusCode() 0 4 1
A getContentType() 0 4 1
1
<?php
2
namespace Tzsk\ScrapePod\Helpers;
3
4
class Request
5
{
6
    /**
7
     * @var string
8
     */
9
    private $contentType;
10
11
    /**
12
     * @var int
13
     */
14
    private $statusCode;
15
16
    /**
17
     * @param string $url
18
     * @param array $options
19
     *
20
     * @return string
21
     */
22
    public function create($url, array $options = [])
23
    {
24
        $request = curl_init($url);
25
26
        $default_options = [
27
           CURLOPT_FAILONERROR    => true,
28
           CURLOPT_FOLLOWLOCATION => true,
29
           CURLOPT_RETURNTRANSFER => true,
30
           CURLOPT_TIMEOUT        => 15,
31
           CURLOPT_SSL_VERIFYPEER => 0,
32
           CURLINFO_HEADER_OUT    => true
33
       ] + $options;
34
35
        curl_setopt_array($request, $default_options);
36
37
        $result = curl_exec($request);
38
        $this->statusCode = curl_getinfo($request, CURLINFO_HTTP_CODE);
39
        $this->contentType = curl_getinfo($request, CURLINFO_CONTENT_TYPE);
40
        curl_close($request);
41
42
        return $result;
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getStatusCode()
49
    {
50
        return $this->statusCode;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getContentType()
57
    {
58
        return $this->contentType;
59
    }
60
}
61