SetStatusAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A doExecute() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-IDP 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\Idp\Action\Profile\Outbound\StatusResponse;
13
14
use LightSaml\Action\Profile\AbstractProfileAction;
15
use LightSaml\Context\Profile\Helper\MessageContextHelper;
16
use LightSaml\Context\Profile\ProfileContext;
17
use LightSaml\Model\Protocol\Status;
18
use LightSaml\Model\Protocol\StatusCode;
19
use LightSaml\SamlConstants;
20
use Psr\Log\LoggerInterface;
21
22
class SetStatusAction extends AbstractProfileAction
23
{
24
    /** @var string */
25
    protected $statusCode;
26
27
    /** @var string */
28
    protected $statusMessage;
29
30
    /**
31
     * @param LoggerInterface $logger
32
     * @param string          $statusCode
33
     * @param string          $statusMessage
34
     */
35
    public function __construct(LoggerInterface $logger, $statusCode = SamlConstants::STATUS_SUCCESS, $statusMessage = null)
36
    {
37
        parent::__construct($logger);
38
39
        $this->statusCode = $statusCode;
40
        $this->statusMessage = $statusMessage;
41
    }
42
43
    /**
44
     * @param ProfileContext $context
45
     */
46
    protected function doExecute(ProfileContext $context)
47
    {
48
        $statusResponse = MessageContextHelper::asStatusResponse($context->getOutboundContext());
0 ignored issues
show
Bug introduced by
It seems like $context->getOutboundContext() can be null; however, asStatusResponse() 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...
49
50
        $statusResponse->setStatus(new Status(new StatusCode($this->statusCode), $this->statusCode));
51
    }
52
}
53