Skip to content

Commit

Permalink
Merge pull request #337 from bastien-phi/fix_php8.1_deprecations
Browse files Browse the repository at this point in the history
Fix php8.1 deprecations
  • Loading branch information
ADmad authored Dec 9, 2021
2 parents 9af22da + dda39e1 commit 87a644a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
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
6 changes: 5 additions & 1 deletion src/Manipulators/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $crop
* @property string|null $crop
*/
class Crop extends BaseManipulator
{
Expand Down Expand Up @@ -45,6 +45,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 @@ -119,6 +119,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 @@ -424,6 +428,10 @@ public function getCrop()
'crop-bottom-right' => [100, 100, 1.0],
];

if (null === $this->fit) {
return [50, 50, 1.0];
}

if (array_key_exists($this->fit, $cropMethods)) {
return $cropMethods[$this->fit];
}
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 87a644a

Please sign in to comment.