SignedElement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 1
1
<?php
2
3
4
namespace flipbox\saml\core\validators;
5
6
use flipbox\saml\core\AbstractPlugin;
7
use RobRichards\XMLSecLibs\XMLSecurityKey;
8
use SAML2\SignedElement as SamlSignedElement;
9
10
class SignedElement
11
{
12
    /**
13
     * @var XMLSecurityKey[]
14
     */
15
    private $xmlSecurityKeyStore;
16
17
    /**
18
     * SignedElement constructor.
19
     * @param XMLSecurityKey[] $xmlSecurityKeyStore
20
     */
21
    public function __construct(array $xmlSecurityKeyStore)
22
    {
23
        $this->xmlSecurityKeyStore = $xmlSecurityKeyStore;
24
    }
25
26
27
    public function validate(SamlSignedElement $signedElement, $result)
28
    {
29
        /** @var \Exception $error */
30
        $errors = [];
31
        $success = false;
0 ignored issues
show
Unused Code introduced by
$success is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
32
        foreach ($this->xmlSecurityKeyStore as $key) {
33
            try {
34
                if ($success = $signedElement->validate($key)) {
0 ignored issues
show
Unused Code introduced by
$success is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
                    // return on success ... no need to continue
36
                    return $result;
37
                }
38
            } catch (\Exception $e) {
39
                $errors[] = $e;
40
                \Craft::info($e->getMessage(), AbstractPlugin::SAML_CORE_HANDLE);
41
            }
42
        }
43
44
        if (! empty($errors)) {
45
            throw $errors[0];
46
        }
47
48
        return $result;
49
    }
50
}
51