Completed
Pull Request — master (#2)
by Markus
08:15
created

SetSessionIndexAction::doExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Logout package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the GPL-3 license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Logout\Action\Profile\Outbound\LogoutRequest;
13
14
use LightSaml\Action\Profile\AbstractProfileAction;
15
use LightSaml\Context\Profile\Helper\MessageContextHelper;
16
use LightSaml\Context\Profile\ProfileContext;
17
use LightSaml\Model\Assertion\NameID;
18
19
/**
20
 * Sets SessionIndex of the outbounding AuthnRequest with values given in the LogoutContext SsoSessionState.
21
 */
22
class SetSessionIndexAction extends AbstractProfileAction
23
{
24
    /**
25
     * @param ProfileContext $context
26
     */
27
    protected function doExecute(ProfileContext $context)
28
    {
29
        $logoutRequest = MessageContextHelper::asLogoutRequest($context->getOutboundContext());
0 ignored issues
show
Bug introduced by
It seems like $context->getOutboundContext() can be null; however, asLogoutRequest() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
30
        $ssoSessionState = $context->getLogoutSsoSessionState();
31
32
        $logoutRequest->setSessionIndex($ssoSessionState->getSessionIndex());
33
    }
34
}
35