Completed
Push — master ( 9b56e4...2c514d )
by Jan-Petter
02:30
created

url   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 4
1
<?php
2
namespace vipnytt\XRobotsTagParser\Adapters;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\Exception\TransferException;
6
use vipnytt\XRobotsTagParser;
7
use vipnytt\XRobotsTagParser\Exceptions\XrobotsTagParserException;
8
9
/**
10
 * Class url
11
 *
12
 * Request the HTTP headers from an URL
13
 *
14
 * @package vipnytt\XRobotsTagParser\Adapters
15
 */
16
class url extends XRobotsTagParser\Adapters\GuzzleHttp
17
{
18
    /**
19
     * Constructor
20
     *
21
     * @param string $url
22
     * @param string $userAgent
23
     * @throws XRobotsTagParserException
24
     */
25
    public function __construct($url, $userAgent = '')
26
    {
27
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
28
            throw new XRobotsTagParserException('Invalid URL provided');
29
        }
30
        $config = [];
31
        if (!empty($userAgent)) {
32
            $config = [
33
                'headers' => [
34
                    'User-Agent' => $userAgent
35
                ]
36
            ];
37
        }
38
        try {
39
            $client = new Client($config);
40
            $request = $client->Request('GET', $url);
41
            parent::__construct($request, $userAgent);
0 ignored issues
show
Compatibility introduced by
$request of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
42
        } catch (TransferException $e) {
43
            throw new XRobotsTagParserException($e->getMessage());
44
        }
45
    }
46
}