Protocol::getVersion()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Furious\Psr7\Protocol;
6
7
use Furious\Psr7\Exception\UnownedProtocolVersion;
8
9
final class Protocol
10
{
11
    public function getVersion(array $server): string
12
    {
13
        if (!isset($server['SERVER_PROTOCOL'])) {
14
            return '1.1';
15
        }
16
17
        if (!preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
18
            throw new UnownedProtocolVersion(
19
                (string) $server['SERVER_PROTOCOL']
20
            );
21
        }
22
23
        return $matches['version'];
24
    }
25
}