Failed Conditions
Pull Request — master (#790)
by Guilherme
05:12
created

HostBelongsToClaimProviderValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 12
cts 12
cp 1
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 2
    public function validate($value, Constraint $constraint)
28
    {
29 2
        if ($value instanceof RemoteClaimInterface) {
30
31 2
            $host = $value->getName()->getAuthorityName();
32 2
            $provider = $value->getProvider();
33
34 2
            $redirectUris = $provider->getRedirectUris();
35 2
            foreach ($redirectUris as $redirectUri) {
36 2
                $uri = HttpUri::parseUri($redirectUri);
37 2
                if ($uri['host'] === $host) {
38 2
                    return;
39
                }
40
            }
41
42
43 1
            $this->context->buildViolation($constraint->message)
44 1
                ->setParameter('{{ host }}', $host)
45 1
                ->addViolation();
46
        }
47 1
    }
48
}
49