Skip to content

Commit

Permalink
Merge pull request #350 from erikn69/pacth-1
Browse files Browse the repository at this point in the history
[1.x] Fix PHP 8.1 deprecations
  • Loading branch information
ADmad authored Apr 27, 2022
2 parents 753bc82 + 8a3449f commit 257e0c3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ jobs:
run: |
composer update --prefer-dist --no-interaction --no-ansi --no-progress
php vendor/bin/phpunit
tests-php-8-1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: PHPUnit
run: |
composer update --prefer-dist --no-interaction --no-ansi --no-progress
php vendor/bin/phpunit
4 changes: 2 additions & 2 deletions src/Manipulators/Brightness.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $bri
* @property string|null $bri
*/
class Brightness extends BaseManipulator
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public function run(Image $image)
*/
public function getBrightness()
{
if (!preg_match('/^-*[0-9]+$/', $this->bri)) {
if (null === $this->bri || !preg_match('/^-*[0-9]+$/', $this->bri)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Manipulators/Contrast.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $con
* @property string|null $con
*/
class Contrast extends BaseManipulator
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public function run(Image $image)
*/
public function getContrast()
{
if (!preg_match('/^-*[0-9]+$/', $this->con)) {
if (null === $this->con || !preg_match('/^-*[0-9]+$/', $this->con)) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Manipulators/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function run(Image $image)
*/
public function getCoordinates(Image $image)
{
if (null === $this->crop) {
return;
}

$coordinates = explode(',', $this->crop);

if (4 !== count($coordinates) or
Expand Down
4 changes: 2 additions & 2 deletions src/Manipulators/Gamma.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $gam
* @property string|null $gam
*/
class Gamma extends BaseManipulator
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public function run(Image $image)
*/
public function getGamma()
{
if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
if (null === $this->gam || !preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
return;
}

Expand Down
16 changes: 12 additions & 4 deletions src/Manipulators/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Intervention\Image\Image;

/**
* @property string $dpr
* @property string $fit
* @property string $h
* @property string $w
* @property string $dpr
* @property string|null $fit
* @property string $h
* @property string $w
*/
class Size extends BaseManipulator
{
Expand Down Expand Up @@ -117,6 +117,10 @@ public function getHeight()
*/
public function getFit()
{
if (null === $this->fit) {
return 'contain';
}

if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch'], true)) {
return $this->fit;
}
Expand Down Expand Up @@ -408,6 +412,10 @@ public function resolveCropOffset(Image $image, $width, $height)
*/
public function getCrop()
{
if (null === $this->fit) {
return [50, 50, 1.0];
}

$cropMethods = [
'crop-top-left' => [0, 0, 1.0],
'crop-top' => [50, 0, 1.0],
Expand Down
6 changes: 3 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function getSource()
*/
public function setSourcePathPrefix($sourcePathPrefix)
{
$this->sourcePathPrefix = trim($sourcePathPrefix, '/');
$this->sourcePathPrefix = trim((string) $sourcePathPrefix, '/');
}

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public function sourceFileExists($path)
*/
public function setBaseUrl($baseUrl)
{
$this->baseUrl = trim($baseUrl, '/');
$this->baseUrl = trim((string) $baseUrl, '/');
}

/**
Expand Down Expand Up @@ -240,7 +240,7 @@ public function getCache()
*/
public function setCachePathPrefix($cachePathPrefix)
{
$this->cachePathPrefix = trim($cachePathPrefix, '/');
$this->cachePathPrefix = trim((string) $cachePathPrefix, '/');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public function getServer()
$this->getApi()
);

$server->setSourcePathPrefix($this->getSourcePathPrefix());
$server->setCachePathPrefix($this->getCachePathPrefix());
$server->setSourcePathPrefix($this->getSourcePathPrefix() ?: '');
$server->setCachePathPrefix($this->getCachePathPrefix() ?: '');
$server->setGroupCacheInFolders($this->getGroupCacheInFolders());
$server->setCacheWithFileExtensions($this->getCacheWithFileExtensions());
$server->setDefaults($this->getDefaults());
$server->setPresets($this->getPresets());
$server->setBaseUrl($this->getBaseUrl());
$server->setBaseUrl($this->getBaseUrl() ?: '');
$server->setResponseFactory($this->getResponseFactory());

if ($this->getTempDir()) {
Expand Down Expand Up @@ -259,7 +259,7 @@ public function getManipulators()
new Flip(),
new Blur(),
new Pixelate(),
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''),
new Background(),
new Border(),
new Encode(),
Expand Down

0 comments on commit 257e0c3

Please sign in to comment.