Skip to content

Commit

Permalink
feat: alterar tipagem de variável em todos os métodos que consome a API
Browse files Browse the repository at this point in the history
  • Loading branch information
Glaydson Rodrigues committed Dec 9, 2024
1 parent 9b5ff65 commit 5bf5784
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 62 deletions.
86 changes: 54 additions & 32 deletions src/rn/ProcessoEletronicoRN.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private function getObjPenWs()
public function consultarRepositoriosDeEstruturas($numIdentificacaoDoRepositorioDeEstruturas)
{
$objRepositorioDTO = null;
$endpoint = "repositorios-de-estruturas/{$numIdentificacaoDoRepositorioDeEstruturas}/estruturas-organizacionais";
$endpoint = 'repositorios-de-estruturas';
try {
$parametros = [
'ativo' => true
Expand All @@ -193,10 +193,12 @@ public function consultarRepositoriosDeEstruturas($numIdentificacaoDoRepositorio

if (isset($arrResultado)) {
foreach ($arrResultado as $repositorio) {
if ($repositorio['id'] == $numIdentificacaoDoRepositorioDeEstruturas) {
$objRepositorioDTO = new RepositorioDTO();
$objRepositorioDTO->setNumId($repositorio['id']);
$objRepositorioDTO->setStrNome(mb_convert_encoding($repositorio['nome'], 'ISO-8859-1', 'UTF-8'));
$objRepositorioDTO->setBolAtivo($repositorio['ativo']);
}
}
}
} catch (Exception $e) {
Expand Down Expand Up @@ -1233,8 +1235,20 @@ public function solicitarMetadados($parNumIdentificacaoTramite)
$objResultado = new stdClass();
$objResultado->IDT = $parNumIdentificacaoTramite;
$objResultado->NRE = $arrResultado['nre'];

$multivalorado = false;
if (count($arrResultado['processo']['documentos']) <= 1) {
$arrResultado['processo']['documentos'] = (object) $arrResultado['processo']['documentos'][0];
} else {
$multivalorado = true;
}

$objResultado->metadados = $this->converterArrayParaObjeto($arrResultado);

if ($multivalorado) {
$objResultado->metadados->processo->documentos = (array) $objResultado->metadados->processo->documentos;
}

return $objResultado;

} catch (\Exception $e) {
Expand Down Expand Up @@ -1478,14 +1492,18 @@ protected function cadastrarTramiteDeProcessoInternoControlado(ProcessoEletronic
*/
public static function getHashFromMetaDados($objMeta)
{
if (is_array($objMeta)) {
$objMeta = (object) $objMeta;
}

$strHashConteudo = '';

if (isset($objMeta)) {
if(is_string($objMeta)){
$strHashConteudo = $objMeta;
} else {
$matches = array();
$strHashConteudo = (isset($objMeta->enc_value)) ? $objMeta->enc_value : $objMeta['conteudo'];
$strHashConteudo = (isset($objMeta->enc_value)) ? $objMeta->enc_value : $objMeta->conteudo;

if (preg_match('/^<hash.*>(.*)<\/hash>$/', $strHashConteudo, $matches, PREG_OFFSET_CAPTURE)) {
$strHashConteudo = $matches[1][0];
Expand Down Expand Up @@ -1612,8 +1630,8 @@ private function montarDadosComponenteDigital($parStrNumeroRegistro, $parNumIden
$objComponenteDigitalDTO->setStrNome(utf8_decode($objComponenteDigital->nome));

if(isset($objDocumento->especie)){
$objComponenteDigitalDTO->setNumCodigoEspecie(intval($objDocumento->especie['codigo']));
$objComponenteDigitalDTO->setStrNomeEspecieProdutor(utf8_decode($objDocumento->especie['nomeNoProdutor']));
$objComponenteDigitalDTO->setNumCodigoEspecie(intval($objDocumento->especie->codigo));
$objComponenteDigitalDTO->setStrNomeEspecieProdutor(utf8_decode($objDocumento->especie->nomeNoProdutor));
}

$strHashConteudo = static::getHashFromMetaDados($objComponenteDigital->hash);
Expand Down Expand Up @@ -2318,7 +2336,7 @@ public static function obterDocumentosProtocolo($parObjProtocolo, $parBolExtrair
{
$arrObjDocumento = array();
if(isset($parObjProtocolo->documentos)){
$arrObjProtocolo = is_array($parObjProtocolo->documentos) ? $parObjProtocolo->documentos : json_decode(json_encode($parObjProtocolo->documentos), true);
$arrObjProtocolo = is_array($parObjProtocolo->documentos) ? $parObjProtocolo->documentos : array($parObjProtocolo->documentos);
usort($arrObjProtocolo, array("ProcessoEletronicoRN", "comparacaoOrdemAjustadaDocumentos"));

//Tratamento recursivo para processos anexados
Expand Down Expand Up @@ -2352,25 +2370,20 @@ public static function obterDocumentosProtocolo($parObjProtocolo, $parBolExtrair

$arrObjDocumentoPadronizados = ($parBolExtrairAnexados) ? $arrObjDocumento : $arrObjProtocolo;

foreach ($arrObjDocumentoPadronizados as $documento) {
if (is_array($documento) && $documento['componentesDigitais']) {
$documento['componentesDigitais'] = self::obterComponentesDocumentos($documento);
} else {
$documento->componentesDigitais = self::obterComponentesDocumentos($documento);
foreach ($arrObjDocumentoPadronizados as $documento) {
if (is_array($documento) && $documento['componentesDigitais']) {
$documento = (object) $documento;
}
$documento->componentesDigitais = self::obterComponentesDocumentos($documento);
}
}

return $arrObjDocumentoPadronizados;
}


public static function obterComponentesDocumentos($parObjDocumento)
{

if (is_array($parObjDocumento) && isset($parObjDocumento['componentesDigitais'])) {
return $parObjDocumento['componentesDigitais'];
}


$arrObjComponenteDigital = array();
if (isset($parObjDocumento->componentesDigitais)) {
$arrObjComponenteDigital = is_array($parObjDocumento->componentesDigitais) ? $parObjDocumento->componentesDigitais : array($parObjDocumento->componentesDigitais);
Expand Down Expand Up @@ -2430,11 +2443,11 @@ public static function obterUnidadeParaRegistroDocumento($parDblIdProcedimento)
* @param $parObjDocumento
* @return array
*/
public static function obterComponentesDigitaisDocumento($parObjDocumento)
public static function obterComponentesDigitaisDocumento($parObjDocumento)
{
$arrObjComponenteDigital = array();
if (isset($parObjDocumento['componentesDigitais'])) {
$arrObjComponenteDigital = is_array($parObjDocumento['componentesDigitais']) ? $parObjDocumento['componentesDigitais'] : array($parObjDocumento['componentesDigitais']);
if(isset($parObjDocumento->componentesDigitais)){
$arrObjComponenteDigital = is_array($parObjDocumento->componentesDigitais) ? $parObjDocumento->componentesDigitais : array($parObjDocumento->componentesDigitais);
}

return $arrObjComponenteDigital;
Expand All @@ -2454,9 +2467,6 @@ public static function obterComponentesDigitaisDocumento($parObjDocumento)
*/
public static function desmembrarProcessosAnexados($parObjProtocolo)
{
if (is_array($parObjProtocolo)) {
$parObjProtocolo = (object) $parObjProtocolo;
}

if(!ProcessoEletronicoRN::existeProcessoAnexado($parObjProtocolo)){
return $parObjProtocolo;
Expand Down Expand Up @@ -2731,18 +2741,30 @@ public function listarAssociacoesDocumentos($idProcedimento)
/**
* Converter arrays associativo para objetos
*/
public static function converterArrayParaObjeto($array)
public static function converterArrayParaObjeto($array)
{
if (is_array($array)) {
// Verificar se o array é associativo
if (self::verificarSeArrayAssociativo($array)) {
$object = new stdClass();
foreach ($array as $key => $value) {
$object->$key = self::converterArrayParaObjeto($value);
}
return $object;
} else {
// Para arrays indexados, manter como está
return array_map([self::class, 'converterArrayParaObjeto'], $array);
}
}

return $array;
}

private static function verificarSeArrayAssociativo(array $array): bool
{
if (is_array($array)) {
$object = new stdClass();
foreach ($array as $key => $value) {
$object->$key = self::converterArrayParaObjeto($value);
}
return $object;
return array_keys($array) !== range(0, count($array) - 1);
}

return $array;
}


/**
* Consulta as estruturas de um repositório de estruturas.
Expand Down
10 changes: 7 additions & 3 deletions src/rn/ReceberComponenteDigitalRN.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,15 @@ private function atualizarAnexoDoComponenteDigital($parObjComponenteDigitalDTO,
* @return AnexoDTO
*
*/
public function copiarComponenteDigitalPastaTemporaria($parArrComponenteDigital, $parObjConteudo)
public function copiarComponenteDigitalPastaTemporaria($parObjComponenteDigital, $parObjConteudo)
{
if (!isset($parArrComponenteDigital)) {
if (!isset($parObjComponenteDigital)) {
throw new InfraException("Componente Digital não informado");
}

if (is_array($parObjComponenteDigital)) {
$parObjComponenteDigital = (object) $parObjComponenteDigital;
}
$objAnexoRN = new AnexoRN();
$strNomeArquivoUpload = $objAnexoRN->gerarNomeArquivoTemporario();
$strConteudoCodificado = $parObjConteudo->conteudoDoComponenteDigital;
Expand All @@ -273,7 +277,7 @@ public function copiarComponenteDigitalPastaTemporaria($parArrComponenteDigital,
$objAnexoDTO->setDthInclusao(InfraData::getStrDataHoraAtual());
$objAnexoDTO->setNumTamanho(filesize(DIR_SEI_TEMP.'/'.$strNomeArquivoUpload));
$objAnexoDTO->setNumIdUsuario(SessaoSEI::getInstance()->getNumIdUsuario());
$objAnexoDTO->setStrNome($parArrComponenteDigital['nome']);
$objAnexoDTO->setStrNome($parObjComponenteDigital->nome);
return $objAnexoDTO;
}

Expand Down
Loading

0 comments on commit 5bf5784

Please sign in to comment.