ScopePolicyDefaultRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 4
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\Scope\Rule;
15
16
use OAuth2Framework\Component\ClientRule\Rule;
17
use OAuth2Framework\Component\ClientRule\RuleHandler;
18
use OAuth2Framework\Component\Core\Client\ClientId;
19
use OAuth2Framework\Component\Core\DataBag\DataBag;
20
21
final class ScopePolicyDefaultRule implements Rule
22
{
23
    public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, RuleHandler $next): DataBag
24
    {
25
        if ($commandParameters->has('default_scope')) {
26
            $defaultScope = $commandParameters->get('default_scope');
27
            if (!\is_string($defaultScope)) {
28
                throw new \InvalidArgumentException('The "default_scope" parameter must be a string.');
29
            }
30
            if (1 !== \Safe\preg_match('/^[\x20\x23-\x5B\x5D-\x7E]+$/', $defaultScope)) {
31
                throw new \InvalidArgumentException('Invalid characters found in the "default_scope" parameter.');
32
            }
33
            $validatedParameters->set('default_scope', $commandParameters->get('default_scope'));
34
        }
35
36
        return $next->handle($clientId, $commandParameters, $validatedParameters);
37
    }
38
}
39