ServiceTypeEndpointResolver::resolve()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
rs 9.6111
cc 5
nc 5
nop 2
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Resolver\Endpoint;
13
14
use LightSaml\Criteria\CriteriaSet;
15
use LightSaml\Model\Metadata\EndpointReference;
16
use LightSaml\Resolver\Endpoint\Criteria\ServiceTypeCriteria;
17
18
/**
19
 * Filters out those endpoint candidates which are not an instance of the type
20
 * specified in the ServiceTypeCriteria. If criteria set does not have
21
 * ServiceTypeCriteria it will return all endpoint candidates.
22
 */
23
class ServiceTypeEndpointResolver implements EndpointResolverInterface
24
{
25
    /**
26
     * @param EndpointReference[] $candidates
27
     *
28
     * @return EndpointReference[]
29
     */
30
    public function resolve(CriteriaSet $criteriaSet, array $candidates)
31
    {
32
        if (false === $criteriaSet->has(ServiceTypeCriteria::class)) {
33
            return $candidates;
34
        }
35
36
        $result = [];
37
        /** @var ServiceTypeCriteria $serviceTypeCriteria */
38
        foreach ($criteriaSet->get(ServiceTypeCriteria::class) as $serviceTypeCriteria) {
39
            foreach ($candidates as $endpointReference) {
40
                $type = $serviceTypeCriteria->getServiceType();
41
                if ($endpointReference->getEndpoint() instanceof $type) {
42
                    $result[] = $endpointReference;
43
                }
44
            }
45
        }
46
47
        return $result;
48
    }
49
}
50