Completed
Push — develop ( 99c8cd...370699 )
by Baptiste
02:34
created

QueryExtractor::extract()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.0534
cc 4
eloc 15
nc 2
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\RangeExtractor;
5
6
use Innmind\Rest\ServerBundle\Exception\RangeNotFoundException;
7
use Innmind\Rest\Server\Request\Range;
8
use Innmind\Http\Message\ServerRequestInterface;
9
10
final class QueryExtractor implements ExtractorInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function extract(ServerRequestInterface $request): Range
16
    {
17
        if (
18
            !$request->query()->has('range') ||
19
            !is_array($request->query()->get('range')->value()) ||
20
            count($request->query()->get('range')->value()) !== 2
21
        ) {
22
            throw new RangeNotFoundException;
23
        }
24
25
        return new Range(
26
            $request
27
                ->query()
28
                ->get('range')
29
                ->value()[0],
30
            $request
31
                ->query()
32
                ->get('range')
33
                ->value()[1]
34
        );
35
    }
36
}
37