AssertionValidatorAction::doExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Action\Assertion\Inbound;
13
14
use LightSaml\Action\Assertion\AbstractAssertionAction;
15
use LightSaml\Context\Profile\AssertionContext;
16
use LightSaml\Validator\Model\Assertion\AssertionValidatorInterface;
17
use Psr\Log\LoggerInterface;
18
19
class AssertionValidatorAction extends AbstractAssertionAction
20
{
21
    /** @var AssertionValidatorInterface */
22
    protected $assertionValidator;
23
24
    /**
25
     * @param LoggerInterface             $logger
26
     * @param AssertionValidatorInterface $assertionValidator
27
     */
28 3
    public function __construct(LoggerInterface $logger, AssertionValidatorInterface $assertionValidator)
29
    {
30 3
        parent::__construct($logger);
31
32 3
        $this->assertionValidator = $assertionValidator;
33 3
    }
34
35
    /**
36
     * @param AssertionContext $context
37
     */
38 2
    protected function doExecute(AssertionContext $context)
39
    {
40 2
        $this->assertionValidator->validateAssertion($context->getAssertion());
0 ignored issues
show
Bug introduced by
It seems like $context->getAssertion() can be null; however, validateAssertion() 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...
41 2
    }
42
}
43