@@ -16,7 +16,7 @@ class Chrome extends AbstractPDF
1616 * an array of temporary file handles
1717 * they are unlinked after rendering
1818 *
19- * @var array
19+ * @var array<string>
2020 */
2121 private $ handles = [];
2222
@@ -43,7 +43,7 @@ public function __construct($binary = 'chrome-pdf', $processClass = null)
4343 /**
4444 * A factory for creating process classes, to execute the binary
4545 *
46- * @param string $cmdline The command to run
46+ * @param array< string> $cmdline The command to run
4747 * @return object
4848 */
4949 public function createProcess ($ cmdline )
@@ -100,7 +100,7 @@ public function getMarginString(): ?string
100100 /**
101101 * Gets an array of options to pass to the command line
102102 *
103- * @return array
103+ * @return array<mixed>
104104 */
105105 private function getCommandFlags (): array
106106 {
@@ -139,12 +139,12 @@ private function getCommandFlags(): array
139139 $ opts [] = "--no-displayHeaderFooter " ;
140140 }
141141 if ($ this ->getHeader ()) {
142- $ headerFile = $ this ->getFileForString ($ this ->getHeader ());
142+ $ headerFile = $ this ->getFileForString ($ this ->getHeader () ?: '' );
143143 $ opts [] = "--headerTemplate " ;
144144 $ opts [] = $ headerFile ;
145145 }
146146 if ($ this ->getFooter ()) {
147- $ footerFile = $ this ->getFileForString ($ this ->getFooter ());
147+ $ footerFile = $ this ->getFileForString ($ this ->getFooter () ?: '' );
148148 $ opts [] = "--footerTemplate " ;
149149 $ opts [] = $ footerFile ;
150150 }
@@ -188,7 +188,7 @@ private function getCommandFlags(): array
188188 */
189189 private function getFileForString (string $ content ): string
190190 {
191- $ tmpfile = tempnam (sys_get_temp_dir (), 'chromepdf ' );
191+ $ tmpfile = tempnam (sys_get_temp_dir (), 'chromepdf ' ) ?: '' ;
192192 // Chrome must see the correct extension to load it as html
193193 rename ($ tmpfile , $ tmpfile .= '.html ' );
194194 $ this ->handles [] = $ tmpfile ;
@@ -200,12 +200,12 @@ private function getFileForString(string $content): string
200200 /**
201201 * Execute the local renderer with the given options
202202 *
203- * @param array $options
203+ * @param array<string> $options
204204 * @return string A path to a temporary file containing the rendered PDF
205205 */
206206 private function executeBinary (array $ options ): string
207207 {
208- $ output = tempnam (sys_get_temp_dir (), 'chromepdf ' );
208+ $ output = tempnam (sys_get_temp_dir (), 'chromepdf ' ) ?: '' ;
209209 $ options [] = "--path " ;
210210 $ options [] = $ output ;
211211 array_unshift ($ options , $ this ->binary , 'pdf ' );
@@ -229,7 +229,7 @@ public function renderContent(string $content)
229229 $ opts [] = $ file ;
230230
231231 $ outputFile = $ this ->executeBinary ($ opts );
232- return fopen ($ outputFile , 'r ' );
232+ return fopen ($ outputFile , 'r ' ) ?: null ;
233233 }
234234
235235 /**
@@ -242,7 +242,7 @@ public function renderURL(string $url)
242242 $ opts [] = $ url ;
243243
244244 $ outputFile = $ this ->executeBinary ($ opts );
245- return fopen ($ outputFile , 'r ' );
245+ return fopen ($ outputFile , 'r ' ) ?: null ;
246246 }
247247
248248 /**
@@ -255,6 +255,6 @@ public function renderFile(string $path)
255255 $ opts [] = $ path ;
256256
257257 $ outputFile = $ this ->executeBinary ($ opts );
258- return fopen ($ outputFile , 'r ' );
258+ return fopen ($ outputFile , 'r ' ) ?: null ;
259259 }
260260}
0 commit comments