Passed
Push — master ( 6db269...70aff8 )
by Jaime Pérez
02:49
created

SignedElement::getValidatingCertificates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2;
6
7
use RobRichards\XMLSecLibs\XMLSecurityKey;
8
9
/**
10
 * Abstract class to a SAML 2 element which may be signed.
11
 *
12
 * @package simplesamlphp/saml2
13
 */
14
abstract class SignedElement implements SignedElementInterface
15
{
16
    /**
17
     * The private key we should use to sign the message.
18
     *
19
     * The private key can be null, in which case the message is sent unsigned.
20
     *
21
     * @var XMLSecurityKey|null
22
     */
23
    protected $signatureKey;
24
25
    /**
26
     * List of certificates that should be included in the message.
27
     *
28
     * @var array
29
     */
30
    protected $certificates = [];
31
32
33
    /**
34
     * Retrieve certificates that sign this element.
35
     *
36
     * @return array Array with certificates.
37
     * @throws \Exception if an error occurs while trying to extract the public key from a certificate.
38
     */
39
    public function getValidatingCertificates(): array
40
    {
41
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
42
43
44
    /**
45
     * Validate this element against a public key.
46
     *
47
     * If no signature is present, false is returned. If a signature is present,
48
     * but cannot be verified, an exception will be thrown.
49
     *
50
     * @param  XMLSecurityKey $key The key we should check against.
51
     * @return bool True if successful, false if we don't have a signature that can be verified.
52
     */
53
    abstract public function validate(XMLSecurityKey $key): bool;
54
55
56
    /**
57
     * Set the certificates that should be included in the element.
58
     * The certificates should be strings with the PEM encoded data.
59
     *
60
     * @param string[] $certificates An array of certificates.
61
     * @return void
62
     */
63
    public function setCertificates(array $certificates): void
64
    {
65
        $this->certificates = $certificates;
66
    }
67
68
69
    /**
70
     * Retrieve the certificates that are included in the message.
71
     *
72
     * @return string[] An array of certificates
73
     */
74
    public function getCertificates(): array
75
    {
76
        return $this->certificates;
77
    }
78
79
80
    /**
81
     * Set the private key we should use to sign the message.
82
     *
83
     * If the key is null, the message will be sent unsigned.
84
     *
85
     * @param XMLSecurityKey|null $signingKey
86
     * @return void
87
     */
88
    public function setSigningKey(XMLSecurityKey $signingKey = null): void
89
    {
90
        $this->signatureKey = $signingKey;
91
    }
92
}
93