Passed
Branch feature/first-release (f6e752)
by Andrea Marco
02:33
created

Endpoint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 38
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleSource() 0 13 2
A shouldHandleSource() 0 11 4
1
<?php
2
3
namespace Cerbero\LazyJson\Handlers;
4
5
use GuzzleHttp\Client;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\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...
6
use Traversable;
7
8
/**
9
 * The endpoint handler.
10
 *
11
 */
12
class Endpoint extends AbstractHandler
13
{
14
    /**
15
     * Determine whether the handler should handle the source
16
     *
17
     * @return bool
18
     */
19
    protected function shouldHandleSource(): bool
20
    {
21
        if (!is_string($this->source)) {
22
            return false;
23
        }
24
25
        if (false === $url = parse_url($this->source)) {
26
            return false;
27
        }
28
29
        return in_array($url['scheme'] ?? null, ['http', 'https']) && isset($url['host']);
30
    }
31
32
    /**
33
     * Handle the source
34
     *
35
     * @return Traversable|null
36
     */
37
    protected function handleSource(): ?Traversable
38
    {
39
        if (!class_exists(Client::class)) {
40
            return null;
41
        }
42
43
        $this->source = (new Client())->get($this->source, [
44
            'headers' => [
45
                'Accept' => 'application/json',
46
            ],
47
        ]);
48
49
        return null;
50
    }
51
}
52