Completed
Push — master ( e55977...d99d38 )
by Sebastian
02:38
created

AbstractJsonResourceRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFromJsonInBody() 0 9 2
1
<?php
2
namespace Kartenmacherei\RestFramework\ResourceRequest;
3
4
use Kartenmacherei\RestFramework\Request\Body\JsonBody;
5
6
abstract class AbstractJsonResourceRequest extends AbstractResourceRequest
7
{
8
    /**
9
     * @param string $selector
10
     * @return \Kartenmacherei\RestFramework\JsonArray|\Kartenmacherei\RestFramework\JsonObject
11
     * @throws BadRequestException
12
     */
13
    public function getFromJsonInBody(string $selector)
14
    {
15
        $body = $this->getRequestBody();
16
        if (!$body->isJson()) {
17
            throw new BadRequestException('Request body does not contain JSON');
18
        }
19
        /** @var JsonBody $body */
20
        return $body->query($selector);
21
    }
22
}
23