diff --git a/src/Knp/Snappy/AbstractGenerator.php b/src/Knp/Snappy/AbstractGenerator.php index dd9690a2..2f8041c0 100644 --- a/src/Knp/Snappy/AbstractGenerator.php +++ b/src/Knp/Snappy/AbstractGenerator.php @@ -65,7 +65,7 @@ abstract class AbstractGenerator implements GeneratorInterface, LoggerAwareInter * @param array $options * @param null|array $env */ - public function __construct(string $binary = null, array $options = [], array $env = null) + public function __construct($binary, array $options = [], array $env = null) { $this->configure(); @@ -88,8 +88,10 @@ public function __destruct() * Set the logger to use to log debugging data. * * @param LoggerInterface $logger + * + * @return $this */ - public function setLogger(LoggerInterface $logger): self + public function setLogger(LoggerInterface $logger) { $this->logger = $logger; @@ -101,8 +103,10 @@ public function setLogger(LoggerInterface $logger): self * Useful when letting Snappy deal with file creation. * * @param string $defaultExtension + * + * @return $this */ - public function setDefaultExtension(string $defaultExtension): self + public function setDefaultExtension($defaultExtension) { $this->defaultExtension = $defaultExtension; @@ -127,8 +131,10 @@ public function getDefaultExtension(): string * @param mixed $value The value (NULL to unset) * * @throws InvalidArgumentException + * + * @return $this */ - public function setOption(string $name, $value): self + public function setOption($name, $value) { if (!\array_key_exists($name, $this->options)) { throw new InvalidArgumentException(\sprintf('The option \'%s\' does not exist.', $name)); @@ -145,8 +151,10 @@ public function setOption(string $name, $value): self * Sets the timeout. * * @param null|int $timeout The timeout to set + * + * @return $this */ - public function setTimeout(?int $timeout): self + public function setTimeout($timeout) { $this->timeout = $timeout; @@ -157,8 +165,10 @@ public function setTimeout(?int $timeout): self * Sets an array of options. * * @param array $options An associative array of options as name/value + * + * @return $this */ - public function setOptions(array $options): self + public function setOptions(array $options) { foreach ($options as $name => $value) { $this->setOption($name, $value); @@ -172,7 +182,7 @@ public function setOptions(array $options): self * * @return array */ - public function getOptions(): array + public function getOptions() { return $this->options; } @@ -266,8 +276,10 @@ public function getOutputFromHtml($html, array $options = []) * Defines the binary. * * @param null|string $binary The path/name of the binary + * + * @return $this */ - public function setBinary(?string $binary): self + public function setBinary($binary) { $this->binary = $binary; @@ -279,7 +291,7 @@ public function setBinary(?string $binary): self * * @return null|string */ - public function getBinary(): ?string + public function getBinary() { return $this->binary; } @@ -294,7 +306,7 @@ public function getBinary(): ?string * * @return string */ - public function getCommand($input, string $output, array $options = []): string + public function getCommand($input, $output, array $options = []) { if (null === $this->binary) { throw new LogicException('You must define a binary prior to conversion.'); @@ -307,8 +319,10 @@ public function getCommand($input, string $output, array $options = []): string /** * Removes all temporary files. + * + * @return void */ - public function removeTemporaryFiles(): void + public function removeTemporaryFiles() { foreach ($this->temporaryFiles as $file) { $this->unlink($file); @@ -320,7 +334,7 @@ public function removeTemporaryFiles(): void * * @return string */ - public function getTemporaryFolder(): string + public function getTemporaryFolder() { if ($this->temporaryFolder === null) { return \sys_get_temp_dir(); @@ -336,7 +350,7 @@ public function getTemporaryFolder(): string * * @return $this */ - public function setTemporaryFolder(string $temporaryFolder): self + public function setTemporaryFolder($temporaryFolder) { $this->temporaryFolder = $temporaryFolder; @@ -348,7 +362,7 @@ public function setTemporaryFolder(string $temporaryFolder): self * * @return void */ - public function resetOptions(): void + public function resetOptions() { $this->options = []; $this->configure(); @@ -361,7 +375,7 @@ public function resetOptions(): void * * @see AbstractGenerator::addOption() */ - abstract protected function configure(): void; + abstract protected function configure(); /** * Adds an option. @@ -370,8 +384,10 @@ abstract protected function configure(): void; * @param mixed $default An optional default value * * @throws InvalidArgumentException + * + * @return $this */ - protected function addOption(string $name, $default = null): self + protected function addOption($name, $default = null) { if (\array_key_exists($name, $this->options)) { throw new InvalidArgumentException(\sprintf('The option \'%s\' already exists.', $name)); @@ -386,8 +402,10 @@ protected function addOption(string $name, $default = null): self * Adds an array of options. * * @param array $options + * + * @return $this */ - protected function addOptions(array $options): self + protected function addOptions(array $options) { foreach ($options as $name => $default) { $this->addOption($name, $default); @@ -406,7 +424,7 @@ protected function addOptions(array $options): self * * @return array */ - protected function mergeOptions(array $options): array + protected function mergeOptions(array $options) { $mergedOptions = $this->options; @@ -428,8 +446,10 @@ protected function mergeOptions(array $options): array * @param string $command The generation command * * @throws RuntimeException if the output file generation failed + * + * @return void */ - protected function checkOutput(string $output, string $command): void + protected function checkOutput($output, $command) { // the output file must exist if (!$this->fileExists($output)) { @@ -451,8 +471,10 @@ protected function checkOutput(string $output, string $command): void * @param string $command The run command * * @throws RuntimeException if the output file generation failed + * + * @return void */ - protected function checkProcessStatus(int $status, string $stdout, string $stderr, string $command): void + protected function checkProcessStatus($status, $stdout, $stderr, $command) { if (0 !== $status && '' !== $stderr) { throw new RuntimeException(\sprintf('The exit status code \'%s\' says something went wrong:' . "\n" . 'stderr: "%s"' . "\n" . 'stdout: "%s"' . "\n" . 'command: %s.', $status, $stderr, $stdout, $command), $status); @@ -468,7 +490,7 @@ protected function checkProcessStatus(int $status, string $stdout, string $stder * * @return string The filename */ - protected function createTemporaryFile(?string $content = null, ?string $extension = null): string + protected function createTemporaryFile($content = null, $extension = null) { $dir = \rtrim($this->getTemporaryFolder(), \DIRECTORY_SEPARATOR); @@ -505,7 +527,7 @@ protected function createTemporaryFile(?string $content = null, ?string $extensi * * @return string */ - protected function buildCommand(string $binary, $input, string $output, array $options = []): string + protected function buildCommand($binary, $input, $output, array $options = []) { $command = $binary; $escapedBinary = \escapeshellarg($binary); @@ -565,7 +587,7 @@ protected function buildCommand(string $binary, $input, string $output, array $o * * @return bool */ - protected function isAssociativeArray(array $array): bool + protected function isAssociativeArray(array $array) { return (bool) \count(\array_filter(\array_keys($array), 'is_string')); } @@ -578,7 +600,7 @@ protected function isAssociativeArray(array $array): bool * * @return array [status, stdout, stderr] */ - protected function executeCommand(string $command): array + protected function executeCommand($command) { if (\method_exists(Process::class, 'fromShellCommandline')) { $process = Process::fromShellCommandline($command, null, $this->env); @@ -609,8 +631,10 @@ protected function executeCommand(string $command): array * @throws FileAlreadyExistsException * @throws RuntimeException * @throws InvalidArgumentException + * + * @return void */ - protected function prepareOutput(string $filename, bool $overwrite): void + protected function prepareOutput($filename, $overwrite) { $directory = \dirname($filename); @@ -636,7 +660,7 @@ protected function prepareOutput(string $filename, bool $overwrite): void * * @return string */ - protected function getFileContents(string $filename): string + protected function getFileContents($filename) { $fileContent = \file_get_contents($filename); @@ -654,7 +678,7 @@ protected function getFileContents(string $filename): string * * @return bool */ - protected function fileExists(string $filename): bool + protected function fileExists($filename) { return \file_exists($filename); } @@ -666,7 +690,7 @@ protected function fileExists(string $filename): bool * * @return bool */ - protected function isFile(string $filename): bool + protected function isFile($filename) { return \strlen($filename) <= \PHP_MAXPATHLEN && \is_file($filename); } @@ -678,7 +702,7 @@ protected function isFile(string $filename): bool * * @return int */ - protected function filesize(string $filename): int + protected function filesize($filename) { $filesize = \filesize($filename); @@ -696,7 +720,7 @@ protected function filesize(string $filename): int * * @return bool */ - protected function unlink(string $filename): bool + protected function unlink($filename) { return $this->fileExists($filename) ? \unlink($filename) : false; } @@ -708,7 +732,7 @@ protected function unlink(string $filename): bool * * @return bool */ - protected function isDir(string $filename): bool + protected function isDir($filename) { return \is_dir($filename); } @@ -720,7 +744,7 @@ protected function isDir(string $filename): bool * * @return bool */ - protected function mkdir(string $pathname): bool + protected function mkdir($pathname) { return \mkdir($pathname, 0777, true); } diff --git a/src/Knp/Snappy/Image.php b/src/Knp/Snappy/Image.php index b572ffa9..a66310be 100644 --- a/src/Knp/Snappy/Image.php +++ b/src/Knp/Snappy/Image.php @@ -13,7 +13,7 @@ class Image extends AbstractGenerator /** * {@inheritdoc} */ - public function __construct(string $binary = null, array $options = [], array $env = null) + public function __construct($binary = null, array $options = [], array $env = null) { $this->setDefaultExtension('jpg'); @@ -23,7 +23,7 @@ public function __construct(string $binary = null, array $options = [], array $e /** * {@inheritdoc} */ - protected function configure(): void + protected function configure() { $this->addOptions([ 'allow' => null, // Allow the file or files from the specified folder to be loaded (repeatable) diff --git a/src/Knp/Snappy/Pdf.php b/src/Knp/Snappy/Pdf.php index ba776b11..b3a51ade 100644 --- a/src/Knp/Snappy/Pdf.php +++ b/src/Knp/Snappy/Pdf.php @@ -18,7 +18,7 @@ class Pdf extends AbstractGenerator /** * {@inheritdoc} */ - public function __construct(string $binary = null, array $options = [], array $env = null) + public function __construct($binary = null, array $options = [], array $env = null) { $this->setDefaultExtension('pdf'); $this->setOptionsWithContentCheck(); @@ -43,7 +43,7 @@ public function generate($input, $output, array $options = [], $overwrite = fals * * @return array $options Transformed options */ - protected function handleOptions(array $options = []): array + protected function handleOptions(array $options = []) { foreach ($options as $option => $value) { if (null === $value) { @@ -73,7 +73,7 @@ protected function handleOptions(array $options = []): array * * @return bool */ - protected function isOptionUrl($option): bool + protected function isOptionUrl($option) { return (bool) \filter_var($option, \FILTER_VALIDATE_URL); } @@ -81,7 +81,7 @@ protected function isOptionUrl($option): bool /** * {@inheritdoc} */ - protected function configure(): void + protected function configure() { $this->addOptions([ // Global options @@ -228,8 +228,10 @@ protected function configure(): void /** * Array with options which require to store the content of the option before passing it to wkhtmltopdf. + * + * @return $this */ - protected function setOptionsWithContentCheck(): self + protected function setOptionsWithContentCheck() { $this->optionsWithContentCheck = [ 'header-html' => 'html', diff --git a/tests/Knp/Snappy/ImageTest.php b/tests/Knp/Snappy/ImageTest.php index 6c2bb383..71bd1ca4 100644 --- a/tests/Knp/Snappy/ImageTest.php +++ b/tests/Knp/Snappy/ImageTest.php @@ -7,7 +7,10 @@ class ImageTest extends TestCase { - public function testCreateInstance(): void + /** + * @return void + */ + public function testCreateInstance() { $testObject = new Image(); $this->assertInstanceOf(Image::class, $testObject); diff --git a/tests/Knp/Snappy/PdfTest.php b/tests/Knp/Snappy/PdfTest.php index f77de540..72ca25f7 100644 --- a/tests/Knp/Snappy/PdfTest.php +++ b/tests/Knp/Snappy/PdfTest.php @@ -161,12 +161,18 @@ public function __construct() parent::__construct('emptyBinary'); } - public function getLastCommand(): string + /** + * @return string + */ + public function getLastCommand() { return $this->lastCommand; } - public function getOutput($input, array $options = []): string + /** + * {@inheritdoc} + */ + public function getOutput($input, array $options = []) { $filename = $this->createTemporaryFile(null, $this->getDefaultExtension()); $this->generate($input, $filename, $options, true); @@ -174,14 +180,20 @@ public function getOutput($input, array $options = []): string return 'output'; } - protected function executeCommand(string $command): array + /** + * {@inheritdoc} + */ + protected function executeCommand($command) { $this->lastCommand = $command; return [0, 'output', 'errorOutput']; } - protected function checkOutput(string $output, string $command): void + /** + * {@inheritdoc} + */ + protected function checkOutput($output, $command) { //let's say everything went right }