Failed Conditions
Push — issue#702_rs ( ed72a1...cdafcf )
by Guilherme
07:33
created

HostBelongsToClaimProviderValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 19 4
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\RemoteClaimsBundle\Validator\Constraints;
12
13
use LoginCidadao\RemoteClaimsBundle\Model\HttpUri;
14
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface;
15
use Symfony\Component\Validator\Constraint;
16
use Symfony\Component\Validator\ConstraintValidator;
17
18
class HostBelongsToClaimProviderValidator extends ConstraintValidator
19
{
20
21
    /**
22
     * Checks if the passed value is valid.
23
     *
24
     * @param mixed $value The value that should be validated
25
     * @param Constraint $constraint The constraint for the validation
26
     */
27
    public function validate($value, Constraint $constraint)
28
    {
29
        if ($value instanceof RemoteClaimInterface) {
30
31
            $host = $value->getName()->getAuthorityName();
32
            $provider = $value->getProvider();
33
34
            $redirectUris = $provider->getRedirectUris();
35
            foreach ($redirectUris as $redirectUri) {
36
                $uri = HttpUri::parseUri($redirectUri);
37
                if ($uri['host'] === $host) {
38
                    return;
39
                }
40
            }
41
42
43
            $this->context->buildViolation($constraint->message)
44
                ->setParameter('{{ host }}', $host)
45
                ->addViolation();
46
        }
47
    }
48
}
49