Failed Conditions
Push — master ( 476087...9b9b51 )
by Florent
11:32
created

ClientIdRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 3
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 OAuth2Framework\Component\Server\Model\DataBag\DataBag;
17
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId;
18
19
final class ClientIdRule implements RuleInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function handle(DataBag $commandParameters, DataBag $validatedParameters, ? UserAccountId $userAccountId, callable $next): DataBag
25
    {
26
        if (!$commandParameters->has('client_id')) {
27
            throw new \InvalidArgumentException('Client ID not defined.');
28
        }
29
        $validatedParameters = $validatedParameters->with('client_id', $commandParameters->get('client_id'));
30
31
        if ($commandParameters->has('client_id_issued_at')) {
32
            $validatedParameters = $validatedParameters->with('client_id_issued_at', $commandParameters->get('client_id_issued_at'));
33
        } else {
34
            $validatedParameters = $validatedParameters->with('client_id_issued_at', time());
35
        }
36
37
        return $next($commandParameters, $validatedParameters, $userAccountId);
38
    }
39
40
}
41