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

DestinationMatches::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
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\ConstraintValidation\Response;
6
7
use SimpleSAML\SAML2\{Binding, Metadata};
8
use SimpleSAML\SAML2\Exception\Protocol\ResourceNotRecognizedException;
9
use SimpleSAML\SAML2\Process\{ServiceProviderAwareInterface, ServiceProviderAwareTrait};
10
use SimpleSAML\SAML2\Process\ConstraintValidation\ConstraintValidatorInterface;
11
use SimpleSAML\XML\SerializableElementInterface;
12
13
final class DestinationMatches implements ConstraintValidatorInterface
14
{
15
    /**
16
     * DestinationMatches constructor.
17
     *
18
     * @param \SimpleSAML\SAML2\Metadata\ServiceProvider $spMetadata
19
     * @param \SimpleSAML\SAML2\Binding $binding
20
     */
21
    public function __construct(
22
        private Metadata\ServiceProvider $spMetadata,
23
        private Binding $binding,
24
    ) {
25
    }
26
27
28
    /**
29
     * @param \SimpleSAML\XML\SerializableElementInterface $response
30
     */
31
    public function validate(SerializableElementInterface $response): void
32
    {
33
        // Validate that the destination matches the appropriate endpoint from the SP-metadata
34
        foreach ($this->spMetadata->getAssertionConsumerService() as $assertionConsumerService) {
35
            if ($assertionConsumerService->getLocation() === $response->getDestination()) {
0 ignored issues
show
Bug introduced by
The method getDestination() does not exist on SimpleSAML\XML\SerializableElementInterface. It seems like you code against a sub-type of SimpleSAML\XML\SerializableElementInterface such as SimpleSAML\SAML2\XML\samlp\AbstractMessage. ( Ignorable by Annotation )

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

35
            if ($assertionConsumerService->getLocation() === $response->/** @scrutinizer ignore-call */ getDestination()) {
Loading history...
36
                if (Binding::getBinding($assertionConsumerService->getBinding()) instanceof $this->binding) {
37
                    return;
38
                }
39
            }
40
        }
41
        throw new ResourceNotRecognizedException();
42
    }
43
}
44