Failed Conditions
Push — ng ( 935f22...b3431d )
by Florent
04:01
created

ScopeRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\Server\Scope\Rule;
15
16
use OAuth2Framework\Component\Server\Core\Client\ClientId;
17
use OAuth2Framework\Component\Server\Core\Client\Rule\Rule;
18
use OAuth2Framework\Component\Server\Core\DataBag\DataBag;
19
20
final class ScopeRule implements Rule
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag
26
    {
27
        if ($commandParameters->has('scope')) {
28
            $scope = $commandParameters->get('scope');
29
            if (!is_string($scope)) {
30
                throw new \InvalidArgumentException('The "scope" parameter must be a string.');
31
            }
32
            if (1 !== preg_match('/^[\x20\x23-\x5B\x5D-\x7E]+$/', $scope)) {
33
                throw new \InvalidArgumentException('Invalid characters found in the "scope" parameter.');
34
            }
35
            $validatedParameters = $validatedParameters->with('scope', $scope);
36
        }
37
38
        return $next($clientId, $commandParameters, $validatedParameters);
39
    }
40
}
41