@@ -17,9 +17,9 @@ |
||
| 17 | 17 | { |
| 18 | 18 | $msg = ''; |
| 19 | 19 | foreach ($errors as $error) { |
| 20 | - $msg .= $error."\n"; |
|
| 20 | + $msg .= $error . "\n"; |
|
| 21 | 21 | } |
| 22 | - return new static('This XML is not valid. '.$msg); |
|
| 22 | + return new static('This XML is not valid. ' . $msg); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function isNotXml() |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | $dom->formatOutput = false; |
| 40 | 40 | $dom->loadXML($xml, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG); |
| 41 | 41 | libxml_clear_errors(); |
| 42 | - if (! $dom->schemaValidate($xsd)) { |
|
| 42 | + if (!$dom->schemaValidate($xsd)) { |
|
| 43 | 43 | $errors = []; |
| 44 | 44 | foreach (libxml_get_errors() as $error) { |
| 45 | 45 | $errors[] = $error->message; |
@@ -23,10 +23,10 @@ discard block |
||
| 23 | 23 | public static function replaceSpecialsChars($string) |
| 24 | 24 | { |
| 25 | 25 | $string = trim($string); |
| 26 | - $aFind = ['&','á','à','ã','â','é','ê','í','ó','ô','õ','ú','ü', |
|
| 27 | - 'ç','Á','À','Ã','Â','É','Ê','Í','Ó','Ô','Õ','Ú','Ü','Ç']; |
|
| 28 | - $aSubs = ['e','a','a','a','a','e','e','i','o','o','o','u','u', |
|
| 29 | - 'c','A','A','A','A','E','E','I','O','O','O','U','U','C']; |
|
| 26 | + $aFind = ['&', 'á', 'à', 'ã', 'â', 'é', 'ê', 'í', 'ó', 'ô', 'õ', 'ú', 'ü', |
|
| 27 | + 'ç', 'Á', 'À', 'Ã', 'Â', 'É', 'Ê', 'Í', 'Ó', 'Ô', 'Õ', 'Ú', 'Ü', 'Ç']; |
|
| 28 | + $aSubs = ['e', 'a', 'a', 'a', 'a', 'e', 'e', 'i', 'o', 'o', 'o', 'u', 'u', |
|
| 29 | + 'c', 'A', 'A', 'A', 'A', 'E', 'E', 'I', 'O', 'O', 'O', 'U', 'U', 'C']; |
|
| 30 | 30 | $newstr = str_replace($aFind, $aSubs, $string); |
| 31 | 31 | $newstr = preg_replace("/[^a-zA-Z0-9 @,-_.;:\/]/", "", $newstr); |
| 32 | 32 | return $newstr; |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | public static function clearProtocoledXML($string) |
| 95 | 95 | { |
| 96 | 96 | $procXML = self::clearXmlString($string); |
| 97 | - $aApp = array('nfe','cte','mdfe'); |
|
| 97 | + $aApp = array('nfe', 'cte', 'mdfe'); |
|
| 98 | 98 | foreach ($aApp as $app) { |
| 99 | 99 | $procXML = str_replace( |
| 100 | - 'xmlns="http://www.portalfiscal.inf.br/'.$app.'" xmlns="http://www.w3.org/2000/09/xmldsig#"', |
|
| 101 | - 'xmlns="http://www.portalfiscal.inf.br/'.$app.'"', |
|
| 100 | + 'xmlns="http://www.portalfiscal.inf.br/' . $app . '" xmlns="http://www.w3.org/2000/09/xmldsig#"', |
|
| 101 | + 'xmlns="http://www.portalfiscal.inf.br/' . $app . '"', |
|
| 102 | 102 | $procXML |
| 103 | 103 | ); |
| 104 | 104 | } |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | public static function removeSomeAlienCharsfromTxt($txt) |
| 114 | 114 | { |
| 115 | 115 | //remove CRs and TABs |
| 116 | - $txt = str_replace(["\r","\t"], "", $txt); |
|
| 116 | + $txt = str_replace(["\r", "\t"], "", $txt); |
|
| 117 | 117 | //remove multiple spaces |
| 118 | 118 | $txt = preg_replace('/(?:\s\s+)/', ' ', $txt); |
| 119 | 119 | //remove spaces at begin and end of fields |
| 120 | - $txt = str_replace(["| "," |"], "|", $txt); |
|
| 120 | + $txt = str_replace(["| ", " |"], "|", $txt); |
|
| 121 | 121 | return $txt; |
| 122 | 122 | } |
| 123 | 123 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | class Signer |
| 35 | 35 | { |
| 36 | - private static $canonical = [true,false,null,null]; |
|
| 36 | + private static $canonical = [true, false, null, null]; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Make Signature tag |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $tagname, |
| 54 | 54 | $mark = 'Id', |
| 55 | 55 | $algorithm = OPENSSL_ALGO_SHA1, |
| 56 | - $canonical = [true,false,null,null], |
|
| 56 | + $canonical = [true, false, null, null], |
|
| 57 | 57 | $rootname = '' |
| 58 | 58 | ) { |
| 59 | 59 | if (!empty($canonical)) { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | if (empty($content)) { |
| 63 | 63 | throw SignerException::isNotXml(); |
| 64 | 64 | } |
| 65 | - if (! Validator::isXML($content)) { |
|
| 65 | + if (!Validator::isXML($content)) { |
|
| 66 | 66 | throw SignerException::isNotXml(); |
| 67 | 67 | } |
| 68 | 68 | $dom = new DOMDocument('1.0', 'UTF-8'); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (empty($node) || empty($root)) { |
| 78 | 78 | throw SignerException::tagNotFound($tagname); |
| 79 | 79 | } |
| 80 | - if (! self::existsSignature($content)) { |
|
| 80 | + if (!self::existsSignature($content)) { |
|
| 81 | 81 | $dom = self::createSignature( |
| 82 | 82 | $certificate, |
| 83 | 83 | $dom, |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | DOMNode $node, |
| 111 | 111 | $mark, |
| 112 | 112 | $algorithm = OPENSSL_ALGO_SHA1, |
| 113 | - $canonical = [true,false,null,null] |
|
| 113 | + $canonical = [true, false, null, null] |
|
| 114 | 114 | ) { |
| 115 | 115 | $nsDSIG = 'http://www.w3.org/2000/09/xmldsig#'; |
| 116 | 116 | $nsCannonMethod = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $nsSignatureMethod = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'; |
| 123 | 123 | $nsDigestMethod = 'http://www.w3.org/2001/04/xmlenc#sha256'; |
| 124 | 124 | } |
| 125 | - $nsTransformMethod1 ='http://www.w3.org/2000/09/xmldsig#enveloped-signature'; |
|
| 125 | + $nsTransformMethod1 = 'http://www.w3.org/2000/09/xmldsig#enveloped-signature'; |
|
| 126 | 126 | $nsTransformMethod2 = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'; |
| 127 | 127 | $idSigned = trim($mark); |
| 128 | 128 | $digestValue = self::makeDigest($node, $digestAlgorithm, $canonical); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public static function removeSignature($content) |
| 176 | 176 | { |
| 177 | - if (! self::existsSignature($content)) { |
|
| 177 | + if (!self::existsSignature($content)) { |
|
| 178 | 178 | return $content; |
| 179 | 179 | } |
| 180 | 180 | $dom = new \DOMDocument('1.0', 'utf-8'); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | public static function isSigned( |
| 203 | 203 | $content, |
| 204 | 204 | $tagname = '', |
| 205 | - $canonical = [true,false,null,null] |
|
| 205 | + $canonical = [true, false, null, null] |
|
| 206 | 206 | ) { |
| 207 | 207 | if (self::existsSignature($content)) { |
| 208 | 208 | if (self::digestCheck($content, $tagname, $canonical)) { |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public static function existsSignature($content) |
| 223 | 223 | { |
| 224 | - if (! Validator::isXML($content)) { |
|
| 224 | + if (!Validator::isXML($content)) { |
|
| 225 | 225 | throw SignerException::isNotXml(); |
| 226 | 226 | } |
| 227 | 227 | $dom = new \DOMDocument('1.0', 'utf-8'); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | private static function signatureCheck( |
| 245 | 245 | $xml, |
| 246 | - $canonical = [true,false,null,null] |
|
| 246 | + $canonical = [true, false, null, null] |
|
| 247 | 247 | ) { |
| 248 | 248 | $dom = new \DOMDocument('1.0', 'utf-8'); |
| 249 | 249 | $dom->formatOutput = false; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | $decodedSignature = base64_decode( |
| 270 | 270 | str_replace(array("\r", "\n"), '', $signatureValue) |
| 271 | 271 | ); |
| 272 | - if (! $publicKey->verify($signInfoNode, $decodedSignature, $algorithm)) { |
|
| 272 | + if (!$publicKey->verify($signInfoNode, $decodedSignature, $algorithm)) { |
|
| 273 | 273 | throw SignerException::signatureComparisonFailed(); |
| 274 | 274 | } |
| 275 | 275 | return true; |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | private static function digestCheck( |
| 286 | 286 | $xml, |
| 287 | 287 | $tagname = '', |
| 288 | - $canonical = [true,false,null,null] |
|
| 288 | + $canonical = [true, false, null, null] |
|
| 289 | 289 | ) { |
| 290 | 290 | $dom = new \DOMDocument('1.0', 'utf-8'); |
| 291 | 291 | $dom->formatOutput = false; |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | private static function makeDigest( |
| 342 | 342 | DOMNode $node, |
| 343 | 343 | $algorithm, |
| 344 | - $canonical = [true,false,null,null] |
|
| 344 | + $canonical = [true, false, null, null] |
|
| 345 | 345 | ) { |
| 346 | 346 | //calcular o hash dos dados |
| 347 | 347 | $c14n = self::canonize($node, $canonical); |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | private static function canonize( |
| 359 | 359 | DOMNode $node, |
| 360 | - $canonical = [true,false,null,null] |
|
| 360 | + $canonical = [true, false, null, null] |
|
| 361 | 361 | ) { |
| 362 | 362 | return $node->C14N( |
| 363 | 363 | $canonical[0], |