Completed
Pull Request — master (#1)
by Woody
27:07 queued 01:07
created

JsonContentHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isApplicableMimeType() 0 4 1
A getParsedBody() 0 11 2
1
<?php
2
namespace Equip\Handler;
3
4
use Equip\Exception\HttpException;
5
6
class JsonContentHandler extends ContentHandler
7
{
8
    /**
9
     * @inheritDoc
10
     */
11 3
    protected function isApplicableMimeType($mime)
12
    {
13 3
        return preg_match('~^application/([a-z.]+\+)?json$~', $mime);
14
    }
15
16
    /**
17
     * @inheritDoc
18
     */
19 2
    protected function getParsedBody($body)
20
    {
21 2
        $body = json_decode($body, true);
22
23 2
        if (json_last_error() !== JSON_ERROR_NONE) {
24 1
            $message = 'JSON ' . json_last_error_msg();
25 1
            throw HttpException::badRequest($message);
26
        }
27
28 1
        return $body;
29
    }
30
}
31