setDomx($xmlEnvio); $this->inconsistenciaModel = $inconsistenciaModel; $this->inconsistencias = json_decode($inconsistenciaModel->inconsistencia); $this->ficha = new stdClass; } private function setDomx($xml) { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadXML($xml); $this->domx = new DOMXPath($dom); } protected function getFirstNodeValue($xmlPath, $context = null) { return $this->domx->query($xmlPath, $context)[0]->nodeValue ?? null; } protected function getDateString($date) { if (is_null($date)) { return null; } return Carbon::createFromTimestamp($date / 1000)->format('d/m/Y'); } protected function getDateTimeString($date) { if (is_null($date)) { return null; } return Carbon::createFromTimestamp($date / 1000)->format('d/m/Y H:i:s'); } protected function getSimNaoNaoInformado($value) { return $value ? DataUtil::getSimOuNao(DataUtil::getBooleanValueFromStringBoolean($value)) : 'Não informado'; } protected function getSexo($exportacaoSexoId) { $sexoId = null; if ($exportacaoSexoId == ExportacaoSexoEnum::MASCULINO) { $sexoId = SexoEnum::MASCULINO; } else if ($exportacaoSexoId == ExportacaoSexoEnum::FEMININO) { $sexoId = SexoEnum::FEMININO; } else if ($exportacaoSexoId == ExportacaoSexoEnum::INDETERMINADO) { $sexoId = SexoEnum::INDETERMINADO; } else { return null; } return Sexo::find($sexoId)->descricao; } protected function getInconsistencias($callbacks) { $inconsistencias = []; foreach ($callbacks as $item) { $prefix = null; $inconsistencia = null; if (is_array($item)) { $prefix = $item[0]; $inconsistencia = $this->getSafeString($item[1]); } else if (is_callable($item)) { $inconsistencia = $this->getSafeString($item); } if (is_null($inconsistencia)) { continue; } if (!is_null($prefix)) { $inconsistencias[] = "{$prefix}: {$inconsistencia}"; } else { $inconsistencias[] = $inconsistencia; } } return $inconsistencias; } private function getSafeString($callback) { try { $value = $callback(); if (is_string($value)) { return $value; } } catch (Exception $_) { return null; } return null; } }