ProxyRestriction::getCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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\Assertion;
13
14
use LightSaml\Model\Context\DeserializationContext;
15
use LightSaml\Model\Context\SerializationContext;
16
use LightSaml\SamlConstants;
17
18
class ProxyRestriction extends AbstractCondition
19
{
20
    /**
21
     * @var int|null
22
     */
23
    protected $count;
24
25
    /**
26
     * @var string[]|null
27
     */
28
    protected $audience;
29
30
    /**
31
     * @param int      $count
32
     * @param string[] $audience
33
     */
34 9
    public function __construct($count = null, array $audience = null)
35
    {
36 9
        $this->count = $count;
37 9
        $this->audience = $audience;
38 9
    }
39
40
    /**
41
     * @param string $audience
42
     *
43
     * @return ProxyRestriction
44
     */
45
    public function addAudience($audience)
46
    {
47
        if (false == is_array($this->audience)) {
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...
48
            $this->audience = array();
49
        }
50
        $this->audience[] = (string) $audience;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @return null|\string[]
57
     */
58 2
    public function getAllAudience()
59
    {
60 2
        return $this->audience;
61
    }
62
63
    /**
64
     * @param int|null $count
65
     *
66
     * @return ProxyRestriction
67
     */
68
    public function setCount($count)
69
    {
70
        $this->count = null !== $count ? intval($count) : null;
71
72
        return $this;
73
    }
74
75
    /**
76
     * @return int|null
77
     */
78 3
    public function getCount()
79
    {
80 3
        return $this->count;
81
    }
82
83
    /**
84
     * @param \DOMNode             $parent
85
     * @param SerializationContext $context
86
     *
87
     * @return void
88
     */
89 View Code Duplication
    public function serialize(\DOMNode $parent, SerializationContext $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...
90
    {
91
        $result = $this->createElement('ProxyRestriction', SamlConstants::NS_ASSERTION, $parent, $context);
92
93
        $this->attributesToXml(array('count'), $result);
94
95
        $this->manyElementsToXml($this->getAllAudience(), $result, $context, 'Audience');
96
    }
97
98
    /**
99
     * @param \DOMNode               $node
100
     * @param DeserializationContext $context
101
     */
102 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...
103
    {
104
        $this->checkXmlNodeName($node, 'ProxyRestriction', SamlConstants::NS_ASSERTION);
105
106
        $this->attributesFromXml($node, array('count'));
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...
107
108
        $this->manyElementsFromXml($node, $context, 'Audience', 'saml', null, 'addAudience');
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...
109
    }
110
}
111