Passed
Push — master ( 26e0e4...4a85b9 )
by Peter
10:37
created

Boolean   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 4 1
A getValue() 0 3 1
A setValueToElement() 0 4 1
A getAttribute() 0 3 1
A __construct() 0 4 1
A setValue() 0 6 3
1
<?php
2
/**
3
 * The MIT License
4
 *
5
 * Copyright 2017 Julien Fastré <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
26
namespace i3Soft\CDA\DataType\Boolean;
27
28
use i3Soft\CDA\ClinicalDocument as CDA;
29
use i3Soft\CDA\DataType\AnyType;
30
31
/**
32
 * Boolean attribute
33
 *
34
 * As the boolean type may have different attribute values
35
 *
36
 * @author Julien Fastré <[email protected]>
37
 */
38
class Boolean extends AnyType
39
{
40
    protected $value;
41
    protected $attribute;
42
43
    /**
44
     * Boolean constructor.
45
     *
46
     * @param      $attribute
47
     * @param      $value
48
     */
49
    public function __construct($attribute, $value)
50
    {
51
        $this->setAttribute($attribute);
52
        $this->setValue($value);
53
    }
54
55
    /**
56
     * @param \DOMElement       $el
57
     * @param \DOMDocument|NULL $doc
58
     */
59
    public function setValueToElement(\DOMElement $el, \DOMDocument $doc)
60
    {
61
        \assert($this->getAttribute() !== null, new \RuntimeException('The tag on boolean must be defined'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAttribute() targeting i3Soft\CDA\DataType\Bool...Boolean::getAttribute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
62
        $el->setAttributeNS(CDA::NS_CDA, $this->getAttribute(), $this->getValue());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAttribute() targeting i3Soft\CDA\DataType\Bool...Boolean::getAttribute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
63
    }
64
65
    /**
66
     * @return null
67
     */
68
    public function getAttribute()
69
    {
70
        return $this->attribute;
71
    }
72
73
    /**
74
     * @param $attribute
75
     *
76
     * @return self
77
     */
78
    public function setAttribute($attribute): self
79
    {
80
        $this->attribute = $attribute;
81
        return $this;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getValue()
88
    {
89
        return $this->value;
90
    }
91
92
    /**
93
     * @param $value
94
     *
95
     * @return self
96
     */
97
    public function setValue($value): self
98
    {
99
        $this->value = $value === 'true' || $value
100
          ? 'true'
101
          : 'false';
102
        return $this;
103
    }
104
}
105