RequestHandlerClientFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromRequestHandler() 0 5 1
A __invoke() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of coisa/http.
5
 *
6
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CoiSA\Http\Client;
15
16
use Psr\Container\ContainerInterface;
17
use Psr\Http\Message\ServerRequestFactoryInterface;
18
use Psr\Http\Server\RequestHandlerInterface;
19
20
/**
21
 * Class RequestHandlerClientFactory.php
22
 *
23
 * @package CoiSA\Http\Client
24
 */
25
final class RequestHandlerClientFactory
26
{
27
    /**
28
     * @param ContainerInterface $container
29
     *
30
     * @return RequestHandlerClient
31
     */
32 4
    public function __invoke(ContainerInterface $container): RequestHandlerClient
33
    {
34 4
        $requestHandler = $container->get(RequestHandlerInterface::class);
35
36 4
        $serverRequestFactory = $container->has(ServerRequestFactoryInterface::class) ?
37 4
            $container->get(ServerRequestFactoryInterface::class) : null;
38
39 4
        return $this->fromRequestHandler($requestHandler, $serverRequestFactory);
40
    }
41
42
    /**
43
     * @param RequestHandlerInterface            $requestHandler
44
     * @param null|ServerRequestFactoryInterface $serverRequestFactory
45
     *
46
     * @return RequestHandlerClient
47
     */
48 2
    public function fromRequestHandler(
49
        RequestHandlerInterface $requestHandler,
50
        ServerRequestFactoryInterface $serverRequestFactory = null
51
    ): RequestHandlerClient {
52 2
        return new RequestHandlerClient($requestHandler, $serverRequestFactory);
53
    }
54
}
55