Passed
Push — main ( 66f102...e7c7b0 )
by Yevhenii
02:28
created

GuzzleStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 30
c 1
b 0
f 0
rs 10
ccs 2
cts 9
cp 0.2222
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 10 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SteamMarketProviders\ParserManager\Http\Strategy;
6
7
use GuzzleHttp\Client;
8
use GuzzleHttp\Exception\GuzzleException;
9
use SteamMarketProviders\ParserManager\Contract\StrategyInterface;
10
use SteamMarketProviders\ParserManager\Http\Options;
11
use SteamMarketProviders\ParserManager\Http\Response;
12
13
class GuzzleStrategy implements StrategyInterface
14
{
15
    /**
16
     * @var Client
17
     */
18
    private Client $client;
19
20
    /**
21
     * @param Options|null $options
22
     */
23 1
    public function __construct(private readonly null|Options $options = null)
24
    {
25 1
        $this->client = new Client();
26
    }
27
28
    /**
29
     * @param string $url
30
     * @return Response
31
     * @throws GuzzleException
32
     */
33
    public function sendRequest(string $url): Response
34
    {
35
        $response = $this->client->get($url, [
36
            'proxy' => $this->options->toArray()
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            'proxy' => $this->options->/** @scrutinizer ignore-call */ toArray()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        ]);
38
39
        return new Response(
40
            $response->getStatusCode(),
41
            $response->getHeaders(),
42
            $response->getBody()->getContents()
0 ignored issues
show
Bug introduced by
$response->getBody()->getContents() of type string is incompatible with the type resource expected by parameter $body of SteamMarketProviders\Par...Response::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
            /** @scrutinizer ignore-type */ $response->getBody()->getContents()
Loading history...
43
        );
44
    }
45
}
46