Completed
Pull Request — master (#60)
by
unknown
05:01
created

Fetcher::fetchResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Traits;
4
5
use GuzzleHttp\Client;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Simple helper for fetching responses using Guzzle client.
10
 *
11
 * @package environmentcheck
12
 */
13
trait Fetcher
14
{
15
    /**
16
     * Configuration for the Guzzle client
17
     *
18
     * @var array
19
     */
20
    protected $clientConfig = [];
21
22
    /**
23
     * Merges configuration arrays and returns the result
24
     *
25
     * @param array $extraConfig
26
     * @return array
27
     */
28
    private function getClientConfig(array $extraConfig = []) : array
29
    {
30
        return array_merge($this->clientConfig, $extraConfig);
31
    }
32
33
    /**
34
     * Fetch a response for a URL using Guzzle client.
35
     *
36
     * @param string $url
37
     * @param array|null $extraConfig Extra configuration
38
     * @return ResponseInterface
39
     */
40
    public function fetchResponse(string $url, ? array $extraConfig = []) : ? ResponseInterface
41
    {
42
        $config = $this->getClientConfig($extraConfig);
0 ignored issues
show
Bug introduced by
It seems like $extraConfig defined by parameter $extraConfig on line 40 can also be of type null; however, SilverStripe\Environment...cher::getClientConfig() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
43
        $client = new Client($config);
44
        return $client->get($url);
45
    }
46
}
47