Completed
Push — master ( aa8b89...6eacd0 )
by John
01:54
created

DefaultBodyParserFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A add() 0 4 1
A create() 0 4 1
1
<?php
2
namespace LunixRESTBasics\APIRequest\BodyParser\BodyParserFactory;
3
4
use LunixRESTBasics\APIRequest\BodyParser\BodyParser;
5
use LunixRESTBasics\APIRequest\BodyParser\JSONBodyParser;
6
use LunixRESTBasics\APIRequest\BodyParser\URLEncodedBodyParser;
7
8
/**
9
 * A BodyParserFactory that understands url encoded and json encoded content-types.
10
 * Class DefaultBodyParserFactory
11
 * @package LunixRESTBasics\Request\BodyParser
12
 */
13
class DefaultBodyParserFactory implements BodyParserFactory
14
{
15
16
    protected $registeredBodyParserFactory;
17
18 4
    public function __construct()
19
    {
20 4
        $this->registeredBodyParserFactory = new RegisteredBodyParserFactory([
21 4
            'application/json' => new JSONBodyParser(),
22 4
            'application/x-www-form-urlencoded' => new URLEncodedBodyParser()
23
        ]);
24 4
    }
25
26 1
    public function add($contentType, BodyParser $bodyParser)
27
    {
28 1
        $this->registeredBodyParserFactory->add($contentType, $bodyParser);
29 1
    }
30
31
    /**
32
     * Parses API request data out of a url
33
     * @param string $contentType
34
     * @return BodyParser
35
     */
36 4
    public function create(string $contentType): BodyParser
37
    {
38 4
        return $this->registeredBodyParserFactory->create($contentType);
39
    }
40
}
41