Url   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 2
c 5
b 1
f 0
lcom 0
cbo 2
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
1
<?php
2
namespace vipnytt\XRobotsTagParser\Adapters;
3
4
use GuzzleHttp\Client;
5
use vipnytt\XRobotsTagParser;
6
7
/**
8
 * Class Url
9
 *
10
 * Request the HTTP headers from an URL
11
 *
12
 * @package vipnytt\XRobotsTagParser\Adapters
13
 */
14
class Url extends XRobotsTagParser\Adapters\GuzzleHttp
15
{
16
    /**
17
     * GuzzleHttp config
18
     * @var array
19
     */
20
    protected $config = [
21
        'allow_redirects' => [
22
            'referer' => true,
23
            'strict' => false,
24
        ],
25
        'connect_timeout' => 30,
26
        'decode_content' => true,
27
        'headers' => [
28
            'user-agent' => 'XRobotsTagParser-VIPnytt/1.0 (+https://github.com/VIPnytt/RobotsTagParser/blob/master/README.md)',
29
        ],
30
        'http_errors' => false,
31
        'timeout' => 120,
32
        'verify' => true,
33
    ];
34
35
    /**
36
     * Constructor
37
     *
38
     * @param string $url
39
     * @param string $userAgent
40
     * @throws XRobotsTagParser\Exceptions\XRobotsTagParserException
41
     */
42
    public function __construct($url, $userAgent = '')
43
    {
44
        if (!empty($userAgent)) {
45
            $this->config['headers']['User-Agent'] = $userAgent;
46
        }
47
        $client = new Client($this->config);
48
        $request = $client->request('GET', $url);
49
        parent::__construct($request, $userAgent);
50
    }
51
}
52