Skip to content

Commit 257e0c3

Browse files
authored
Merge pull request #350 from erikn69/pacth-1
[1.x] Fix PHP 8.1 deprecations
2 parents 753bc82 + 8a3449f commit 257e0c3

File tree

8 files changed

+41
-17
lines changed

8 files changed

+41
-17
lines changed

.github/workflows/test.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ jobs:
5454
run: |
5555
composer update --prefer-dist --no-interaction --no-ansi --no-progress
5656
php vendor/bin/phpunit
57+
58+
tests-php-8-1:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@master
62+
- uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: '8.1'
65+
- name: PHPUnit
66+
run: |
67+
composer update --prefer-dist --no-interaction --no-ansi --no-progress
68+
php vendor/bin/phpunit

src/Manipulators/Brightness.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Intervention\Image\Image;
66

77
/**
8-
* @property string $bri
8+
* @property string|null $bri
99
*/
1010
class Brightness extends BaseManipulator
1111
{
@@ -34,7 +34,7 @@ public function run(Image $image)
3434
*/
3535
public function getBrightness()
3636
{
37-
if (!preg_match('/^-*[0-9]+$/', $this->bri)) {
37+
if (null === $this->bri || !preg_match('/^-*[0-9]+$/', $this->bri)) {
3838
return;
3939
}
4040

src/Manipulators/Contrast.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Intervention\Image\Image;
66

77
/**
8-
* @property string $con
8+
* @property string|null $con
99
*/
1010
class Contrast extends BaseManipulator
1111
{
@@ -34,7 +34,7 @@ public function run(Image $image)
3434
*/
3535
public function getContrast()
3636
{
37-
if (!preg_match('/^-*[0-9]+$/', $this->con)) {
37+
if (null === $this->con || !preg_match('/^-*[0-9]+$/', $this->con)) {
3838
return;
3939
}
4040

src/Manipulators/Crop.php

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function run(Image $image)
4343
*/
4444
public function getCoordinates(Image $image)
4545
{
46+
if (null === $this->crop) {
47+
return;
48+
}
49+
4650
$coordinates = explode(',', $this->crop);
4751

4852
if (4 !== count($coordinates) or

src/Manipulators/Gamma.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Intervention\Image\Image;
66

77
/**
8-
* @property string $gam
8+
* @property string|null $gam
99
*/
1010
class Gamma extends BaseManipulator
1111
{
@@ -34,7 +34,7 @@ public function run(Image $image)
3434
*/
3535
public function getGamma()
3636
{
37-
if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
37+
if (null === $this->gam || !preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
3838
return;
3939
}
4040

src/Manipulators/Size.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use Intervention\Image\Image;
66

77
/**
8-
* @property string $dpr
9-
* @property string $fit
10-
* @property string $h
11-
* @property string $w
8+
* @property string $dpr
9+
* @property string|null $fit
10+
* @property string $h
11+
* @property string $w
1212
*/
1313
class Size extends BaseManipulator
1414
{
@@ -117,6 +117,10 @@ public function getHeight()
117117
*/
118118
public function getFit()
119119
{
120+
if (null === $this->fit) {
121+
return 'contain';
122+
}
123+
120124
if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch'], true)) {
121125
return $this->fit;
122126
}
@@ -408,6 +412,10 @@ public function resolveCropOffset(Image $image, $width, $height)
408412
*/
409413
public function getCrop()
410414
{
415+
if (null === $this->fit) {
416+
return [50, 50, 1.0];
417+
}
418+
411419
$cropMethods = [
412420
'crop-top-left' => [0, 0, 1.0],
413421
'crop-top' => [50, 0, 1.0],

src/Server.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getSource()
138138
*/
139139
public function setSourcePathPrefix($sourcePathPrefix)
140140
{
141-
$this->sourcePathPrefix = trim($sourcePathPrefix, '/');
141+
$this->sourcePathPrefix = trim((string) $sourcePathPrefix, '/');
142142
}
143143

144144
/**
@@ -200,7 +200,7 @@ public function sourceFileExists($path)
200200
*/
201201
public function setBaseUrl($baseUrl)
202202
{
203-
$this->baseUrl = trim($baseUrl, '/');
203+
$this->baseUrl = trim((string) $baseUrl, '/');
204204
}
205205

206206
/**
@@ -240,7 +240,7 @@ public function getCache()
240240
*/
241241
public function setCachePathPrefix($cachePathPrefix)
242242
{
243-
$this->cachePathPrefix = trim($cachePathPrefix, '/');
243+
$this->cachePathPrefix = trim((string) $cachePathPrefix, '/');
244244
}
245245

246246
/**

src/ServerFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public function getServer()
5757
$this->getApi()
5858
);
5959

60-
$server->setSourcePathPrefix($this->getSourcePathPrefix());
61-
$server->setCachePathPrefix($this->getCachePathPrefix());
60+
$server->setSourcePathPrefix($this->getSourcePathPrefix() ?: '');
61+
$server->setCachePathPrefix($this->getCachePathPrefix() ?: '');
6262
$server->setGroupCacheInFolders($this->getGroupCacheInFolders());
6363
$server->setCacheWithFileExtensions($this->getCacheWithFileExtensions());
6464
$server->setDefaults($this->getDefaults());
6565
$server->setPresets($this->getPresets());
66-
$server->setBaseUrl($this->getBaseUrl());
66+
$server->setBaseUrl($this->getBaseUrl() ?: '');
6767
$server->setResponseFactory($this->getResponseFactory());
6868

6969
if ($this->getTempDir()) {
@@ -259,7 +259,7 @@ public function getManipulators()
259259
new Flip(),
260260
new Blur(),
261261
new Pixelate(),
262-
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),
262+
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''),
263263
new Background(),
264264
new Border(),
265265
new Encode(),

0 commit comments

Comments
 (0)