Completed
Pull Request — 1.x (#66)
by
unknown
02:19
created

VaryUriTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getVaryUri() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\Resource\AbstractUri;
8
9
trait VaryUriTrait
10
{
11
    private function getVaryUri(AbstractUri $uri) : string
12
    {
13
        if (! isset($_SERVER['X_VARY'])) {
14
            return (string) $uri;
15
        }
16
        $varys = \explode(',', $_SERVER['X_VARY']);
17
        $varyId = '';
18
        foreach ($varys as $vary) {
19
            $phpVaryKey = \sprintf('X_%s', \strtoupper($vary));
20
            if (isset($_SERVER[$phpVaryKey])) {
21
                $varyId .= $_SERVER[$phpVaryKey];
22
            }
23
        }
24
25
        return (string) $uri . $varyId;
26
    }
27
}
28