Skip to content

Commit 90b84f9

Browse files
committed
PHP 7.4 support + modernize codestyle
1 parent d2828e1 commit 90b84f9

File tree

4 files changed

+10
-34
lines changed

4 files changed

+10
-34
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Install
99
By Composer:
1010

1111
```shell
12-
composer require baraja-core/php-pdf-to-image
12+
$ composer require baraja-core/php-pdf-to-image
1313
```
1414

1515
Usage
@@ -21,4 +21,4 @@ $imagePath = __DIR__ . '/example.jpg';
2121

2222
// Render PDF to image and save to disk.
2323
\Baraja\PdfToImage\Convertor::convert($pdfPath, $imagePath, 'jpg');
24-
```
24+
```

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.1.0"
12+
"php": ">=7.4.0"
1313
},
1414
"require-dev": {
1515
"phpstan/phpstan": "^0.12.18",
1616
"tracy/tracy": "^2.7",
17-
"phpstan/phpstan-nette": "^0.12.6"
17+
"phpstan/phpstan-nette": "^0.12.6",
18+
"symplify/easy-coding-standard": "^7.2"
1819
},
1920
"autoload": {
2021
"classmap": [

src/Convertor.php

+4-27
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ final class Convertor
1616
public const SUPPORTED_FORMATS = [self::FORMAT_JPG, self::FORMAT_PNG, self::FORMAT_GIF];
1717

1818

19-
/**
20-
* @throws \Error
21-
*/
19+
/** @throws \Error */
2220
public function __construct()
2321
{
2422
throw new \Error('Class ' . get_class($this) . ' is static and cannot be instantiated.');
@@ -28,25 +26,18 @@ public function __construct()
2826
/**
2927
* Convert first page of PDF to image and save to disk.
3028
*
31-
* @param string $pdfPath
32-
* @param string $savePath
33-
* @param string $format
34-
* @param bool $trim
3529
* @throws ConvertorException
3630
*/
3731
public static function convert(string $pdfPath, string $savePath, string $format = 'jpg', bool $trim = false): void
3832
{
3933
if (\in_array($format = strtolower($format), self::SUPPORTED_FORMATS, true) === false) {
4034
ConvertorException::unsupportedFormat($format);
4135
}
42-
4336
if (\is_file($pdfPath) === false) {
4437
ConvertorException::fileDoesNotExist($pdfPath);
4538
}
46-
4739
try {
4840
$im = self::process($pdfPath, $savePath);
49-
5041
if ($trim === true) {
5142
$im->setImageBorderColor('rgb(255,255,255)');
5243
$im->trimImage(1);
@@ -59,8 +50,6 @@ public static function convert(string $pdfPath, string $savePath, string $format
5950

6051

6152
/**
62-
* @param string $pdfPath
63-
* @param string $savePath
6453
* @return \Imagick
6554
* @throws ConvertorException|\ImagickException
6655
*/
@@ -79,12 +68,8 @@ private static function process(string $pdfPath, string $savePath): \Imagick
7968

8069

8170
/**
82-
* Writes a string to a file.
83-
* Moved from nette/utils
71+
* Writes a string to a file. Moved from nette/utils
8472
*
85-
* @param string $file
86-
* @param string $content
87-
* @param int|null $mode
8873
* @throws ConvertorException
8974
*/
9075
private static function write(string $file, string $content, ?int $mode = 0666): void
@@ -100,11 +85,8 @@ private static function write(string $file, string $content, ?int $mode = 0666):
10085

10186

10287
/**
103-
* Creates a directory.
104-
* Moved from nette/utils
88+
* Creates a directory. Moved from nette/utils
10589
*
106-
* @param string $dir
107-
* @param int $mode
10890
* @throws ConvertorException
10991
*/
11092
private static function createDir(string $dir, int $mode = 0777): void
@@ -115,13 +97,8 @@ private static function createDir(string $dir, int $mode = 0777): void
11597
}
11698

11799

118-
/**
119-
* Moved from nette/utils
120-
*
121-
* @return string
122-
*/
123100
private static function getLastError(): string
124101
{
125102
return (string) preg_replace('#^\w+\(.*?\): #', '', error_get_last()['message']);
126103
}
127-
}
104+
}

src/ConvertorException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ final class ConvertorException extends \Exception
99
{
1010

1111
/**
12-
* @param string $path
1312
* @throws ConvertorException
1413
*/
1514
public static function fileDoesNotExist(string $path): void
@@ -19,7 +18,6 @@ public static function fileDoesNotExist(string $path): void
1918

2019

2120
/**
22-
* @param string $format
2321
* @throws ConvertorException
2422
*/
2523
public static function unsupportedFormat(string $format): void
@@ -38,4 +36,4 @@ public static function imagicKIsNotInstalled(): void
3836
{
3937
throw new self('Imagick is not installed.');
4038
}
41-
}
39+
}

0 commit comments

Comments
 (0)