Section   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 53
dl 0
loc 121
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A clearEntries() 0 4 1
C __construct() 0 36 12
A getElementTag() 0 3 1
A createEntry() 0 5 1
A toDOMElement() 0 16 1
1
<?php
2
3
4
/**
5
 * The MIT License
6
 *
7
 * Copyright 2018  Peter Gee <https://github.com/pgee70>.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
 * THE SOFTWARE.
26
 */
27
28
namespace i3Soft\CDA\Component\SingleComponent;
29
30
/**
31
 *
32
 * @package     i3Soft\CDA
33
 * @author      Peter Gee <https://github.com/pgee70>
34
 * @link        https://github.com/pgee70/cda
35
 *
36
 */
37
38
use i3Soft\CDA\Elements\AbstractElement;
39
use i3Soft\CDA\Elements\Code;
40
use i3Soft\CDA\Elements\Entry;
41
use i3Soft\CDA\Elements\Html\Text;
42
use i3Soft\CDA\Elements\Html\Title;
43
use i3Soft\CDA\Elements\Id;
44
use i3Soft\CDA\Interfaces\ClassCodeInterface;
45
use i3Soft\CDA\Interfaces\MoodCodeInterface;
46
use i3Soft\CDA\Traits\AuthorTrait;
47
use i3Soft\CDA\Traits\ClassCodeTrait;
48
use i3Soft\CDA\Traits\CodeTrait;
49
use i3Soft\CDA\Traits\ConfidentialityCodeTrait;
50
use i3Soft\CDA\Traits\EntriesTrait;
51
use i3Soft\CDA\Traits\ExtCoverage2Trait;
52
use i3Soft\CDA\Traits\IdTrait;
53
use i3Soft\CDA\Traits\InformantsTrait;
54
use i3Soft\CDA\Traits\LanguageCodeTrait;
55
use i3Soft\CDA\Traits\MoodCodeTrait;
56
use i3Soft\CDA\Traits\SingleComponentTrait;
57
use i3Soft\CDA\Traits\SubjectTrait;
58
use i3Soft\CDA\Traits\TextTrait;
59
use i3Soft\CDA\Traits\TitleTrait;
60
61
/**
62
 * Class Section
63
 *
64
 * @package i3Soft\CDA\Component\SingleComponent
65
 */
66
class Section extends AbstractElement implements ClassCodeInterface, MoodCodeInterface
67
{
68
  use AuthorTrait;
69
  use CodeTrait;
70
  use ConfidentialityCodeTrait;
71
  use EntriesTrait;
72
  use IdTrait;
73
  use LanguageCodeTrait;
74
  use SingleComponentTrait;
75
  use SubjectTrait;
76
  use TextTrait;
77
  use TitleTrait;
78
  use InformantsTrait;
79
  use ExtCoverage2Trait;
80
  use ClassCodeTrait;
81
  use MoodCodeTrait;
82
83
  /** @noinspection ArrayTypeOfParameterByDefaultValueInspection */
84
85
  /**
86
   * Section constructor.
87
   *
88
   * @param Id    $id
89
   * @param Code  $code
90
   * @param Title $title
91
   * @param Text  $text
92
   * @param       $entry
93
   */
94
  public function __construct ($id = NULL, $code = NULL, $title = NULL, $text = NULL, $entry = [])
95
  {
96
    $this->setAcceptableClassCodes(ClassCodeInterface::ActClass)
97
      ->setAcceptableMoodCodes(MoodCodeInterface::ActMood)
98
      ->setClassCode(ClassCodeInterface::DOCUMENT_SECTION)
99
      ->setMoodCode(MoodCodeInterface::EVENT);
100
101
    $this->entries = [];
102
103
    if ($id && $id instanceof Id)
104
    {
105
      $this->setId($id);
106
    }
107
    if ($code && $code instanceof Code)
108
    {
109
      $this->setCode($code);
110
    }
111
112
    if ($title && $title instanceof Title)
113
    {
114
      $this->setTitle($title);
115
    }
116
117
    if ($text && $text instanceof Text)
118
    {
119
      $this->setText($text);
120
    }
121
    if ($entry)
122
    {
123
      if (\is_array($entry))
124
      {
125
        $this->setEntries($entry);
126
      }
127
      elseif ($entry instanceof Entry)
128
      {
129
        $this->addEntry($entry);
130
      }
131
    }
132
  }
133
134
135
  /**
136
   * @return self
137
   */
138
  public function clearEntries (): self
139
  {
140
    $this->entries = array();
141
    return $this;
142
  }
143
144
  /**
145
   * create an entry, which is already bound to the current section
146
   *
147
   * @return Entry
148
   */
149
  public function createEntry (): Entry
150
  {
151
    $entry = new Entry();
152
    $this->addEntry($entry);
153
    return $entry;
154
  }
155
156
157
  /**
158
   * @param \DOMDocument $doc
159
   *
160
   * @return \DOMElement
161
   */
162
  public function toDOMElement (\DOMDocument $doc): \DOMElement
163
  {
164
    $el = $this->createElement($doc);
165
    $this->renderId($el, $doc)
166
      ->renderCode($el, $doc)
167
      ->renderTitle($el, $doc)
168
      ->renderText($el, $doc)
169
      ->renderConfidentialityCode($el, $doc)
170
      ->renderLanguageCode($el, $doc)
171
      ->renderSubject($el, $doc)
172
      ->renderAuthor($el, $doc)
173
      ->renderInformants($el, $doc)
174
      ->renderEntries($el, $doc)
175
      ->renderComponents($el, $doc)
176
      ->renderExtCoverage2($el, $doc);
177
    return $el;
178
  }
179
180
181
  /**
182
   * @return string
183
   */
184
  protected function getElementTag (): string
185
  {
186
    return 'section';
187
  }
188
189
}