AlgorithmFilterResolver::resolve()   B
last analyzed

Complexity

Conditions 8
Paths 5

Size

Total Lines 19
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 19
rs 8.4444
cc 8
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\CredentialInterface;
15
use LightSaml\Credential\Criteria\AlgorithmCriteria;
16
use LightSaml\Criteria\CriteriaSet;
17
18
class AlgorithmFilterResolver extends AbstractQueryableResolver
19
{
20
    /**
21
     * @param CredentialInterface[] $arrCredentials
22
     *
23
     * @return CredentialInterface[]
24
     */
25
    public function resolve(CriteriaSet $criteriaSet, array $arrCredentials = [])
26
    {
27
        if (false == $criteriaSet->has(AlgorithmCriteria::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...
28
            return $arrCredentials;
29
        }
30
31
        $result = [];
32
        foreach ($criteriaSet->get(AlgorithmCriteria::class) as $criteria) {
33
            /* @var AlgorithmCriteria $criteria */
34
            foreach ($arrCredentials as $credential) {
35
                if (($credential->getPrivateKey() && $credential->getPrivateKey()->getAlgorith() == $criteria->getAlgorithm()) ||
36
                    ($credential->getPublicKey() && $credential->getPublicKey()->getAlgorith() == $criteria->getAlgorithm())
37
                ) {
38
                    $result[] = $credential;
39
                }
40
            }
41
        }
42
43
        return $result;
44
    }
45
}
46