Completed
Branch master (73f336)
by John
01:59
created

GenericRequestFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 2
lcom 1
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 7 1
1
<?php
2
namespace LunixREST\Request\RequestFactory;
3
4
use LunixREST\Request\BodyParser\BodyParser;
5
use LunixREST\Request\Request;
6
use LunixREST\Request\URLParser\Exceptions\InvalidRequestURLException;
7
use LunixREST\Request\URLParser\URLParser;
8
9
class GenericRequestFactory implements RequestFactory {
10
11
    /**
12
     * @var URLParser
13
     */
14
    protected $URLParser;
15
    /**
16
     * @var BodyParser
17
     */
18
    private $bodyParser;
19
20
    /**
21
     * BasicRequestFactory constructor.
22
     * @param URLParser $URLParser
23
     * @param BodyParser $bodyParser
24
     */
25
    public function __construct(URLParser $URLParser, BodyParser $bodyParser) {
26
        $this->URLParser = $URLParser;
27
        $this->bodyParser = $bodyParser;
28
    }
29
30
    /**
31
     * Creates a request from raw $data and a $url
32
     * @param $method
33
     * @param array $headers
34
     * @param string $data
35
     * @param $ip
36
     * @param $url
37
     * @return Request
38
     * @throws InvalidRequestURLException
39
     */
40
    public function create($method, array $headers, string $data, $ip, $url): Request {
41
        $parsedURL = $this->URLParser->parse($url);
42
        $parsedData = $this->bodyParser->parse($data);
43
44
        return new Request($method, $headers, $parsedData, $parsedURL->getRequestData(), $ip, $parsedURL->getVersion(),
45
            $parsedURL->getApiKey(), $parsedURL->getEndpoint(), $parsedURL->getExtension(), $parsedURL->getInstance());
46
    }
47
}
48