Failed Conditions
Push — master ( f41a1f...02e26d )
by Florent
03:57
created

MaxAgeParameterAccountChecker   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C check() 0 28 7
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\AuthorizationEndpoint\UserAccount;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\RedirectToLoginPageException;
18
19
final class MaxAgeParameterAccountChecker implements UserAccountChecker
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function check(Authorization $authorization)
25
    {
26
        $userAccount = $authorization->getUserAccount();
27
        if (null === $userAccount) {
28
            throw new RedirectToLoginPageException($authorization);
29
        }
30
31
        switch (true) {
32
            case $authorization->hasQueryParam('max_age'):
33
                $max_age = (int) $authorization->getQueryParam('max_age');
34
35
                break;
36
            case $authorization->getClient()->has('default_max_age'):
37
                $max_age = (int) $authorization->getClient()->get('default_max_age');
38
39
                break;
40
            default:
41
                return;
42
        }
43
44
        if ($authorization->isUserAccountFullyAuthenticated()) {
45
            return;
46
        }
47
48
        if (null === $userAccount->getLastLoginAt() || time() - $userAccount->getLastLoginAt() > $max_age) {
49
            throw new RedirectToLoginPageException($authorization);
50
        }
51
    }
52
}
53