ManufacturedProduct::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
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\RIM\Role;
27
28
use i3Soft\CDA\Interfaces\ClassCodeInterface;
29
use i3Soft\CDA\RIM\Entity\ManufacturedLabeledDrug;
30
use i3Soft\CDA\RIM\Entity\ManufacturedMaterial;
31
use i3Soft\CDA\RIM\Entity\Organization;
32
33
/**
34
 * Class ManufacturedProduct
35
 *
36
 * @package i3Soft\CDA\RIM\Role
37
 */
38
class ManufacturedProduct extends Role
39
{
40
41
  /** @var ManufacturedLabeledDrug */
42
  protected $manufacturedLabeledDrug;
43
  /** @var ManufacturedMaterial */
44
  protected $manufacturedMaterial;
45
46
  /** @var Organization */
47
  protected $manufacturerOrganization;
48
  protected $manufacturedDrugOrOther;
49
50
  /**
51
   * ManufacturedProduct constructor.
52
   *
53
   * @param null $drug
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $drug is correct as it would always require null to be passed?
Loading history...
54
   */
55
  public function __construct ($drug = NULL)
56
  {
57
    $this->setAcceptableClassCodes(ClassCodeInterface::RoleClassManufacturedProduct)
58
      ->setClassCode(ClassCodeInterface::MANUFACTURED_PRODUCT);
59
    if ($drug instanceof ManufacturedLabeledDrug)
60
    {
61
      $this->setManufacturedLabeledDrug($drug);
62
    }
63
    elseif ($drug instanceof ManufacturedMaterial)
64
    {
65
      $this->setManufacturedMaterial($drug);
66
    }
67
  }
68
69
70
  /**
71
   * @return bool
72
   */
73
  public function hasManufacturedDrugOrOther (): bool
74
  {
75
    return NULL !== $this->manufacturedDrugOrOther;
76
  }
77
78
  /**
79
   * @param \DOMDocument $doc
80
   *
81
   * @return \DOMElement
82
   */
83
  public function toDOMElement (\DOMDocument $doc): \DOMElement
84
  {
85
    $el = $this->createElement($doc);
86
    $this->renderIds($el, $doc);
87
    if ($this->hasManufacturedLabeledDrug())
88
    {
89
      $el->appendChild($this->getManufacturedLabeledDrug()->toDOMElement($doc));
90
    }
91
    elseif ($this->hasManufacturedMaterial())
92
    {
93
      $el->appendChild($this->getManufacturedMaterial()->toDOMElement($doc));
94
    }
95
    if ($this->hasManufacturerOrganization())
96
    {
97
      $el->appendChild($this->getManufacturerOrganization()->toDOMElement($doc));
98
    }
99
    return $el;
100
  }
101
102
  /**
103
   * @return bool
104
   */
105
  public function hasManufacturedLabeledDrug (): bool
106
  {
107
    return NULL !== $this->manufacturedLabeledDrug;
108
  }
109
110
  /**
111
   * @return ManufacturedLabeledDrug
112
   */
113
  public function getManufacturedLabeledDrug (): ManufacturedLabeledDrug
114
  {
115
    return $this->manufacturedLabeledDrug;
116
  }
117
118
  /**
119
   * @param ManufacturedLabeledDrug $manufacturedLabeledDrug
120
   *
121
   * @return ManufacturedProduct
122
   */
123
  public function setManufacturedLabeledDrug (ManufacturedLabeledDrug $manufacturedLabeledDrug): self
124
  {
125
    $this->manufacturedLabeledDrug = $manufacturedLabeledDrug;
126
    return $this;
127
  }
128
129
  /**
130
   * @return bool
131
   */
132
  public function hasManufacturedMaterial (): bool
133
  {
134
    return NULL !== $this->manufacturedMaterial;
135
  }
136
137
  /**
138
   * @return ManufacturedMaterial
139
   */
140
  public function getManufacturedMaterial (): ManufacturedMaterial
141
  {
142
    return $this->manufacturedMaterial;
143
  }
144
145
  /**
146
   * @param ManufacturedMaterial $manufacturedMaterial
147
   *
148
   * @return ManufacturedProduct
149
   */
150
  public function setManufacturedMaterial (ManufacturedMaterial $manufacturedMaterial): self
151
  {
152
    $this->manufacturedMaterial = $manufacturedMaterial;
153
    return $this;
154
  }
155
156
  /**
157
   * @return bool
158
   */
159
  public function hasManufacturerOrganization (): bool
160
  {
161
    return NULL !== $this->manufacturerOrganization;
162
  }
163
164
  /**
165
   * @return Organization
166
   */
167
  public function getManufacturerOrganization (): Organization
168
  {
169
    return $this->manufacturerOrganization;
170
  }
171
172
  /**
173
   * @param Organization $manufacturerOrganization
174
   */
175
  public function setManufacturerOrganization (Organization $manufacturerOrganization)
176
  {
177
    $this->manufacturerOrganization = $manufacturerOrganization;
178
  }
179
180
  /**
181
   * @return string
182
   */
183
  protected function getElementTag (): string
184
  {
185
    return 'manufacturedProduct';
186
  }
187
}
188