| 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 NONINFRINGEMENT. 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 |  |  | namespace PHPHealth\CDA\Component\SingleComponent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use PHPHealth\CDA\Elements\AbstractElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use PHPHealth\CDA\HasClassCode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use PHPHealth\CDA\Elements\TemplateId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use PHPHealth\CDA\DataType\Identifier\InstanceIdentifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use PHPHealth\CDA\Elements\Id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use PHPHealth\CDA\Elements\Title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use PHPHealth\CDA\DataType\Code\CodedWithEquivalents; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use PHPHealth\CDA\Elements\Code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use PHPHealth\CDA\DataType\TextAndMultimedia\CharacterString; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use PHPHealth\CDA\Elements\Text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use PHPHealth\CDA\Elements\Entry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * Single section which will be included in component | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * @author Julien Fastré <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | class Section extends AbstractElement implements HasClassCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var InstanceIdentifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     private $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @var CodedWithEquivalents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     private $code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @var CharacterString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     private $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @var InstanceIdentifier[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     private $templateIds = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @var CharacterString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     private $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @var Entry[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     private $entries = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     protected function getElementTag(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         return 'section'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function getClassCode(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return 'DOCSECT'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @return InstanceIdentifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function getId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return $this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function setId(InstanceIdentifier $id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $this->id = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     public function getCode(): CodedWithEquivalents | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         return $this->code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public function setCode(CodedWithEquivalents $code) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $this->code = $code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     public function getText(): CharacterString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         return $this->text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     public function setText(CharacterString $text) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $this->text = $text; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 131 |  | View Code Duplication |     public function setTemplateIds(array $templateIds) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $validation = \array_reduce($templateIds,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             function ($carry, $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 if ($carry === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                     return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 return $item instanceof InstanceIdentifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         if ($validation === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             throw new \UnexpectedValueException(sprintf("The values of templateIds" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 . " must contains only %s", InstanceIdentifier::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $this->templateIds = $templateIds; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     public function addTemplateId(InstanceIdentifier $templateId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         $this->templateIds[] = $templateId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * the code for the current section | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @return InstanceIdentifier[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     public function getTemplateIds() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         return $this->templateIds; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * The title for the section | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      * @return CharacterString | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     public function getTitle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         return $this->title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     public function setTitle(CharacterString $title) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $this->title = $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * create an entry, which is already bound to the current section | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @return Entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     public function createEntry(): Entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $entry = new Entry(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $this->addEntry($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         return $entry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     function getEntries(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         return $this->entries; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     public function addEntry(Entry $entry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $this->entries[] = $entry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |      * @param \DOMDocument $doc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 215 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 216 |  |  |     public function toDOMElement(\DOMDocument $doc): \DOMElement | 
            
                                                        
            
                                    
            
            
                | 217 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 218 |  |  |         $el = $this->createElement($doc); | 
            
                                                        
            
                                    
            
            
                | 219 |  |  |         // append templateId | 
            
                                                        
            
                                    
            
            
                | 220 |  |  |         if ($this->getTemplateIds() !== NULL) { | 
            
                                                        
            
                                    
            
            
                | 221 |  |  |             foreach ($this->getTemplateIds() as $id) { | 
            
                                                        
            
                                    
            
            
                | 222 |  |  |                 $el->appendChild( | 
            
                                                        
            
                                    
            
            
                | 223 |  |  |                     (new TemplateId($id))->toDOMElement($doc) | 
            
                                                        
            
                                    
            
            
                | 224 |  |  |                     ); | 
            
                                                        
            
                                    
            
            
                | 225 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 226 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 227 |  |  |         // append id | 
            
                                                        
            
                                    
            
            
                | 228 |  |  |         if ($this->getId() !== NULL) { | 
            
                                                        
            
                                    
            
            
                | 229 |  |  |             $el->appendChild( | 
            
                                                        
            
                                    
            
            
                | 230 |  |  |                 (new Id($this->getId()))->toDOMElement($doc) | 
            
                                                        
            
                                    
            
            
                | 231 |  |  |                 ); | 
            
                                                        
            
                                    
            
            
                | 232 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 233 |  |  |         // append code | 
            
                                                        
            
                                    
            
            
                | 234 |  |  |         if ($this->getCode() !== NULL) { | 
            
                                                        
            
                                    
            
            
                | 235 |  |  |             $el->appendChild( | 
            
                                                        
            
                                    
            
            
                | 236 |  |  |                 (new Code($this->getCode()))->toDOMElement($doc) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 237 |  |  |                 ); | 
            
                                                        
            
                                    
            
            
                | 238 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 239 |  |  |         // append title | 
            
                                                        
            
                                    
            
            
                | 240 |  |  |         if (! empty($this->getTitle())) { | 
            
                                                        
            
                                    
            
            
                | 241 |  |  |             $el->appendChild( | 
            
                                                        
            
                                    
            
            
                | 242 |  |  |                 (new Title($this->getTitle()))->toDOMElement($doc) | 
            
                                                        
            
                                    
            
            
                | 243 |  |  |                 ); | 
            
                                                        
            
                                    
            
            
                | 244 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 245 |  |  |         // append text | 
            
                                                        
            
                                    
            
            
                | 246 |  |  |         if (! empty($this->getText())) { | 
            
                                                        
            
                                    
            
            
                | 247 |  |  |             $el->appendChild( | 
            
                                                        
            
                                    
            
            
                | 248 |  |  |                 (new Text($this->getText()))->toDOMElement($doc) | 
            
                                                        
            
                                    
            
            
                | 249 |  |  |                 ); | 
            
                                                        
            
                                    
            
            
                | 250 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 251 |  |  |          | 
            
                                                        
            
                                    
            
            
                | 252 |  |  |         foreach ($this->getEntries() as $entry) { | 
            
                                                        
            
                                    
            
            
                | 253 |  |  |             $el->appendChild($entry->toDOMElement($doc)); | 
            
                                                        
            
                                    
            
            
                | 254 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 255 |  |  |          | 
            
                                                        
            
                                    
            
            
                | 256 |  |  |         return $el; | 
            
                                                        
            
                                    
            
            
                | 257 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 258 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 259 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.