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

XMLBodyComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 23
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getElementTag() 0 3 1
A toDOMElement() 0 9 2
A __construct() 0 17 2
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\Component;
27
28
use i3Soft\CDA\Interfaces\ClassCodeInterface;
29
use i3Soft\CDA\Interfaces\MoodCodeInterface;
30
use i3Soft\CDA\Traits\ClassCodeTrait;
31
use i3Soft\CDA\Traits\MoodCodeTrait;
32
use i3Soft\CDA\Traits\SingleComponentTrait;
33
34
/**
35
 * @author Julien Fastré <[email protected]>
36
 */
37
class XMLBodyComponent extends AbstractComponent implements ClassCodeInterface, MoodCodeInterface
38
{
39
    use SingleComponentTrait;
40
    use ClassCodeTrait;
41
    use MoodCodeTrait;
42
43
    /**
44
     * XMLBodyComponent constructor.
45
     *
46
     * @param null $component
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $component is correct as it would always require null to be passed?
Loading history...
47
     */
48
    public function __construct($component = null)
49
    {
50
        $acceptable_values = array(
51
          '',
52
          MoodCodeInterface::EVENT,
53
          MoodCodeInterface::GOAL,
54
          MoodCodeInterface::INTENT,
55
          MoodCodeInterface::PROMISE,
56
          MoodCodeInterface::PROPOSAL,
57
          MoodCodeInterface::REQUEST
58
        );
59
        $this->setAcceptableClassCodes(ClassCodeInterface::ActClass)
60
          ->setAcceptableMoodCodes($acceptable_values)
61
          ->setClassCode(ClassCodeInterface::DOCUMENT_BODY)
62
          ->setMoodCode('');
63
        if ($component instanceof SingleComponent) {
64
            $this->addComponent($component);
65
        }
66
    }
67
68
69
    /**
70
     * @param \DOMDocument $doc
71
     *
72
     * @return \DOMElement
73
     */
74
    public function toDOMElement(\DOMDocument $doc): \DOMElement
75
    {
76
        $el = $this->createElement($doc);
77
78
        foreach ($this->getComponents() as $component) {
79
            $el->appendChild($component->toDOMElement($doc));
80
        }
81
82
        return $el;
83
    }
84
85
86
    /**
87
     * get the element tag name
88
     *
89
     * @return string
90
     */
91
    protected function getElementTag(): string
92
    {
93
        return 'structuredBody';
94
    }
95
}
96