Completed
Push — master ( 4ef642...49bb93 )
by Julien
02:53
created

TableCell::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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 NONINFRINGEMENT. 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
namespace PHPHealth\CDA\Elements;
26
27
use PHPHealth\CDA\Elements\AbstractElement;
28
use PHPHealth\CDA\Elements\TableRow;
29
use PHPHealth\CDA\Elements\ReferenceType;
30
31
/**
32
 * 
33
 *
34
 * @author Julien Fastré <[email protected]>
35
 */
36
class TableCell extends AbstractElement
37
{
38
    /**
39
     *
40
     * @var string
41
     */
42
    private $content;
43
    
44
    /**
45
     *
46
     * @var ReferenceType
47
     */
48
    private $reference;
49
    
50
    /**
51
     *
52
     * @var TableRow
53
     */
54
    private $row;
55
    
56
    /**
57
     * a string determining if the row is th or td
58
     *
59
     * @var string
60
     */
61
    private $level;
62
    
63
    const TH = 'th';
64
    const TD = 'td';
65
    
66
    
67
    function __construct($level, TableRow $row = null, $content = '')
0 ignored issues
show
Unused Code introduced by
The parameter $row is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
68
    {
69
        $this->setContent($content);
70
        $this->level = $level;
71
    }
72
    
73
    /**
74
     * 
75
     * @return string
76
     */
77
    function getContent()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
78
    {
79
        return $this->content;
80
    }
81
82
    /**
83
     * 
84
     * @param string $content
85
     * @return $this
86
     */
87
    function setContent($content)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
88
    {
89
        $this->content = $content;
90
        
91
        return $this;
92
    }
93
    
94
    /**
95
     * 
96
     * @return TableRow
97
     */
98
    function getRow(): TableRow
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
99
    {
100
        return $this->row;
101
    }
102
103
    /**
104
     * 
105
     * @param TableRow $row
106
     * @return $this
107
     */
108
    function setRow(TableRow $row)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
109
    {
110
        $this->row = $row;
111
        
112
        return $this;
113
    }
114
    
115
    /**
116
     * 
117
     * @return ReferenceType
118
     */
119
    function getReference()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
120
    {
121
        return $this->reference;
122
    }
123
124
    /**
125
     * 
126
     * @param ReferenceType $reference
127
     * @return $this
128
     */
129
    function setReference(ReferenceType $reference)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
130
    {
131
        $this->reference = $reference;
132
        
133
        return $this;
134
    }
135
136
    
137
    /**
138
     * 
139
     * @return boolean
140
     */
141
    public function isEmpty()
142
    {
143
        return empty($this->getContent());
144
    }
145
        
146
    protected function getElementTag(): string
147
    {
148
        return $this->level;
149
    }
150
151 View Code Duplication
    public function toDOMElement(\DOMDocument $doc): \DOMElement
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...
152
    {
153
        $el = $this->createElement($doc);
154
        
155
        if ($this->getReference() !== null) {
156
            $this->getReference()->setValueToElement($el, $doc);
157
        }
158
        
159
        $el->appendChild($doc->createTextNode($this->getContent()));
160
        
161
        return $el;
162
    }
163
}
164