UsageFilterResolver::resolve()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.0493

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
rs 9.0444
cc 6
nc 5
nop 2
crap 6.0493
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\Criteria\CriteriaSet;
16
use LightSaml\Credential\Criteria\UsageCriteria;
17
18
class UsageFilterResolver 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(UsageCriteria::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
            return $arrCredentials;
30
        }
31
32 10
        $result = array();
33 10
        foreach ($criteriaSet->get(UsageCriteria::class) as $criteria) {
34
            /* @var UsageCriteria $criteria */
35 10
            foreach ($arrCredentials as $credential) {
36 10
                if (false == $credential->getUsageType() || $criteria->getUsage() == $credential->getUsageType()) {
37 10
                    $result[] = $credential;
38
                }
39
            }
40
        }
41
42 10
        return $result;
43
    }
44
}
45