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

HeaderExtractor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A extract() 0 21 2
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 HeaderExtractor implements ExtractorInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function extract(ServerRequestInterface $request): Range
16
    {
17
        if (!$request->headers()->has('Range')) {
18
            throw new RangeNotFoundException;
19
        }
20
21
        return new Range(
22
            $request
23
                ->headers()
24
                ->get('Range')
25
                ->values()
26
                ->current()
27
                ->firstPosition(),
28
            $request
29
                ->headers()
30
                ->get('Range')
31
                ->values()
32
                ->current()
33
                ->lastPosition()
34
        );
35
    }
36
}
37