ServiceInfoCollection::findByAS()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.2
cc 4
eloc 8
nc 3
nop 1
crap 4
1
<?php
2
3
namespace AerialShip\SamlSPBundle\Config;
4
5
class ServiceInfoCollection
6
{
7
    /** @var ServiceInfo[] */
8
    private $data = array();
9
10
11
    /**
12
     * @param ServiceInfo $serviceInfo
13
     */
14 6
    public function add(ServiceInfo $serviceInfo)
15
    {
16 6
        $this->data[$serviceInfo->getAuthenticationService()] = $serviceInfo;
17 6
    }
18
19
20
    /**
21
     * @param string $id
22
     * @return ServiceInfo|null
23
     */
24 3
    public function get($id)
25
    {
26 3
        if (isset($this->data[$id])) {
27 2
            return $this->data[$id];
28
        }
29 1
        return null;
30
    }
31
32
33
    /**
34
     * @return ServiceInfo[]
35
     */
36 2
    public function all()
37
    {
38 2
        return $this->data;
39
    }
40
41
42
    /**
43
     * @param string $entityID
44
     * @return ServiceInfo|null
45
     */
46 2
    public function findByIDPEntityID($entityID)
47
    {
48 2
        $result = null;
49 2
        foreach ($this->data as $provider) {
50 1
            if ($entityID == $provider->getIdpProvider()->getEntityDescriptor()->getEntityID()) {
51 1
                $result = $provider;
52 1
                break;
53
            }
54 2
        }
55 2
        return $result;
56
    }
57
58
59
    /**
60
     * @param string|null $as
61
     * @return ServiceInfo|null
62
     */
63 3
    public function findByAS($as)
64
    {
65 3
        $result = null;
66 3
        if (!$as && count($this->data)==1) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $as of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
67 1
            $arr = $this->data;
68 1
            $result = array_pop($arr);
69 3
        } else if ($as) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $as of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
70 1
            $result = $this->get($as);
71 1
        }
72 3
        return $result;
73
    }
74
}
75