Passed
Push — main ( 36fa87...8ed71a )
by Chema
01:06 queued 13s
created

HttpDependencyProvider::addHttpClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Http;
6
7
use Gacela\Framework\AbstractDependencyProvider;
8
use Gacela\Framework\Container\Container;
9
use PhpLightning\Http\Infrastructure\FakeHttpClient;
10
use PhpLightning\Http\Infrastructure\SymfonyHttpClient;
11
12
/**
13
 * @method HttpConfig getConfig()
14
 */
15
final class HttpDependencyProvider extends AbstractDependencyProvider
16
{
17
    public const HTTP_CLIENT = 'HTTP_CLIENT';
18
19
    public function provideModuleDependencies(Container $container): void
20
    {
21
        $this->addHttpClient($container);
22
    }
23
24
    private function addHttpClient(Container $container): void
25
    {
26
        if ($this->getConfig()->isProd()) {
27
            $container->set(self::HTTP_CLIENT, static fn () => new SymfonyHttpClient());
28
        } else {
29
            $container->set(self::HTTP_CLIENT, static fn () => new FakeHttpClient());
30
        }
31
    }
32
}
33