Passed
Pull Request — master (#363)
by Tim
02:37
created

ValidatorTrait::addConstraintValidator()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Process\Validator;
6
7
use SimpleSAML\SAML2\Process\{IdentityProviderAwareInterface, ServiceProviderAwareInterface};
8
use SimpleSAML\SAML2\Process\ConstraintValidation\ConstraintValidatorInterface;
9
use SimpleSAML\XML\SerializableElementInterface;
10
11
trait ValidatorTrait
12
{
13
    /** @var array<\SimpleSAML\SAML2\Process\ConstraintValidation\ConstraintValidatorInterface> */
14
    protected array $validators;
15
16
17
    /**
18
     * Add a validation to the chain.
19
     *
20
     * @param \SimpleSAML\SAML2\Process\ConstraintValidation\ConstraintValidatorInterface $validation
21
     */
22
    public function addConstraintValidator(ConstraintValidatorInterface $validator)
23
    {
24
        if ($validator instanceof IdentityProviderAwareInterface) {
25
            $validator->setIdentityProvider($this->idpMetadata);
0 ignored issues
show
Bug introduced by
The method setIdentityProvider() does not exist on SimpleSAML\SAML2\Process...yProviderAwareInterface. ( Ignorable by Annotation )

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

25
            $validator->/** @scrutinizer ignore-call */ 
26
                        setIdentityProvider($this->idpMetadata);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method setIdentityProvider() does not exist on SimpleSAML\SAML2\Process...raintValidatorInterface. ( Ignorable by Annotation )

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

25
            $validator->/** @scrutinizer ignore-call */ 
26
                        setIdentityProvider($this->idpMetadata);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        }
27
28
        if ($validator instanceof ServiceProviderAwareInterface) {
29
            $validator->setServiceProvider($this->spMetadata);
0 ignored issues
show
Bug introduced by
The method setServiceProvider() does not exist on SimpleSAML\SAML2\Process...raintValidatorInterface. ( Ignorable by Annotation )

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

29
            $validator->/** @scrutinizer ignore-call */ 
30
                        setServiceProvider($this->spMetadata);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method setServiceProvider() does not exist on SimpleSAML\SAML2\Process...eProviderAwareInterface. ( Ignorable by Annotation )

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

29
            $validator->/** @scrutinizer ignore-call */ 
30
                        setServiceProvider($this->spMetadata);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
        }
31
32
        $this->validators[] = $validator;
33
    }
34
35
36
    /**
37
     * Runs all the validations in the validation chain.
38
     *
39
     * If this function returns, all validations have been succesful.
40
     *
41
     * @throws \SimpleSAML\SAML2\Exception\ConstraintViolationFailedException when one of the conditions fail.
42
     */
43
    public function validate(SerializableElementInterface $element): void
44
    {
45
        foreach ($this->validators as $validator) {
46
            $validator->validate($element);
47
        }
48
    }
49
}
50