Completed
Push — master ( 128ddb...c5783a )
by
unknown
14s queued 10s
created

ClientFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Services;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use SilverStripe\Core\Injector\Factory;
7
use SilverStripe\Core\Config\Configurable;
8
9
/**
10
 * Factory class for creating HTTP client which are injected into some env check classes. Inject via YAML,
11
 * arguments for Guzzle client can be supplied using "constructor" property or set as default_config.
12
 *
13
 * @see SilverStripe\EnvironmentCheck\Traits\Fetcher
14
 */
15
class ClientFactory implements Factory
16
{
17
    use Configurable;
18
19
    /**
20
     * Default config for Guzzle client.
21
     *
22
     * @var array
23
     */
24
    private static $default_config = [];
0 ignored issues
show
introduced by
The private property $default_config is not used, and could be removed.
Loading history...
25
26
    /**
27
     * Wrapper to create a Guzzle client.
28
     *
29
     * {@inheritdoc}
30
     */
31
    public function create($service, array $params = [])
32
    {
33
        return new GuzzleClient($this->getConfig($params));
34
    }
35
36
    /**
37
     * Merge config provided from yaml with default config
38
     *
39
     * @param array $overrides
40
     * @return array
41
     */
42
    public function getConfig(array $overrides)
43
    {
44
        return array_merge(
45
            $this->config()->get('default_config'),
46
            $overrides
47
        );
48
    }
49
}
50