RequestFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createRequest() 0 12 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Http\Factory;
6
7
use Cakasim\Payone\Sdk\Http\Message\Request;
8
use Psr\Http\Message\RequestFactoryInterface;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\StreamFactoryInterface;
11
use Psr\Http\Message\UriFactoryInterface;
12
use Psr\Http\Message\UriInterface;
13
14
/**
15
 * Implements the PSR-17 request factory interface.
16
 *
17
 * @author Fabian Böttcher <[email protected]>
18
 * @since 0.1.0
19
 */
20
class RequestFactory implements RequestFactoryInterface
21
{
22
    /**
23
     * @var UriFactoryInterface The URI factory used for generating request URIs.
24
     */
25
    protected $uriFactory;
26
27
    /**
28
     * @var StreamFactoryInterface The stream factory used for generating request bodies.
29
     */
30
    protected $streamFactory;
31
32
    /**
33
     * Constructs the RequestFactory.
34
     *
35
     * @param UriFactoryInterface $uriFactory A URI factory.
36
     * @param StreamFactoryInterface $streamFactory A stream factory.
37
     */
38
    public function __construct(UriFactoryInterface $uriFactory, StreamFactoryInterface $streamFactory)
39
    {
40
        $this->uriFactory = $uriFactory;
41
        $this->streamFactory = $streamFactory;
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public function createRequest(string $method, $uri): RequestInterface
48
    {
49
        if (!($uri instanceof UriInterface)) {
50
            $uri = $this->uriFactory->createUri($uri);
51
        }
52
53
        return new Request(
54
            $method,
55
            $uri,
56
            Request::PROTOCOL_VERSION_1_1,
57
            $this->streamFactory->createStream(),
58
            []
59
        );
60
    }
61
}
62