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

GuzzleHttp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
1
<?php
2
namespace vipnytt\XRobotsTagParser\Adapters;
3
4
use GuzzleHttp\Psr7\Response;
5
use vipnytt\XRobotsTagParser;
6
use vipnytt\XRobotsTagParser\Exceptions\XrobotsTagParserException;
7
8
/**
9
 * Class GuzzleHttp
10
 *
11
 * Parse from an \GuzzleHttp\Psr7\Response object
12
 *
13
 * @package vipnytt\XRobotsTagParser\Adapters
14
 */
15
class GuzzleHttp extends XRobotsTagParser
16
{
17
    /**
18
     * Constructor
19
     *
20
     * @param \GuzzleHttp\Psr7\Response $response
21
     * @param string $userAgent
22
     * @throws XRobotsTagParserException
23
     * @throws XRobotsTagParser\Exceptions\XRobotsTagParserException
24
     */
25
    public function __construct(Response $response, $userAgent = '')
26
    {
27
        if (!$response instanceof Response) {
28
            throw new XRobotsTagParserException('Object is not an instance of `\GuzzleHttp\Psr7\Response`');
29
        }
30
        parent::__construct($userAgent);
31
        $headers = [];
32
        foreach ($response->getHeader(parent::HEADER_RULE_IDENTIFIER) as $name => $values) {
33
            $headers[] = $name . ': ' . implode(' ', $values) . "\r\n";
34
        }
35
        $this->parse($headers);
36
    }
37
}