Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix php8.1 deprecations #337

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Manipulators/Brightness.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $bri
* @property string|null $bri
*/
class Brightness extends BaseManipulator
{
@@ -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;
}

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

/**
* @property string $con
* @property string|null $con
*/
class Contrast extends BaseManipulator
{
@@ -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;
}

6 changes: 5 additions & 1 deletion src/Manipulators/Crop.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $crop
* @property string|null $crop
*/
class Crop extends BaseManipulator
{
@@ -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
4 changes: 2 additions & 2 deletions src/Manipulators/Gamma.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
use Intervention\Image\Image;

/**
* @property string $gam
* @property string|null $gam
*/
class Gamma extends BaseManipulator
{
@@ -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;
}

16 changes: 12 additions & 4 deletions src/Manipulators/Size.php
Original file line number Diff line number Diff line change
@@ -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
{
@@ -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;
}
@@ -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];
}
8 changes: 4 additions & 4 deletions src/ServerFactory.php
Original file line number Diff line number Diff line change
@@ -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()) {
@@ -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(),