Failed Conditions
Push — master ( dc4e55...720050 )
by Florent
19:46 queued 13:33
created

ScopePolicyRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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\Model\Client\Rule;
15
16
use Assert\Assertion;
17
use OAuth2Framework\Component\Server\Model\DataBag\DataBag;
18
use OAuth2Framework\Component\Server\Model\Scope\ScopePolicyManager;
19
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId;
20
21
final class ScopePolicyRule implements RuleInterface
22
{
23
    /**
24
     * @var ScopePolicyManager
25
     */
26
    private $scopePolicyManager;
27
28
    /**
29
     * @param ScopePolicyManager $scopePolicyManager
30
     */
31
    public function __construct(ScopePolicyManager $scopePolicyManager)
32
    {
33
        $this->scopePolicyManager = $scopePolicyManager;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function handle(DataBag $commandParameters, DataBag $validatedParameters, ?UserAccountId $userAccountId, callable $next): DataBag
40
    {
41
        if ($commandParameters->has('scope_policy')) {
42
            Assertion::true($this->scopePolicyManager->has($commandParameters->get('scope_policy')), sprintf('The scope policy \'%s\' is not supported.', $commandParameters->get('scope_policy')));
43
            $validatedParameters = $validatedParameters->with('scope_policy', $commandParameters->get('scope_policy'));
44
        }
45
46
        return $next($commandParameters, $validatedParameters, $userAccountId);
47
    }
48
}
49