@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | ?array $namespace = null, |
| 75 | 75 | ?DOMElement $parent = null, |
| 76 | 76 | ?XmlDocument $doc = null |
| 77 | - ): XmlDocument|DOMElement |
|
| 77 | + ): XmlDocument | DOMElement |
|
| 78 | 78 | { |
| 79 | 79 | // Si no hay un documento XML completo (desde raíz, no vale un nodo), |
| 80 | 80 | // entonces se crea, pues se necesitará para crear los futuros nodos. |
| 81 | - if ($doc === null) { |
|
| 81 | + if ($doc===null) { |
|
| 82 | 82 | $doc = new XmlDocument(); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // Si no hay un elemento padre, entonces se está pidiendo crear el |
| 86 | 86 | // documento XML desde 0 (desde el nodo raíz). |
| 87 | - if ($parent === null) { |
|
| 87 | + if ($parent===null) { |
|
| 88 | 88 | $parent = $doc; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | // Si el índice es '@attributes' entonces el valor de este índice |
| 96 | 96 | // es un arreglo donde la llave es el nombre del atributo del tag |
| 97 | 97 | // de $parent y el valor es el valor del atributo. |
| 98 | - if ($key === '@attributes') { |
|
| 98 | + if ($key==='@attributes') { |
|
| 99 | 99 | // Solo se agregan atributos si el valor es un arreglo. |
| 100 | 100 | if (is_array($value)) { |
| 101 | 101 | self::nodeAddAttributes($parent, $value); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | // el valor al nodo, pues es un escalar (no un arreglo con nodos |
| 107 | 107 | // hijos). Este caso normalmente se usa cuando se crea un nodo que |
| 108 | 108 | // debe tener valor y atributos. |
| 109 | - else if ($key === '@value') { |
|
| 109 | + else if ($key==='@value') { |
|
| 110 | 110 | if (!self::skipValue($value)) { |
| 111 | 111 | $parent->nodeValue = XmlUtils::sanitize($value); |
| 112 | 112 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $doc, |
| 132 | 132 | $parent, |
| 133 | 133 | $key, |
| 134 | - (string) $value, |
|
| 134 | + (string)$value, |
|
| 135 | 135 | $namespace |
| 136 | 136 | ); |
| 137 | 137 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | private static function nodeAddChilds( |
| 187 | 187 | XmlDocument $doc, |
| 188 | - XmlDocument|DOMElement $parent, |
|
| 188 | + XmlDocument | DOMElement $parent, |
|
| 189 | 189 | string $tagName, |
| 190 | 190 | array $childs, |
| 191 | 191 | ?array $namespace = null, |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | // Agregar nodos hijos del nodo hijo (agregar |
| 218 | 218 | // asociativo al nodo $tagName). |
| 219 | 219 | $Node = $namespace |
| 220 | - ? $doc->createElementNS($namespace[0], $namespace[1] . ':' . $tagName) |
|
| 220 | + ? $doc->createElementNS($namespace[0], $namespace[1].':'.$tagName) |
|
| 221 | 221 | : $doc->createElement($tagName) |
| 222 | 222 | ; |
| 223 | 223 | $parent->appendChild($Node); |
@@ -226,10 +226,10 @@ discard block |
||
| 226 | 226 | // Si el hijo no es un arreglo, es simplemente un nodo duplicado |
| 227 | 227 | // que se debe agregar en el mismo nivel que el nodo padre. |
| 228 | 228 | else { |
| 229 | - $value = XmlUtils::sanitize((string) $child); |
|
| 229 | + $value = XmlUtils::sanitize((string)$child); |
|
| 230 | 230 | $Node = $namespace |
| 231 | 231 | ? $doc->createElementNS( |
| 232 | - $namespace[0], $namespace[1] . ':' . $tagName, |
|
| 232 | + $namespace[0], $namespace[1].':'.$tagName, |
|
| 233 | 233 | $value |
| 234 | 234 | ) |
| 235 | 235 | : $doc->createElement($tagName, $value) |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | $value = XmlUtils::sanitize($value); |
| 262 | 262 | $Node = $namespace |
| 263 | 263 | ? $doc->createElementNS( |
| 264 | - $namespace[0], $namespace[1] . ':' . $tagName, |
|
| 264 | + $namespace[0], $namespace[1].':'.$tagName, |
|
| 265 | 265 | $value |
| 266 | 266 | ) |
| 267 | 267 | : $doc->createElement($tagName, $value) |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array Arreglo con la representación del XML. |
| 311 | 311 | */ |
| 312 | 312 | public static function xmlToArray( |
| 313 | - XmlDocument|DOMElement $documentElement, |
|
| 313 | + XmlDocument | DOMElement $documentElement, |
|
| 314 | 314 | ?array &$data = null, |
| 315 | 315 | bool $twinsAsArray = false |
| 316 | 316 | ): array |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | // Si no hay un arreglo de destino para los datos se crea un arreglo |
| 333 | 333 | // con el índice del nodo principal con valor vacío. |
| 334 | - if ($data === null) { |
|
| 334 | + if ($data===null) { |
|
| 335 | 335 | //$data = [$key => self::getEmptyValue()]; |
| 336 | 336 | $data = [$key => null]; |
| 337 | 337 | } |
@@ -382,10 +382,10 @@ discard block |
||
| 382 | 382 | foreach ($childs as $child) { |
| 383 | 383 | if ($child instanceof DOMText) { |
| 384 | 384 | $textContent = trim($child->textContent); |
| 385 | - if ($textContent !== '') { |
|
| 385 | + if ($textContent!=='') { |
|
| 386 | 386 | if ($tagElement->hasAttributes()) { |
| 387 | 387 | $data[$key]['@value'] = $textContent; |
| 388 | - } else if ($childs->length === 1 && empty($data[$key])) { |
|
| 388 | + } else if ($childs->length===1 && empty($data[$key])) { |
|
| 389 | 389 | $data[$key] = $textContent; |
| 390 | 390 | } else { |
| 391 | 391 | $array[$key]['@value'] = $textContent; |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $tagElement, |
| 397 | 397 | $child->tagName |
| 398 | 398 | ); |
| 399 | - if ($n_twinsNodes === 1) { |
|
| 399 | + if ($n_twinsNodes===1) { |
|
| 400 | 400 | if ($twinsAsArray) { |
| 401 | 401 | self::xmlToArray($child, $data); |
| 402 | 402 | } else { |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | // Se revisa si el nodo hijo es escalar. Si lo es, se añade |
| 413 | 413 | // a la lista directamente. |
| 414 | 414 | $textContent = trim($child->textContent); |
| 415 | - if ($textContent !== '') { |
|
| 415 | + if ($textContent!=='') { |
|
| 416 | 416 | $data[$key][$child->tagName][] = $textContent; |
| 417 | 417 | } |
| 418 | 418 | // Si el nodo hijo es un escalar, sino que es una lista de |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | { |
| 444 | 444 | $twins = 0; |
| 445 | 445 | foreach ($dom->childNodes as $child) { |
| 446 | - if ($child instanceof DOMElement && $child->tagName === $tagName) { |
|
| 446 | + if ($child instanceof DOMElement && $child->tagName===$tagName) { |
|
| 447 | 447 | $twins++; |
| 448 | 448 | } |
| 449 | 449 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | ): void |
| 99 | 99 | { |
| 100 | 100 | // Determinar $schemaPath si no fue pasado. |
| 101 | - if ($schemaPath === null) { |
|
| 101 | + if ($schemaPath===null) { |
|
| 102 | 102 | $schemaPath = self::getSchemaPath($xmlDocument); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | if (!$isValid) { |
| 119 | 119 | $errors = !empty($errors) |
| 120 | 120 | ? self::translateLibxmlErrors($errors, array_merge($translations, [ |
| 121 | - '{' . $xmlDocument->getNamespace() . '}' => '', |
|
| 121 | + '{'.$xmlDocument->getNamespace().'}' => '', |
|
| 122 | 122 | ])) |
| 123 | 123 | : [] |
| 124 | 124 | ; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | foreach ($errors as $error) { |
| 150 | 150 | $translatedErrors[] = str_replace( |
| 151 | 151 | ['%(line)s'], |
| 152 | - [(string) $error->line], |
|
| 152 | + [(string)$error->line], |
|
| 153 | 153 | str_replace( |
| 154 | 154 | array_keys($replace), |
| 155 | 155 | array_values($replace), |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | { |
| 175 | 175 | // Determinar el nombre del archivo del esquema del XML. |
| 176 | 176 | $schema = $xmlDocument->getSchema(); |
| 177 | - if ($schema === null) { |
|
| 177 | + if ($schema===null) { |
|
| 178 | 178 | throw new XmlException( |
| 179 | 179 | 'El XML no contiene una ubicación de esquema válida en el atributo "xsi:schemaLocation".' |
| 180 | 180 | ); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | // Armar la ruta al archivo del esquema y corroborar que exista. |
| 184 | 184 | $schemaPath = PathManager::getSchemasPath($schema); |
| 185 | - if ($schemaPath === null) { |
|
| 185 | + if ($schemaPath===null) { |
|
| 186 | 186 | throw new XmlException(sprintf( |
| 187 | 187 | 'No se encontró el archivo de esquema XML %s.', |
| 188 | 188 | $schema |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | $namespace = $this->documentElement->getAttribute('xmlns'); |
| 72 | 72 | |
| 73 | - return $namespace !== '' ? $namespace : null; |
|
| 73 | + return $namespace!=='' ? $namespace : null; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | preg_match('/<\?xml\s+version="([^"]+)"\s+encoding="([^"]+)"\?>/', $source, $matches); |
| 111 | 111 | $version = $matches[1] ?? $this->xmlVersion; |
| 112 | 112 | $encoding = strtoupper($matches[2] ?? $this->encoding); |
| 113 | - if ($encoding === 'UTF-8') { |
|
| 113 | + if ($encoding==='UTF-8') { |
|
| 114 | 114 | $source = XmlUtils::utf2iso($source); |
| 115 | 115 | $source = str_replace(' encoding="UTF-8"?>', ' encoding="ISO-8859-1"?>', $source); |
| 116 | 116 | } |
@@ -83,12 +83,11 @@ |
||
| 83 | 83 | */ |
| 84 | 84 | private function libXmlErrorToString(array $errors): array |
| 85 | 85 | { |
| 86 | - return array_map(function ($error) { |
|
| 87 | - if ($error instanceof LibXMLError ) { |
|
| 86 | + return array_map(function($error) { |
|
| 87 | + if ($error instanceof LibXMLError) { |
|
| 88 | 88 | return sprintf( |
| 89 | 89 | 'Error %s: %s en la línea %d, columna %d (Código: %d).', |
| 90 | - $error->level === LIBXML_ERR_WARNING ? 'Advertencia' : |
|
| 91 | - ($error->level === LIBXML_ERR_ERROR ? 'Error' : 'Fatal'), |
|
| 90 | + $error->level===LIBXML_ERR_WARNING ? 'Advertencia' : ($error->level===LIBXML_ERR_ERROR ? 'Error' : 'Fatal'), |
|
| 92 | 91 | trim($error->message), |
| 93 | 92 | $error->line, |
| 94 | 93 | $error->column, |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $xpath = new DOMXPath($document); |
| 47 | 47 | $result = @$xpath->query($expression); |
| 48 | 48 | |
| 49 | - if ($result === false) { |
|
| 49 | + if ($result===false) { |
|
| 50 | 50 | throw new InvalidArgumentException(sprintf( |
| 51 | 51 | 'Expresión XPath inválida: %s', |
| 52 | 52 | $expression |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | $newString = ''; |
| 131 | 131 | $n_letras = strlen($string); |
| 132 | 132 | $convertir = false; |
| 133 | - for ($i = 0; $i < $n_letras; ++$i) { |
|
| 134 | - if ($string[$i] === '>') { |
|
| 133 | + for ($i = 0; $i<$n_letras; ++$i) { |
|
| 134 | + if ($string[$i]==='>') { |
|
| 135 | 135 | $convertir = true; |
| 136 | 136 | } |
| 137 | - if ($string[$i] === '<') { |
|
| 137 | + if ($string[$i]==='<') { |
|
| 138 | 138 | $convertir = false; |
| 139 | 139 | } |
| 140 | 140 | $newString .= $convertir |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | // Validar que venga DV en el ID (RUN). |
| 47 | 47 | $dv = explode('-', $id)[1] ?? null; |
| 48 | - if ($dv === null) { |
|
| 48 | + if ($dv===null) { |
|
| 49 | 49 | throw new CertificateException(sprintf( |
| 50 | 50 | 'El ID (RUN) %s de la firma no es válido, debe incluir "-" (guión).', |
| 51 | 51 | $id |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Validar que si el ID (RUN) termina con DV igual a "K", sea mayúscula. |
| 56 | - if ($dv === 'k') { |
|
| 56 | + if ($dv==='k') { |
|
| 57 | 57 | throw new CertificateException(sprintf( |
| 58 | 58 | 'El RUN %s asociado a la firma no es válido, termina en "k" (minúscula). Debe adquirir una nueva firma y al comprarla corroborar que la "K" sea mayúscula. Se recomienda no comprar con el mismo proveedor: %s. Esto es necesario porque LibreDTE no puede utilizar un RUN que terminan con "k" (minúscula) en el certificado digital (firma electrónica).', |
| 59 | 59 | $id, |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | // Verificar el serialNumber en el subject del certificado. |
| 172 | 172 | $serialNumber = $this->getData()['subject']['serialNumber'] ?? null; |
| 173 | - if ($serialNumber !== null) { |
|
| 173 | + if ($serialNumber!==null) { |
|
| 174 | 174 | $serialNumber = ltrim(trim($serialNumber), '0'); |
| 175 | 175 | return $force_upper ? strtoupper($serialNumber) : $serialNumber; |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | if (isset($cert['tbsCertificate']['extensions'])) { |
| 182 | 182 | foreach ($cert['tbsCertificate']['extensions'] as $extension) { |
| 183 | 183 | if ( |
| 184 | - $extension['extnId'] === 'id-ce-subjectAltName' |
|
| 184 | + $extension['extnId']==='id-ce-subjectAltName' |
|
| 185 | 185 | && isset($extension['extnValue'][0]['otherName']['value']['ia5String']) |
| 186 | 186 | ) { |
| 187 | 187 | $id = ltrim( |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function getName(): string |
| 208 | 208 | { |
| 209 | 209 | $name = $this->getData()['subject']['CN'] ?? null; |
| 210 | - if ($name === null) { |
|
| 210 | + if ($name===null) { |
|
| 211 | 211 | throw new CertificateException( |
| 212 | 212 | 'No fue posible obtener el Name (subject.CN) de la firma.' |
| 213 | 213 | ); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | public function getEmail(): string |
| 225 | 225 | { |
| 226 | 226 | $email = $this->getData()['subject']['emailAddress'] ?? null; |
| 227 | - if ($email === null) { |
|
| 227 | + if ($email===null) { |
|
| 228 | 228 | throw new CertificateException( |
| 229 | 229 | 'No fue posible obtener el Email (subject.emailAddress) de la firma.' |
| 230 | 230 | ); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | $start = new DateTime($this->getFrom()); |
| 264 | 264 | $end = new DateTime($this->getTo()); |
| 265 | 265 | $diff = $start->diff($end); |
| 266 | - return (int) $diff->format('%a'); |
|
| 266 | + return (int)$diff->format('%a'); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -274,13 +274,13 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | public function getExpirationDays(?string $desde = null): int |
| 276 | 276 | { |
| 277 | - if ($desde === null) { |
|
| 277 | + if ($desde===null) { |
|
| 278 | 278 | $desde = date('Y-m-d\TH:i:s'); |
| 279 | 279 | } |
| 280 | 280 | $start = new DateTime($desde); |
| 281 | 281 | $end = new DateTime($this->getTo()); |
| 282 | 282 | $diff = $start->diff($end); |
| 283 | - return (int) $diff->format('%a'); |
|
| 283 | + return (int)$diff->format('%a'); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | public function isActive(?string $when = null): bool |
| 297 | 297 | { |
| 298 | - if ($when === null) { |
|
| 298 | + if ($when===null) { |
|
| 299 | 299 | $when = date('Y-m-d').'T23:59:59'; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $when .= 'T23:59:59'; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - return $when >= $this->getFrom() && $when <= $this->getTo(); |
|
| 306 | + return $when>=$this->getFrom() && $when<=$this->getTo(); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | { |
| 326 | 326 | $modulus = $this->getPrivateKeyDetails()['rsa']['n'] ?? null; |
| 327 | 327 | |
| 328 | - if ($modulus === null) { |
|
| 328 | + if ($modulus===null) { |
|
| 329 | 329 | throw new CertificateException( |
| 330 | 330 | 'No fue posible obtener el módulo de la clave privada.' |
| 331 | 331 | ); |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | { |
| 344 | 344 | $exponent = $this->getPrivateKeyDetails()['rsa']['e'] ?? null; |
| 345 | 345 | |
| 346 | - if ($exponent === null) { |
|
| 346 | + if ($exponent===null) { |
|
| 347 | 347 | throw new CertificateException( |
| 348 | 348 | 'No fue posible obtener el exponente de la clave privada.' |
| 349 | 349 | ); |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | if (!str_contains($publicKey, '-----BEGIN CERTIFICATE-----')) { |
| 54 | 54 | $body = trim($publicKey); |
| 55 | - $publicKey = '-----BEGIN CERTIFICATE-----' . "\n"; |
|
| 56 | - $publicKey .= self::wordwrap($body, $wordwrap) . "\n"; |
|
| 57 | - $publicKey .= '-----END CERTIFICATE-----' . "\n"; |
|
| 55 | + $publicKey = '-----BEGIN CERTIFICATE-----'."\n"; |
|
| 56 | + $publicKey .= self::wordwrap($body, $wordwrap)."\n"; |
|
| 57 | + $publicKey .= '-----END CERTIFICATE-----'."\n"; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $publicKey; |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | if (!str_contains($privateKey, '-----BEGIN PRIVATE KEY-----')) { |
| 76 | 76 | $body = trim($privateKey); |
| 77 | - $privateKey = '-----BEGIN PRIVATE KEY-----' . "\n"; |
|
| 78 | - $privateKey .= self::wordwrap($body, $wordwrap) . "\n"; |
|
| 79 | - $privateKey .= '-----END PRIVATE KEY-----' . "\n"; |
|
| 77 | + $privateKey = '-----BEGIN PRIVATE KEY-----'."\n"; |
|
| 78 | + $privateKey .= self::wordwrap($body, $wordwrap)."\n"; |
|
| 79 | + $privateKey .= '-----END PRIVATE KEY-----'."\n"; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return $privateKey; |
@@ -118,7 +118,7 @@ |
||
| 118 | 118 | // Traducir los errores. |
| 119 | 119 | foreach ($errors as &$error) { |
| 120 | 120 | foreach ($translations as $code => $trans) { |
| 121 | - if (str_contains($error, 'error:' . $code)) { |
|
| 121 | + if (str_contains($error, 'error:'.$code)) { |
|
| 122 | 122 | $error = sprintf('%s (Error #%s).', $trans, $code); |
| 123 | 123 | } |
| 124 | 124 | } |