Code Duplication    Length = 47-63 lines in 2 locations

lib/Component/SingleComponent.php 1 location

@@ 37-99 (lines=63) @@
34
 *
35
 * @author Julien Fastré <[email protected]>
36
 */
37
class SingleComponent extends AbstractComponent implements HasTypeCode
38
{
39
    /**
40
     *
41
     * @var SingleComponent\Section[]
42
     */
43
    private $sections = array();
44
    
45
    /**
46
     * 
47
     * @return SingleComponent\Section[]
48
     */
49
    public function getSections()
50
    {
51
        return $this->sections;
52
    }
53
54
    /**
55
     * 
56
     * @param SingleComponent\Section[] $sections
57
     * @return $this
58
     */
59
    public function setSections($sections)
60
    {
61
        $this->sections = array();
62
        
63
        foreach ($sections as $section) {
64
            $this->addSection($section);
65
        }
66
        
67
        return $this;
68
    }
69
70
    /**
71
     * 
72
     * @param \PHPHealth\CDA\Component\SingleComponent\Section $section
73
     * @return $this
74
     */
75
    public function addSection(SingleComponent\Section $section)
76
    {
77
        $this->sections[] = $section;
78
        
79
        return $this;
80
    }
81
    
82
    public function getTypeCode(): string
83
    {
84
        return 'COMP';
85
    }
86
87
    
88
    public function toDOMElement(\DOMDocument $doc): \DOMElement
89
    {
90
        $component = $doc->createElement(CDA::NS_CDA.'component');
91
        $component->setAttribute(CDA::NS_CDA.'typeCode', $this->getTypeCode());
92
        
93
        foreach ($this->getSections() as $section) {
94
            $component->appendChild($section->toDOMElement($doc));
95
        }
96
        
97
        return $component;
98
    }
99
}
100

lib/Component/XMLBodyComponent.php 1 location

@@ 36-82 (lines=47) @@
33
 *
34
 * @author Julien Fastré <[email protected]>
35
 */
36
class XMLBodyComponent extends AbstractComponent implements HasClassCode
37
{
38
    /**
39
     *
40
     * @var AbstractComponent[]
41
     */
42
    private $components = array();
43
    
44
    public function getComponents(): array
45
    {
46
        return $this->components;
47
    }
48
49
    public function setComponents(array $components)
50
    {
51
        $this->components = $components;
52
        
53
        return $this;
54
    }
55
    
56
    public function addComponent(SingleComponent $component)
57
    {
58
        $this->components[] = $component;
59
        
60
        return $this;
61
    }
62
    
63
    public function getClassCode(): string
64
    {
65
        return 'DOCBODY';
66
    }
67
68
            
69
    public function toDOMElement(\DOMDocument $doc): \DOMElement
70
    {
71
        $structuredBody = $doc->createElement(CDA::NS_CDA.'structuredBody');
72
        $structuredBody->setAttribute(CDA::NS_CDA.'classCode',
73
            $this->getClassCode());
74
        
75
        
76
        foreach ($this->getComponents() as $component) {
77
            $structuredBody->appendChild($component->toDOMElement($doc));
78
        }
79
        
80
        return $structuredBody;
81
    }
82
}
83