Skip to content

Commit 678dd17

Browse files
Simple changes for phpstan.
1 parent b3967d1 commit 678dd17

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/AbstractPDF.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,23 @@ public function getLandscape(): ?bool
462462
* Renders a string of HTML to a PDF
463463
*
464464
* @param string $content Content to render
465-
* @return resource
465+
* @return resource|null
466466
*/
467467
abstract public function renderContent(string $content);
468468

469469
/**
470470
* Renders a URL to a PDF
471471
*
472472
* @param string $url URL to render
473-
* @return resource
473+
* @return resource|null
474474
*/
475475
abstract public function renderURL(string $url);
476476

477477
/**
478478
* Renders a local file to a PDF
479479
*
480480
* @param string $path Local file to render
481-
* @return resource
481+
* @return resource|null
482482
*/
483483
abstract public function renderFile(string $path);
484484
}

src/Browserless.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Browserless extends AbstractPDF
2222
*/
2323
private $pdfEndpoint = '/pdf';
2424
/**
25-
* @var object
25+
* @var \GuzzleHttp\Client
2626
*/
2727
private $client;
2828
/**
@@ -40,7 +40,7 @@ class Browserless extends AbstractPDF
4040

4141
/**
4242
* @param string $apiKey api key from browserless.io
43-
* @param object $client custom Guzzle client
43+
* @param \GuzzleHttp\Client $client custom Guzzle client
4444
*/
4545
public function __construct(string $apiKey = null, $client = null)
4646
{
@@ -149,7 +149,7 @@ public function getRotation(): ?int
149149
/**
150150
* Gets the payload of JSON options to be sent to browserless, minus the `url` or `html` property
151151
*
152-
* @return array
152+
* @return array<string, mixed>
153153
*/
154154
public function getFormattedOptions(): array
155155
{
@@ -227,7 +227,7 @@ public function getFormattedOptions(): array
227227
}
228228

229229
/**
230-
* @param array $options
230+
* @param array<string, mixed> $options
231231
* @return resource
232232
*/
233233
private function render(array $options)

src/Chrome.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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 array $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

Comments
 (0)