Passed
Push — master ( fb60c6...a721e7 )
by Rutger
03:14
created

autoApproveAndProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\components\authorization\EndSession;
4
5
use rhertogh\Yii2Oauth2Server\components\authorization\base\Oauth2BaseAuthorizationRequest;
6
use rhertogh\Yii2Oauth2Server\components\authorization\EndSession\base\Oauth2BaseEndSessionAuthorizationRequest;
7
use rhertogh\Yii2Oauth2Server\helpers\UrlHelper;
8
use Yii;
9
use yii\base\InvalidCallException;
10
11
class Oauth2EndSessionAuthorizationRequest extends Oauth2BaseEndSessionAuthorizationRequest
12
{
13
    public function isAuthorizationAllowed()
14
    {
15
        return $this->getModule()->getUserIdentity() !== null;
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getModule()->getUserIdentity() targeting rhertogh\Yii2Oauth2Serve...dule::getUserIdentity() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
16
    }
17
18
    public function processAuthorization()
19
    {
20
        if ($this->isApproved()) {
21
            $this->getModule()->logoutUser();
22
        }
23
24
        $this->setCompleted(true);
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function getEndSessionRequestUrl()
31
    {
32
        return UrlHelper::addQueryParams(
33
            $this->getEndSessionUrl(),
34
            [
35
                'endSessionAuthorizationRequestId' => $this->getRequestId()
36
            ]
37
        );
38
    }
39
40
    public function autoApproveAndProcess()
41
    {
42
        if ($this->getEndUserAuthorizationRequired()) {
43
            throw new InvalidCallException('Auto approve is only allowed if end-user authorization is not required.');
44
        }
45
46
        $this->setAuthorizationStatus(Oauth2BaseAuthorizationRequest::AUTHORIZATION_APPROVED);
47
        $this->processAuthorization();
48
    }
49
50
    public function getRequestCompletedRedirectUrl($ignoreApprovalStatus = false)
51
    {
52
        if (!$this->isApproved()) {
53
            return $this->getDeniedRedirectUrl();
54
        }
55
56
        $redirectUri = $this->getRedirectUri();
57
58
        if (!$redirectUri) {
59
            return $this->getDefaultRedirectUrl();
60
        }
61
62
        // Return the original `post_logout_redirect_uri` with the `state`
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
63
        return UrlHelper::addQueryParams($redirectUri, ['state' => $this->getState()]);
64
    }
65
66
    protected function getDefaultRedirectUrl()
67
    {
68
        return Yii::$app->getHomeUrl();
69
    }
70
71
    protected function getDeniedRedirectUrl()
72
    {
73
        return Yii::$app->getHomeUrl();
74
    }
75
}
76