Boolean::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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::getNS(), $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