Completed
Push — master ( 005b00...a8a0a1 )
by John
01:59
created

DefaultBodyParserFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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