SetNameIdAction   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 17
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A doExecute() 0 11 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