Failed Conditions
Push — ng ( f9780e...ccd5de )
by Florent
11:07
created

Checker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkUsedOnce() 0 7 2
A checkCharset() 0 6 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2018 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace OAuth2Framework\Component\Server\Scope;
13
14
final class Checker
15
{
16
    /**
17
     * @param string $scope
18
     * @param string $scopes
19
     *
20
     * @throws \InvalidArgumentException
21
     */
22
    public static function checkUsedOnce(string $scope, string $scopes)
23
    {
24
        $scopes = explode(' ', $scopes);
25
        if (1 < count(array_keys($scopes, $scope))) {
26
            throw new \InvalidArgumentException(sprintf('Scope "%s" appears more than once.', $scope));
27
        }
28
    }
29
30
    /**
31
     * @param string $scope
32
     *
33
     * @throws \InvalidArgumentException
34
     */
35
    public static function checkCharset(string $scope)
36
    {
37
        if (1 !== preg_match('/^[\x20\x23-\x5B\x5D-\x7E]+$/', $scope)) {
38
            throw new \InvalidArgumentException('Scope contains illegal characters.');
39
        }
40
    }
41
}
42