DisplayParameterChecker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedDisplayValues() 0 7 1
A check() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\AuthorizationEndpoint\ParameterChecker;
15
16
use Assert\Assertion;
17
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
18
use function Safe\sprintf;
19
20
final class DisplayParameterChecker implements ParameterChecker
21
{
22
    public const DISPLAY_PAGE = 'page';
23
24
    public const DISPLAY_POPUP = 'popup';
25
26
    public const DISPLAY_TOUCH = 'touch';
27
28
    public const DISPLAY_WAP = 'wap';
29
30
    public function check(AuthorizationRequest $authorization): void
31
    {
32
        if ($authorization->hasQueryParam('display')) {
33
            Assertion::inArray($authorization->getQueryParam('display'), $this->getAllowedDisplayValues(), sprintf('Invalid parameter "display". Allowed values are %s', implode(', ', $this->getAllowedDisplayValues())));
34
        }
35
    }
36
37
    /**
38
     * @return string[]
39
     */
40
    private function getAllowedDisplayValues(): array
41
    {
42
        return [
43
            self::DISPLAY_PAGE,
44
            self::DISPLAY_POPUP,
45
            self::DISPLAY_TOUCH,
46
            self::DISPLAY_WAP,
47
        ];
48
    }
49
}
50