Passed
Push — release-4-alpha ( 8fbd76...340a81 )
by Tim
03:38 queued 43s
created

SignedElement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 1 1
A setSignatureKey() 0 1 1
A setCertificates() 0 1 1
A getSignatureKey() 0 1 1
A getCertificates() 0 1 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2;
6
7
use RobRichards\XMLSecLibs\XMLSecurityKey;
8
9
/**
10
 * Interface to a SAML 2 element which may be signed.
11
 *
12
 * @package SimpleSAMLphp
13
 */
14
abstract class SignedElement
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
     * Validate this element against a public key.
35
     *
36
     * If no signature is present, false is returned. If a signature is present,
37
     * but cannot be verified, an exception will be thrown.
38
     *
39
     * @param  XMLSecurityKey $key The key we should check against.
40
     * @return bool True if successful, false if we don't have a signature that can be verified.
41
     */
42
    public function validate(XMLSecurityKey $key) : bool;
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 boolean. 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...
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
    public function validate(/** @scrutinizer ignore-unused */ XMLSecurityKey $key) : bool;

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
44
45
    /**
46
     * Set the certificates that should be included in the element.
47
     * The certificates should be strings with the PEM encoded data.
48
     *
49
     * @param array $certificates An array of certificates.
50
     * @return void
51
     */
52
    public function setCertificates(array $certificates);
0 ignored issues
show
Unused Code introduced by
The parameter $certificates is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

52
    public function setCertificates(/** @scrutinizer ignore-unused */ array $certificates);

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
54
55
    /**
56
     * Retrieve the certificates that are included in the element (if any).
57
     *
58
     * @return array An array of certificates.
59
     */
60
    public function getCertificates() : array;
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...
61
62
63
    /**
64
     * Retrieve the private key we should use to sign the element.
65
     *
66
     * @return XMLSecurityKey|null The key, or NULL if no key is specified.
67
     */
68
    public function getSignatureKey();
69
70
71
    /**
72
     * Set the private key we should use to sign the element.
73
     * If the key is null, the message will be sent unsigned.
74
     *
75
     * @param XMLSecurityKey|null $signatureKey
76
     * @return void
77
     */
78
    public function setSignatureKey(XMLSecurityKey $signatureKey = null);
0 ignored issues
show
Unused Code introduced by
The parameter $signatureKey is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function setSignatureKey(/** @scrutinizer ignore-unused */ XMLSecurityKey $signatureKey = null);

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
}
80