IndexEndpointResolver::resolve()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 19.8497

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
ccs 3
cts 11
cp 0.2727
rs 8.9617
cc 6
nc 6
nop 2
crap 19.8497
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\Model\Metadata\EndpointReference;
15
use LightSaml\Model\Metadata\IndexedEndpoint;
16
use LightSaml\Resolver\Endpoint\Criteria\IndexCriteria;
17
use LightSaml\Criteria\CriteriaSet;
18
19
class IndexEndpointResolver implements EndpointResolverInterface
20
{
21
    /**
22
     * @param CriteriaSet         $criteriaSet
23
     * @param EndpointReference[] $candidates
24
     *
25
     * @return EndpointReference[]
26
     */
27 2
    public function resolve(CriteriaSet $criteriaSet, array $candidates)
28
    {
29 2
        if (false === $criteriaSet->has(IndexCriteria::class)) {
30 2
            return $candidates;
31
        }
32
33
        $result = array();
34
        /** @var IndexCriteria $indexCriteria */
35
        foreach ($criteriaSet->get(IndexCriteria::class) as $indexCriteria) {
36
            foreach ($candidates as $endpointReference) {
37
                $endpoint = $endpointReference->getEndpoint();
38
                if ($endpoint instanceof IndexedEndpoint) {
39
                    if ($endpoint->getIndex() == $indexCriteria->getIndex()) {
40
                        $result[] = $endpointReference;
41
                    }
42
                }
43
            }
44
        }
45
46
        return $result;
47
    }
48
}
49