AssertionValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addConstraintValidator() 0 11 3
A validate() 0 9 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assertion\Validation;
6
7
use SimpleSAML\SAML2\Configuration\IdentityProvider;
8
use SimpleSAML\SAML2\Configuration\IdentityProviderAware;
9
use SimpleSAML\SAML2\Configuration\ServiceProvider;
10
use SimpleSAML\SAML2\Configuration\ServiceProviderAware;
11
use SimpleSAML\SAML2\XML\saml\Assertion;
12
13
class AssertionValidator
14
{
15
    /**
16
     * @var \SimpleSAML\SAML2\Assertion\Validation\AssertionConstraintValidator[]
17
     */
18
    protected array $constraints;
19
20
21
    /**
22
     * @param \SimpleSAML\SAML2\Configuration\IdentityProvider $identityProvider
23
     * @param \SimpleSAML\SAML2\Configuration\ServiceProvider  $serviceProvider
24
     */
25
    public function __construct(
26
        private IdentityProvider $identityProvider,
27
        private ServiceProvider $serviceProvider,
28
    ) {
29
    }
30
31
32
    /**
33
     * @param \SimpleSAML\SAML2\Assertion\Validation\AssertionConstraintValidator $constraint
34
     */
35
    public function addConstraintValidator(AssertionConstraintValidator $constraint): void
36
    {
37
        if ($constraint instanceof IdentityProviderAware) {
38
            $constraint->setIdentityProvider($this->identityProvider);
39
        }
40
41
        if ($constraint instanceof ServiceProviderAware) {
42
            $constraint->setServiceProvider($this->serviceProvider);
43
        }
44
45
        $this->constraints[] = $constraint;
46
    }
47
48
49
    /**
50
     * @param \SimpleSAML\SAML2\XML\saml\Assertion $assertion
51
     * @return \SimpleSAML\SAML2\Assertion\Validation\Result
52
     */
53
    public function validate(Assertion $assertion): Result
54
    {
55
        $result = new Result();
56
57
        foreach ($this->constraints as $validator) {
58
            $validator->validate($assertion, $result);
59
        }
60
61
        return $result;
62
    }
63
}
64