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

HttpDependencyProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 6
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provideModuleDependencies() 0 3 1
A addHttpClient() 0 6 2
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