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

DefaultBodyParserFactory::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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