AssignedEntity::__construct()   C
last analyzed

Complexity

Conditions 13
Paths 64

Size

Total Lines 35
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
rs 6.6166
c 0
b 0
f 0
cc 13
nc 64
nop 7

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * The MIT License
5
 *
6
 * Copyright 2018  Peter Gee <https://github.com/pgee70>.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
/**
28
 *
29
 * @package     i3Soft\CDA
30
 * @author      Peter Gee <https://github.com/pgee70>
31
 * @link        https://github.com/pgee70/cda
32
 *
33
 */
34
35
36
namespace i3Soft\CDA\RIM\Entity;
37
38
39
use i3Soft\CDA\Elements\AbstractElement;
40
use i3Soft\CDA\Elements\Address\Addr;
41
use i3Soft\CDA\Elements\Address\Telecom;
42
use i3Soft\CDA\Elements\Code;
43
use i3Soft\CDA\Elements\Id;
44
use i3Soft\CDA\Interfaces\ClassCodeInterface;
45
use i3Soft\CDA\RIM\Extensions\AsEntityIdentifier;
46
use i3Soft\CDA\Traits\AddrsTrait;
47
use i3Soft\CDA\Traits\AsEntityIdentifierTrait;
48
use i3Soft\CDA\Traits\AssignedEntityTrait;
49
use i3Soft\CDA\Traits\AssignedPersonTrait;
50
use i3Soft\CDA\Traits\ClassCodeTrait;
51
use i3Soft\CDA\Traits\CodeTrait;
52
use i3Soft\CDA\Traits\IdTrait;
53
use i3Soft\CDA\Traits\RepresentedOrganizationTrait;
54
use i3Soft\CDA\Traits\TelecomsTrait;
55
56
/**
57
 * Class AssignedEntity
58
 *
59
 * @package i3Soft\CDA\RIM\Role
60
 */
61
class AssignedEntity extends AbstractElement implements ClassCodeInterface
62
{
63
  use IdTrait;
64
  use CodeTrait;
65
  use AddrsTrait;
66
  use TelecomsTrait;
67
  use AssignedEntityTrait;
68
  use AsEntityIdentifierTrait;
69
  use RepresentedOrganizationTrait;
70
  use AssignedPersonTrait;
71
  use ClassCodeTrait;
72
73
  /**
74
   * AssignedEntity constructor.
75
   *
76
   * @param Id                      $id
77
   * @param Code                    $code
78
   * @param Addr                    $addr
79
   * @param Telecom                 $telecom
80
   * @param AssignedPerson          $assigned_person
81
   * @param AsEntityIdentifier      $as_entity_identifier
82
   * @param RepresentedOrganization $represented_organization
83
   */
84
  public function __construct (
85
    Id $id,
86
    $code = NULL,
87
    $addr = NULL,
88
    $telecom = NULL,
89
    $assigned_person = NULL,
90
    $as_entity_identifier = NULL,
91
    $represented_organization = NULL
92
  ) {
93
    $this->setAcceptableClassCodes(['', ClassCodeInterface::ASSIGNED])
94
      ->setClassCode('')
95
      ->setId($id);
96
    if ($code && $code instanceof Code)
97
    {
98
      $this->setCode($code);
99
    }
100
    if ($addr && $addr instanceof Addr)
101
    {
102
      $this->addAddr($addr);
103
    }
104
    if ($telecom && $telecom instanceof Telecom)
105
    {
106
      $this->addTelecom($telecom);
107
    }
108
    if ($assigned_person && $assigned_person instanceof AssignedPerson)
109
    {
110
      $this->setAssignedPerson($assigned_person);
111
    }
112
    if ($as_entity_identifier && $as_entity_identifier instanceof AsEntityIdentifier)
113
    {
114
      $this->setAsEntityIdentifier($as_entity_identifier);
115
    }
116
    if ($represented_organization && $represented_organization instanceof RepresentedOrganization)
117
    {
118
      $this->setRepresentedOrganization($represented_organization);
119
    }
120
  }
121
122
123
  /**
124
   * @param \DOMDocument $doc
125
   *
126
   * @return \DOMElement
127
   */
128
  public function toDOMElement (\DOMDocument $doc): \DOMElement
129
  {
130
    $el = $this->createElement($doc);
131
    $this->renderId($el, $doc);
132
    $this->renderCode($el, $doc);
133
    $this->renderAddrs($el, $doc);
134
    $this->renderTelecoms($el, $doc);
135
    $this->renderAssignedPerson($el, $doc);
136
    $this->renderAsEntityIdentifier($el, $doc);
137
    $this->renderRepresentedOrganization($el, $doc);
138
    return $el;
139
  }
140
141
142
  /**
143
   * @return string
144
   */
145
  protected function getElementTag (): string
146
  {
147
    return 'assignedEntity';
148
  }
149
}