getAllSingleSignOnServicesByUrl()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 9.9
cc 3
nc 3
nop 1
crap 12
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\Model\Metadata;
13
14
use LightSaml\Model\Context\DeserializationContext;
15
use LightSaml\Model\Context\SerializationContext;
16
use LightSaml\Model\Assertion\Attribute;
17
use LightSaml\SamlConstants;
18
19
class IdpSsoDescriptor extends SSODescriptor
20
{
21
    /** @var bool|null */
22
    protected $wantAuthnRequestsSigned;
23
24
    /** @var SingleSignOnService[]|null */
25
    protected $singleSignOnServices;
26
27
    /** @var Attribute[]|null */
28
    protected $attributes;
29
30
    /**
31
     * @param bool|null $wantAuthnRequestsSigned
32
     *
33
     * @return IdpSsoDescriptor
34
     */
35 6
    public function setWantAuthnRequestsSigned($wantAuthnRequestsSigned)
36
    {
37 6
        $this->wantAuthnRequestsSigned = filter_var($wantAuthnRequestsSigned, FILTER_VALIDATE_BOOLEAN, ['flags' => FILTER_NULL_ON_FAILURE]);
38
39 6
        return $this;
40
    }
41
42
    /**
43
     * @return bool|null
44
     */
45 3
    public function getWantAuthnRequestsSigned()
46
    {
47 3
        return $this->wantAuthnRequestsSigned;
48
    }
49
50
    /**
51
     * @param SingleSignOnService $singleSignOnService
52
     *
53
     * @return IdpSsoDescriptor
54
     */
55 42
    public function addSingleSignOnService(SingleSignOnService $singleSignOnService)
56
    {
57 42
        if (false == is_array($this->singleSignOnServices)) {
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...
58 3
            $this->singleSignOnServices = array();
59
        }
60 42
        $this->singleSignOnServices[] = $singleSignOnService;
61
62 42
        return $this;
63
    }
64
65
    /**
66
     * @return SingleSignOnService[]|null
67
     */
68 14
    public function getAllSingleSignOnServices()
69
    {
70 14
        return $this->singleSignOnServices;
71
    }
72
73
    /**
74
     * @param string $url
75
     *
76
     * @return SingleSignOnService[]
77
     */
78
    public function getAllSingleSignOnServicesByUrl($url)
79
    {
80
        $result = array();
81
        foreach ($this->getAllSingleSignOnServices() as $svc) {
0 ignored issues
show
Bug introduced by
The expression $this->getAllSingleSignOnServices() of type array<integer,object<Lig...gleSignOnService>>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
82
            if ($svc->getLocation() == $url) {
83
                $result[] = $svc;
84
            }
85
        }
86
87
        return $result;
88
    }
89
90
    /**
91
     * @param string $binding
92
     *
93
     * @return SingleSignOnService[]
94
     */
95 1
    public function getAllSingleSignOnServicesByBinding($binding)
96
    {
97 1
        $result = array();
98 1
        foreach ($this->getAllSingleSignOnServices() as $svc) {
0 ignored issues
show
Bug introduced by
The expression $this->getAllSingleSignOnServices() of type array<integer,object<Lig...gleSignOnService>>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
99 1
            if ($svc->getBinding() == $binding) {
100 1
                $result[] = $svc;
101
            }
102
        }
103
104 1
        return $result;
105
    }
106
107
    /**
108
     * @param string|null $binding
109
     *
110
     * @return SingleSignOnService|null
111
     */
112 1 View Code Duplication
    public function getFirstSingleSignOnService($binding = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114 1
        foreach ($this->getAllSingleSignOnServices() as $svc) {
0 ignored issues
show
Bug introduced by
The expression $this->getAllSingleSignOnServices() of type array<integer,object<Lig...gleSignOnService>>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
115 1
            if (null == $binding || $svc->getBinding() == $binding) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $binding of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
116 1
                return $svc;
117
            }
118
        }
119
120
        return null;
121
    }
122
123
    /**
124
     * @param \LightSaml\Model\Assertion\Attribute $attribute
125
     *
126
     * @return IdpSsoDescriptor
127
     */
128 23
    public function addAttribute(Attribute $attribute)
129
    {
130 23
        if (false == is_array($this->attributes)) {
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...
131 3
            $this->attributes = array();
132
        }
133 23
        $this->attributes[] = $attribute;
134
135 23
        return $this;
136
    }
137
138
    /**
139
     * @return \LightSaml\Model\Assertion\Attribute[]|null
140
     */
141 3
    public function getAllAttributes()
142
    {
143 3
        return $this->attributes;
144
    }
145
146
    /**
147
     * @param \DOMNode             $parent
148
     * @param SerializationContext $context
149
     */
150 2
    public function serialize(\DOMNode $parent, SerializationContext $context)
151
    {
152 2
        $result = $this->createElement('IDPSSODescriptor', SamlConstants::NS_METADATA, $parent, $context);
153
154 2
        parent::serialize($result, $context);
155
156 2
        $this->attributesToXml(array('WantAuthnRequestsSigned'), $result);
157
158 2
        if ($this->getAllSingleSignOnServices()) {
159 2
            foreach ($this->getAllSingleSignOnServices() as $object) {
160 2
                $object->serialize($result, $context);
161
            }
162
        }
163 2
        if ($this->getAllAttributes()) {
164 2
            foreach ($this->getAllAttributes() as $object) {
165 2
                $object->serialize($result, $context);
166
            }
167
        }
168 2
    }
169
170
    /**
171
     * @param \DOMNode               $node
172
     * @param DeserializationContext $context
173
     */
174 40 View Code Duplication
    public function deserialize(\DOMNode $node, DeserializationContext $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
    {
176 40
        $this->checkXmlNodeName($node, 'IDPSSODescriptor', SamlConstants::NS_METADATA);
177
178 40
        parent::deserialize($node, $context);
179
180 40
        $this->attributesFromXml($node, array('WantAuthnRequestsSigned'));
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
181
182 40
        $this->singleSignOnServices = array();
183 40
        $this->manyElementsFromXml(
184 40
            $node,
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
185 40
            $context,
186 40
            'SingleSignOnService',
187 40
            'md',
188 40
            'LightSaml\Model\Metadata\SingleSignOnService',
189 40
            'addSingleSignOnService'
190
        );
191
192 40
        $this->attributes = array();
193 40
        $this->manyElementsFromXml(
194 40
            $node,
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
195 40
            $context,
196 40
            'Attribute',
197 40
            'saml',
198 40
            'LightSaml\Model\Assertion\Attribute',
199 40
            'addAttribute'
200
        );
201 40
    }
202
}
203