MetadataFilterResolver::resolve()   B
last analyzed

Complexity

Conditions 9
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 8.0555
cc 9
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\Credential;
13
14
use LightSaml\Credential\Context\MetadataCredentialContext;
15
use LightSaml\Credential\CredentialInterface;
16
use LightSaml\Credential\Criteria\MetadataCriteria;
17
use LightSaml\Criteria\CriteriaSet;
18
use LightSaml\Model\Metadata\IdpSsoDescriptor;
19
use LightSaml\Model\Metadata\SpSsoDescriptor;
20
21
class MetadataFilterResolver extends AbstractQueryableResolver
22
{
23
    /**
24
     * @param CredentialInterface[] $arrCredentials
25
     *
26
     * @return CredentialInterface[]
27
     */
28
    public function resolve(CriteriaSet $criteriaSet, array $arrCredentials = [])
29
    {
30
        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...
31
            return $arrCredentials;
32
        }
33
34
        $result = [];
35
        foreach ($criteriaSet->get(MetadataCriteria::class) as $criteria) {
36
            /* @var MetadataCriteria $criteria */
37
            foreach ($arrCredentials as $credential) {
38
                /** @var MetadataCredentialContext $metadataContext */
39
                $metadataContext = $credential->getCredentialContext()->get(MetadataCredentialContext::class);
40
                if (false == $metadataContext ||
41
                    MetadataCriteria::TYPE_IDP == $criteria->getMetadataType() && $metadataContext->getRoleDescriptor() instanceof IdpSsoDescriptor ||
42
                    MetadataCriteria::TYPE_SP == $criteria->getMetadataType() && $metadataContext->getRoleDescriptor() instanceof SpSsoDescriptor
43
                ) {
44
                    $result[] = $credential;
45
                }
46
            }
47
        }
48
49
        return $result;
50
    }
51
}
52