SetNotOnOrAfterAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doExecute() 0 5 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\Provider\TimeProvider\TimeProviderInterface;
18
use Psr\Log\LoggerInterface;
19
20
/**
21
 * Sets NotOnOrAfter attribute of the outbounding LogoutRequest to the value given by timeProvider plus secondsSkew.
22
 */
23
class SetNotOnOrAfterAction extends AbstractProfileAction
24
{
25
    /** @var TimeProviderInterface */
26
    protected $timeProvider;
27
28
    /** @var int */
29
    protected $secondsSkew;
30
31
    /**
32
     * @param LoggerInterface       $logger
33
     * @param TimeProviderInterface $timeProvider
34
     * @param int                   $secondsSkew
35
     */
36 2
    public function __construct(LoggerInterface $logger, TimeProviderInterface $timeProvider, $secondsSkew)
37
    {
38 2
        parent::__construct($logger);
39 2
        $this->timeProvider = $timeProvider;
40 2
        $this->secondsSkew = $secondsSkew;
41 2
    }
42
43
    /**
44
     * @param ProfileContext $context
45
     */
46 1
    protected function doExecute(ProfileContext $context)
47
    {
48 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...
49 1
        $logoutRequest->setNotOnOrAfter($this->timeProvider->getTimestamp() + $this->secondsSkew);
50 1
    }
51
}
52