AlgorithmFilterResolver::resolve()   B
last analyzed

Complexity

Conditions 8
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 29.9519

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 3
cts 10
cp 0.3
rs 8.4444
cc 8
nc 5
nop 2
crap 29.9519
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 CriteriaSet           $criteriaSet
22
     * @param CredentialInterface[] $arrCredentials
23
     *
24
     * @return CredentialInterface[]
25
     */
26 10
    public function resolve(CriteriaSet $criteriaSet, array $arrCredentials = array())
27
    {
28 10
        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...
29 10
            return $arrCredentials;
30
        }
31
32
        $result = array();
33
        foreach ($criteriaSet->get(AlgorithmCriteria::class) as $criteria) {
34
            /* @var AlgorithmCriteria $criteria */
35
            foreach ($arrCredentials as $credential) {
36
                if (($credential->getPrivateKey() && $credential->getPrivateKey()->getAlgorith() == $criteria->getAlgorithm()) ||
0 ignored issues
show
Deprecated Code introduced by
The method RobRichards\XMLSecLibs\X...urityKey::getAlgorith() has been deprecated.

This method has been deprecated.

Loading history...
37
                    ($credential->getPublicKey() && $credential->getPublicKey()->getAlgorith() == $criteria->getAlgorithm())
0 ignored issues
show
Deprecated Code introduced by
The method RobRichards\XMLSecLibs\X...urityKey::getAlgorith() has been deprecated.

This method has been deprecated.

Loading history...
38
                ) {
39
                    $result[] = $credential;
40
                }
41
            }
42
        }
43
44
        return $result;
45
    }
46
}
47