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

AbstractJsonResourceRequest::getFromJsonInBody()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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