@@ -47,7 +47,7 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
47
47
// load the cfdi document
48
48
$ cfdi = new DOMDocument ();
49
49
if (! $ cfdi ->loadXML ($ cfdiContent )) {
50
- $ this ->throwLibXmlErrorOrMessage ('Error while loading the cfdi content ' );
50
+ throw $ this ->createLibXmlErrorOrMessage ('Error while loading the cfdi content ' );
51
51
}
52
52
53
53
// if not set, obtain default location from document version
@@ -61,18 +61,18 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
61
61
62
62
$ xsl = new DOMDocument ();
63
63
if (! $ xsl ->load ($ xsltLocation )) {
64
- $ this ->throwLibXmlErrorOrMessage ('Error while loading the Xslt location ' );
64
+ throw $ this ->createLibXmlErrorOrMessage ('Error while loading the Xslt location ' );
65
65
}
66
66
67
67
$ xslt = new XSLTProcessor ();
68
- if (! $ xslt ->importStyleSheet ($ xsl )) {
69
- $ this ->throwLibXmlErrorOrMessage ('Error while importing the style sheet from the Xslt location ' );
68
+ if (! $ xslt ->importStylesheet ($ xsl )) {
69
+ throw $ this ->createLibXmlErrorOrMessage ('Error while importing the style sheet from the Xslt location ' );
70
70
}
71
71
72
72
// this error silenced call is intentional, avoid transformation errors except when return false
73
- $ transform = @$ xslt ->transformToXML ($ cfdi );
73
+ $ transform = @$ xslt ->transformToXml ($ cfdi );
74
74
if (false === $ transform || null === $ transform ) {
75
- $ this ->throwLibXmlErrorOrMessage ('Error while transforming the xslt content ' );
75
+ throw $ this ->createLibXmlErrorOrMessage ('Error while transforming the xslt content ' );
76
76
}
77
77
78
78
return $ transform ;
@@ -82,12 +82,12 @@ public function build(string $cfdiContent, string $xsltLocation = ''): string
82
82
}
83
83
}
84
84
85
- private function throwLibXmlErrorOrMessage (string $ message )
85
+ private function createLibXmlErrorOrMessage (string $ message ): \ Exception
86
86
{
87
87
$ error = libxml_get_last_error ();
88
- if ($ error instanceof LibXMLError) {
88
+ if (( $ error instanceof LibXMLError) && isset ( $ error -> message ) ) {
89
89
$ message = $ message . ': ' . $ error ->message ;
90
90
}
91
- throw new \RuntimeException ($ message );
91
+ return new \RuntimeException ($ message );
92
92
}
93
93
}
0 commit comments