AcceptLanguage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 21 5
1
<?php
2
/*
3
 * This file is part of the Respect\Rest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Respect\Rest\Routines;
10
11
/** Handles Language content negotiation */
12
class AcceptLanguage extends AbstractAccept
13
{
14
    const ACCEPT_HEADER = 'HTTP_ACCEPT_LANGUAGE';
15
16 9
    protected function authorize($requested, $provided)
17
    {
18 9
        $requested = preg_replace('/^x\-/', '', $requested);
19 9
        $provided = preg_replace('/^x\-/', '', $provided);
20
21 9
        if ($requested == $provided) {
22 5
            return $provided;
23
        }
24
25 7
        if (stripos($requested, '-') || !stripos($provided, '-')) {
26 4
            return false;
27
        }
28
29 4
        list($providedA,) = explode('-', $provided);
30
31 4
        if ($requested === $providedA) {
32 4
            return $providedA;
33
        }
34
35 1
        return parent::authorize($requested, $provided);
36
    }
37
}
38