| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace NFePHP\eSocial\Factories; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Class eSocial EvtTabOperPort Event S-1080 constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @category  NFePHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @package   NFePHPSocial | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright NFePHP Copyright (c) 2017 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license   https://opensource.org/licenses/MIT MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author    Roberto L. Machado <linux.rlm at gmail dot com> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use NFePHP\Common\Certificate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use NFePHP\eSocial\Common\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use NFePHP\eSocial\Common\FactoryId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use NFePHP\eSocial\Common\FactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use stdClass; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | class EvtTabOperPort extends Factory implements FactoryInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @var int | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     public $sequencial; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     protected $evtName = 'evtTabOperPort'; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     protected $evtAlias = 'S-1080'; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * Parameters patterns | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     protected $parameters = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |      * Constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * @param string $config | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @param stdClass $std | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @param Certificate $certificate | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         stdClass $std, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         Certificate $certificate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         parent::__construct($config, $std, $certificate); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * Node constructor | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     protected function toNode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |          $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         //o idEvento pode variar de evento para evento | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         //então cada factory individualmente terá de construir o seu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $ideEvento = $this->dom->createElement("ideEvento"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $ideEvento, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             "tpAmb", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             $this->tpAmb, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $ideEvento, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             "procEmi", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $this->procEmi, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $ideEvento, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             "verProc", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $this->verProc, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->node->insertBefore($ideEvento, $ideEmpregador); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $ide = $this->dom->createElement("ideOperPortuario"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $ide, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             "cnpjOpPortuario", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $this->std->cnpjopportuario, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $ide, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             "iniValid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             $this->std->inivalid, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             $ide, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             "fimValid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             ! empty($this->std->fimvalid) ? $this->std->fimvalid : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if (!empty($this->std->dadosoperportuario)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $da = $this->std->dadosoperportuario; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $dados = $this->dom->createElement("dadosOperPortuario"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                 $dados, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 "aliqRat", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 $da->aliqrat, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                 $dados, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 "fap", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 $da->fap, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 $dados, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 "aliqRatAjust", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $da->aliqratajust, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         if (!empty($this->std->novavalidade)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             $nova = $this->dom->createElement("novaValidade"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 $nova, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 "iniValid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                 $this->std->novavalidade->inivalid, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             $this->dom->addChild( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 $nova, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                 "fimValid", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                 ! empty($this->std->novavalidade->fimvalid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                     ? $this->std->novavalidade->fimvalid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                     : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                 false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $info = $this->dom->createElement("infoOperPortuario"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         //seleção do modo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         if ($this->std->modo == 'INC') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $node = $this->dom->createElement("inclusao"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             $node->appendChild($ide); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             $node->appendChild($dados); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } elseif ($this->std->modo == 'ALT') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             $node = $this->dom->createElement("alteracao"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $node->appendChild($ide); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $node->appendChild($dados); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $node->appendChild($nova); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $node = $this->dom->createElement("exclusao"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $node->appendChild($ide); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         $info->appendChild($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $this->node->appendChild($info); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $this->eSocial->appendChild($this->node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         //$this->xml = $this->dom->saveXML($this->eSocial); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         $this->sign(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 175 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 176 |  |  |  | 
            
                        
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: