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

Oauth2AuthorizeEndSessionAction::run()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 16
cp 0
rs 9.1111
cc 6
nc 12
nop 1
crap 42
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\controllers\web\consent;
4
5
use rhertogh\Yii2Oauth2Server\controllers\web\base\Oauth2BaseWebAction;
6
use rhertogh\Yii2Oauth2Server\controllers\web\Oauth2ConsentController;
7
use rhertogh\Yii2Oauth2Server\exceptions\Oauth2ServerHttpException;
0 ignored issues
show
Bug introduced by
The type rhertogh\Yii2Oauth2Serve...uth2ServerHttpException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use rhertogh\Yii2Oauth2Server\interfaces\controllers\web\consent\Oauth2AuthorizeEndSessionActionInterface;
9
use Yii;
10
use yii\base\InvalidConfigException;
11
use yii\web\BadRequestHttpException;
12
use yii\web\HttpException;
13
use yii\web\ServerErrorHttpException;
14
15
/**
16
 * @property Oauth2ConsentController $controller
17
 */
18
class Oauth2AuthorizeEndSessionAction extends Oauth2BaseWebAction implements Oauth2AuthorizeEndSessionActionInterface
19
{
20
    /**
21
     * Path to view file for End Session authorization.
22
     * @var string|null
23
     */
24
    public $openIdConnectLogoutConfirmationView = null;
25
26
    public function init()
27
    {
28
        parent::init();
29
        if (empty($this->openIdConnectLogoutConfirmationView)) {
30
            throw new InvalidConfigException('$openIdConnectLogoutConfirmationView must be set.');
31
        }
32
    }
33
34
    public function run($endSessionAuthorizationRequestId)
35
    {
36
        try {
37
            $module = $this->controller->module;
38
39
            $endSessionAuthorizationRequest = $module->getEndSessionAuthReqSession($endSessionAuthorizationRequestId);
40
41
            if (empty($endSessionAuthorizationRequest)) {
42
                throw new BadRequestHttpException(Yii::t('oauth2', 'Invalid endSessionAuthorizationRequestId.'));
43
            }
44
45
            if (
46
                $endSessionAuthorizationRequest->load(Yii::$app->request->post())
0 ignored issues
show
Bug introduced by
It seems like Yii::app->request->post() can also be of type object; however, parameter $data of rhertogh\Yii2Oauth2Serve...equestInterface::load() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
                $endSessionAuthorizationRequest->load(/** @scrutinizer ignore-type */ Yii::$app->request->post())
Loading history...
47
                && $endSessionAuthorizationRequest->validate()
48
            ) {
49
                return $module->generateEndSessionAuthReqCompledRedirectResponse($endSessionAuthorizationRequest);
50
            }
51
52
            return $this->controller->render($this->openIdConnectLogoutConfirmationView, [
53
                'endSessionAuthorizationRequest' => $endSessionAuthorizationRequest,
54
            ]);
55
        } catch (\Exception $e) {
56
            $message = Yii::t('oauth2', 'Unable to respond to logout authorization request.');
57
            if ($e instanceof HttpException) {
58
                $message .= ' ' . $e->getMessage();
59
            }
60
            throw new ServerErrorHttpException($message, 0, $e);
61
        }
62
    }
63
}
64