MaxAgeParameterAuthenticationChecker   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAuthenticationNeeded() 0 20 5
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\AuthorizationEndpoint\User;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
17
18
final class MaxAgeParameterAuthenticationChecker implements UserAuthenticationChecker
19
{
20
    public function isAuthenticationNeeded(AuthorizationRequest $authorization): bool
21
    {
22
        if (!$authorization->hasUserAccount()) {
23
            return true;
24
        }
25
26
        switch (true) {
27
            case $authorization->hasQueryParam('max_age'):
28
                $max_age = (int) $authorization->getQueryParam('max_age');
29
30
                break;
31
            case $authorization->getClient()->has('default_max_age'):
32
                $max_age = (int) $authorization->getClient()->get('default_max_age');
33
34
                break;
35
            default:
36
                return false;
37
        }
38
39
        return null === $authorization->getUserAccount()->getLastLoginAt() || time() - $authorization->getUserAccount()->getLastLoginAt() > $max_age;
40
    }
41
}
42