GuzzleRequestHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A request() 0 4 1
A setClient() 0 5 1
A getClient() 0 7 2
1
<?php
2
namespace VDB\Spider\RequestHandler;
3
4
use GuzzleHttp\Client;
5
use GuzzleHttp\HandlerStack;
6
use GuzzleHttp\Message\Request;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Message\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use GuzzleHttp\Message\RequestInterface;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Message\RequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use VDB\Spider\RequestHandler\RequestHandlerInterface;
9
use VDB\Spider\Resource;
10
use VDB\Spider\Uri\DiscoveredUri;
11
12
/**
13
 * @author Matthijs van den Bos <[email protected]>
14
 * @copyright 2013 Matthijs van den Bos
15
 */
16
class GuzzleRequestHandler implements RequestHandlerInterface
17
{
18
    /** @var Client */
19
    private $client;
20
21
    /**
22
     * @param Client $client
23
     * @return RequestHandlerInterface
24
     */
25
    public function setClient(Client $client)
26
    {
27
        $this->client = $client;
28
29
        return $this;
30
    }
31
32
    /**
33
     * @return Client
34
     */
35
    public function getClient()
36
    {
37
        if (!$this->client) {
38
            $this->client = new Client();
39
        }
40
41
        return $this->client;
42
    }
43
44
    /**
45
     * @param DiscoveredUri $uri
46
     * @return Resource
47
     */
48
    public function request(DiscoveredUri $uri)
49
    {
50
        $response = $this->getClient()->get($uri->toString());
51
        return new Resource($uri, $response);
52
    }
53
}
54