MetadataFilterResolver::resolve()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 9.0468

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
rs 8.0555
cc 9
nc 5
nop 2
crap 9.0468
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\Credential;
13
14
use LightSaml\Model\Metadata\IdpSsoDescriptor;
15
use LightSaml\Model\Metadata\SpSsoDescriptor;
16
use LightSaml\Credential\Context\MetadataCredentialContext;
17
use LightSaml\Credential\CredentialInterface;
18
use LightSaml\Criteria\CriteriaSet;
19
use LightSaml\Credential\Criteria\MetadataCriteria;
20
21
class MetadataFilterResolver extends AbstractQueryableResolver
22
{
23
    /**
24
     * @param CriteriaSet           $criteriaSet
25
     * @param CredentialInterface[] $arrCredentials
26
     *
27
     * @return CredentialInterface[]
28
     */
29 10
    public function resolve(CriteriaSet $criteriaSet, array $arrCredentials = array())
30
    {
31 10
        if (false == $criteriaSet->has(MetadataCriteria::class)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
32
            return $arrCredentials;
33
        }
34
35 10
        $result = array();
36 10
        foreach ($criteriaSet->get(MetadataCriteria::class) as $criteria) {
37
            /* @var MetadataCriteria $criteria */
38 10
            foreach ($arrCredentials as $credential) {
39
                /** @var MetadataCredentialContext $metadataContext */
40 10
                $metadataContext = $credential->getCredentialContext()->get(MetadataCredentialContext::class);
41 10
                if (false == $metadataContext ||
42 7
                    MetadataCriteria::TYPE_IDP == $criteria->getMetadataType() && $metadataContext->getRoleDescriptor() instanceof IdpSsoDescriptor ||
43 10
                    MetadataCriteria::TYPE_SP == $criteria->getMetadataType() && $metadataContext->getRoleDescriptor() instanceof SpSsoDescriptor
44
                ) {
45 10
                    $result[] = $credential;
46
                }
47
            }
48
        }
49
50 10
        return $result;
51
    }
52
}
53