SetNameIdAction::doExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 8
cts 8
cp 1
cc 1
eloc 7
nc 1
nop 1
crap 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 NameID of the outbounding AuthnRequest with values given in the LogoutContext SsoSessionState.
21
 */
22
class SetNameIdAction extends AbstractProfileAction
23
{
24
    /**
25
     * @param ProfileContext $context
26
     */
27 1
    protected function doExecute(ProfileContext $context)
28
    {
29 1
        $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 1
        $ssoSessionState = $context->getLogoutSsoSessionState();
31
32 1
        $nameId = new NameID();
33 1
        $nameId->setValue($ssoSessionState->getNameId());
34 1
        $nameId->setFormat($ssoSessionState->getNameIdFormat());
35
36 1
        $logoutRequest->setNameID($nameId);
37 1
    }
38
}
39