RequestHandlerClientFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

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 8
ccs 5
cts 5
cp 1
crap 2
rs 10
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