LegacyGuzzleReaderFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getReader() 0 3 1
A __construct() 0 14 2
1
<?php
2
3
namespace Gocobachi\Compressy\Resource\Reader\Guzzle;
4
5
use Gocobachi\Compressy\Resource\Resource as ZippyResource;
6
use Gocobachi\Compressy\Resource\ResourceReader;
7
use Gocobachi\Compressy\Resource\ResourceReaderFactory;
8
use Guzzle\Http\Client;
0 ignored issues
show
Bug introduced by
The type Guzzle\Http\Client 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...
9
use Guzzle\Http\ClientInterface;
0 ignored issues
show
Bug introduced by
The type Guzzle\Http\ClientInterface 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...
10
use Guzzle\Plugin\Backoff\BackoffPlugin;
0 ignored issues
show
Bug introduced by
The type Guzzle\Plugin\Backoff\BackoffPlugin 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...
11
use Symfony\Component\EventDispatcher\Event;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventDispatcher\Event 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...
12
13
class LegacyGuzzleReaderFactory implements ResourceReaderFactory
14
{
15
    /**
16
     * @var ClientInterface|null
17
     */
18
    private $client = null;
19
20
    public function __construct(ClientInterface $client = null)
21
    {
22
        $this->client = $client;
23
24
        if (!$this->client) {
25
            $this->client = new Client();
26
27
            $this->client->getEventDispatcher()->addListener('request.error', function(Event $event) {
28
                // override guzzle default behavior of throwing exceptions
29
                // when 4xx & 5xx responses are encountered
30
                $event->stopPropagation();
31
            }, -254);
32
33
            $this->client->addSubscriber(BackoffPlugin::getExponentialBackoff(5, array(500, 502, 503, 408)));
34
        }
35
    }
36
37
    /**
38
     * @param ZippyResource $resource
39
     * @param string        $context
40
     *
41
     * @return ResourceReader
42
     */
43
    public function getReader(ZippyResource $resource, $context)
44
    {
45
        return new LegacyGuzzleReader($resource, $this->client);
46
    }
47
}
48