Skip to content

Commit 01ccac9

Browse files
Fix PHP 8.4 deprecations nullable objects (#865)
* Fix PHP 8.4 deprecations nullable objects * Fix deprecated github action * Increase required PHP version to 7.1 * Use specific ubuntu version * Add hint about supported PHP versions * Fix gmackig mock * Add getImage to mock in testWebpFormatIsAllowedAsAnimatedFormat * Remove mock from imagick testWebpFormatIsAllowedAsAnimatedFormat
1 parent 8908a6c commit 01ccac9

24 files changed

+44
-36
lines changed

.github/workflows/phpunit.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,28 @@ jobs:
7171
run: composer run test --ansi --no-interaction -- --exclude-group "${{ steps.inspect.outputs.excluded-groups }}"
7272
- name: Save tests temporary files
7373
if: always() && env.IMAGINE_TEST_KEEP_TEMPFILES == 'yes'
74-
uses: actions/upload-artifact@v2
74+
uses: actions/upload-artifact@v4
7575
with:
7676
name: windows-${{ matrix.php-version }}-${{ matrix.extensions }}
7777
path: tests/tmp/
7878
retention-days: 1
7979

8080
docker:
8181
name: PHP ${{ matrix.php-version }} - ${{ matrix.image-suffix }} (Docker)
82-
runs-on: ubuntu-latest
82+
runs-on: ubuntu-22.04
8383
strategy:
8484
fail-fast: false
8585
matrix:
8686
php-version:
87-
- "5.5"
88-
- "5.6"
89-
- "7.0"
9087
- "7.1"
9188
- "7.2"
9289
- "7.3"
9390
- "7.4"
9491
- "8.0"
9592
- "8.1"
93+
- "8.2"
94+
- "8.3"
95+
- "8.4"
9696
image-suffix:
9797
- gd-gmagick
9898
- gd-imagick
@@ -129,7 +129,7 @@ jobs:
129129
run: composer run test --ansi --no-interaction -- --exclude-group "${{ steps.inspect.outputs.excluded-groups }}"
130130
- name: Save tests temporary files
131131
if: always() && env.IMAGINE_TEST_KEEP_TEMPFILES == 'yes'
132-
uses: actions/upload-artifact@v2
132+
uses: actions/upload-artifact@v4
133133
with:
134134
name: docker-${{ matrix.php-version }}-${{ matrix.image-suffix }}
135135
path: tests/tmp/

.php-cs-fixer.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This document has been generated with
45
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.1.0|configurator
@@ -224,6 +225,8 @@
224225
'whitespace_after_comma_in_array' => true,
225226
// Write conditions in Yoda style (`true`), non-Yoda style (`['equal' => false, 'identical' => false, 'less_and_greater' => false]`) or ignore those conditions (`null`) based on configuration.
226227
'yoda_style' => array('always_move_variable' => false, 'equal' => false, 'identical' => false, 'less_and_greater' => false),
228+
// Make type definition of default null also nullable to avoid PHP 8.4 deprecations
229+
'nullable_type_declaration_for_default_null_value' => true,
227230
))
228231
->setFinder(
229232
PhpCsFixer\Finder::create()

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ libraries.
1111

1212
The Imagine library has the following requirements:
1313

14-
- PHP 5.5+
14+
- PHP 7.1+
15+
16+
Older version of the library support also older PHP Version:
17+
18+
- PHP 5.5 - 7.0 use version ^1.3
19+
- PHP 5.3 - 5.4 use version ^1.2
1520

1621
Depending on the chosen Image implementation, you may need one of the following PHP extensions:
1722

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=5.5"
20+
"php": ">=7.1"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.4 || ^9.3"

src/Filter/Advanced/Canvas.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Canvas implements FilterInterface
5252
* @param \Imagine\Image\PointInterface $placement
5353
* @param \Imagine\Image\Palette\Color\ColorInterface $background
5454
*/
55-
public function __construct(ImagineInterface $imagine, BoxInterface $size, PointInterface $placement = null, ColorInterface $background = null)
55+
public function __construct(ImagineInterface $imagine, BoxInterface $size, ?PointInterface $placement = null, ?ColorInterface $background = null)
5656
{
5757
$this->imagine = $imagine;
5858
$this->size = $size;

src/Filter/Basic/Rotate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Rotate implements FilterInterface
3636
* @param int $angle
3737
* @param \Imagine\Image\Palette\Color\ColorInterface $background
3838
*/
39-
public function __construct($angle, ColorInterface $background = null)
39+
public function __construct($angle, ?ColorInterface $background = null)
4040
{
4141
$this->angle = $angle;
4242
$this->background = $background;

src/Filter/Transformation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class Transformation implements FilterInterface, ManipulatorInterface
6060
*
6161
* @param \Imagine\Image\ImageInterface|null $imagine An ImagineInterface instance
6262
*/
63-
public function __construct(ImagineInterface $imagine = null)
63+
public function __construct(?ImagineInterface $imagine = null)
6464
{
6565
$this->imagine = $imagine;
6666
}
@@ -215,7 +215,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE
215215
*
216216
* @see \Imagine\Image\ManipulatorInterface::rotate()
217217
*/
218-
public function rotate($angle, ColorInterface $background = null)
218+
public function rotate($angle, ?ColorInterface $background = null)
219219
{
220220
return $this->add(new Rotate($angle, $background));
221221
}

src/Gd/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ final public function resize(BoxInterface $size, $filter = ImageInterface::FILTE
239239
*
240240
* @see \Imagine\Image\ManipulatorInterface::rotate()
241241
*/
242-
final public function rotate($angle, ColorInterface $background = null)
242+
final public function rotate($angle, ?ColorInterface $background = null)
243243
{
244244
if ($background === null) {
245245
$background = $this->palette->color('fff');

src/Gd/Imagine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function getDriverInfo($required = true)
5555
*
5656
* @see \Imagine\Image\ImagineInterface::create()
5757
*/
58-
public function create(BoxInterface $size, ColorInterface $color = null)
58+
public function create(BoxInterface $size, ?ColorInterface $color = null)
5959
{
6060
$width = $size->getWidth();
6161
$height = $size->getHeight();

src/Gmagick/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE
275275
*
276276
* @see \Imagine\Image\ManipulatorInterface::rotate()
277277
*/
278-
public function rotate($angle, ColorInterface $background = null)
278+
public function rotate($angle, ?ColorInterface $background = null)
279279
{
280280
try {
281281
if ($background === null) {

src/Gmagick/Imagine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function open($path)
8181
*
8282
* @see \Imagine\Image\ImagineInterface::create()
8383
*/
84-
public function create(BoxInterface $size, ColorInterface $color = null)
84+
public function create(BoxInterface $size, ?ColorInterface $color = null)
8585
{
8686
$width = $size->getWidth();
8787
$height = $size->getHeight();

src/Image/Box.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function increase($size)
9999
*
100100
* @see \Imagine\Image\BoxInterface::contains()
101101
*/
102-
public function contains(BoxInterface $box, PointInterface $start = null)
102+
public function contains(BoxInterface $box, ?PointInterface $start = null)
103103
{
104104
$start = $start ? $start : new Point(0, 0);
105105

src/Image/BoxInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function increase($size);
5757
*
5858
* @return bool
5959
*/
60-
public function contains(BoxInterface $box, PointInterface $start = null);
60+
public function contains(BoxInterface $box, ?PointInterface $start = null);
6161

6262
/**
6363
* Gets current box square, useful for getting total number of pixels in a

src/Image/ImagineInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface ImagineInterface extends ClassFactoryAwareInterface
3333
*
3434
* @return \Imagine\Image\ImageInterface
3535
*/
36-
public function create(BoxInterface $size, ColorInterface $color = null);
36+
public function create(BoxInterface $size, ?ColorInterface $color = null);
3737

3838
/**
3939
* Opens an existing image from $path.

src/Image/ManipulatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE
9494
*
9595
* @return $this
9696
*/
97-
public function rotate($angle, ColorInterface $background = null);
97+
public function rotate($angle, ?ColorInterface $background = null);
9898

9999
/**
100100
* Pastes an image into a parent image

src/Imagick/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDE
305305
*
306306
* @see \Imagine\Image\ManipulatorInterface::rotate()
307307
*/
308-
public function rotate($angle, ColorInterface $background = null)
308+
public function rotate($angle, ?ColorInterface $background = null)
309309
{
310310
if ($background === null) {
311311
$background = $this->palette->color('fff');

src/Imagick/Imagine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function open($path)
8888
*
8989
* @see \Imagine\Image\ImagineInterface::create()
9090
*/
91-
public function create(BoxInterface $size, ColorInterface $color = null)
91+
public function create(BoxInterface $size, ?ColorInterface $color = null)
9292
{
9393
$width = $size->getWidth();
9494
$height = $size->getHeight();

tests/tests/Constraint/IsImageEqual.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class IsImageEqual extends Constraint
5959
*
6060
* @throws \InvalidArgumentException
6161
*/
62-
public function __construct($expected, $delta = 0.1, ImagineInterface $imagine = null, $buckets = 4)
62+
public function __construct($expected, $delta = 0.1, ?ImagineInterface $imagine = null, $buckets = 4)
6363
{
6464
parent::__construct();
6565
$this->imagine = $imagine;

tests/tests/Filter/Advanced/CanvasTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CanvasTest extends FilterTestCase
3030
* @param PointInterface $placement
3131
* @param ColorInterface $background
3232
*/
33-
public function testShouldCanvasImageAndReturnResult(BoxInterface $size, PointInterface $placement = null, ColorInterface $background = null)
33+
public function testShouldCanvasImageAndReturnResult(BoxInterface $size, ?PointInterface $placement = null, ?ColorInterface $background = null)
3434
{
3535
$placement = $placement ?: new Point(0, 0);
3636
$image = $this->getImage();

tests/tests/Gmagick/LayersTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ public function testCount()
8686

8787
public function testWebpFormatIsAllowedAsAnimatedFormat()
8888
{
89-
$palette = new RGB();
89+
$this->checkGmagickMockable();
9090
$resource = $this->getMockBuilder('\Gmagick')->getMock();
9191

92+
$palette = new RGB();
93+
9294
$resource->expects($this->atLeastOnce())
9395
->method('getNumberImages')
9496
->will($this->returnValue(42));

tests/tests/Image/Fill/Gradient/HorizontalTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the Imagine package.
45
*

tests/tests/Image/Fill/Gradient/VerticalTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of the Imagine package.
45
*

tests/tests/Imagick/LayersTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@ public function testCount()
8585

8686
public function testWebpFormatIsAllowedAsAnimatedFormat()
8787
{
88-
$palette = new RGB();
89-
$resource = $this->getMockBuilder('\Imagick')->getMock();
90-
91-
$resource->expects($this->atLeastOnce())
92-
->method('getNumberImages')
93-
->will($this->returnValue(42));
94-
95-
$layers = new Layers(new Image($resource, $palette, new MetadataBag()), $palette, $resource);
96-
97-
$layers->animate('webp', 200, 0);
88+
$image = $this->getImagine()->open(IMAGINE_TEST_FIXTURESFOLDER . '/anima3.gif');
89+
$originalDelayInTicks = $image->layers()->get(0)->getImagick()->getImageDelay();
90+
$image->layers()->animate('webp', (int) (1000 + $originalDelayInTicks * 1000 / 20), 0);
91+
$this->assertSame('webp', $image->getImagick()->getFormat());
92+
$newDelayInTicks = $image->layers()->get(0)->getImagick()->getImageDelay();
93+
$this->assertNotEquals($originalDelayInTicks, $newDelayInTicks);
9894
}
9995

10096
public function testGetLayer()

tests/tests/ImagineTestCaseBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class ImagineTestCaseBase extends \PHPUnit\Framework\TestCase
3737
* @param \Imagine\Image\ImagineInterface|null $imagine
3838
* @param int $buckets
3939
*/
40-
public static function assertImageEquals($expected, $actual, $message = '', $delta = 0.1, ImagineInterface $imagine = null, $buckets = 4)
40+
public static function assertImageEquals($expected, $actual, $message = '', $delta = 0.1, ?ImagineInterface $imagine = null, $buckets = 4)
4141
{
4242
$constraint = new IsImageEqual($expected, $delta, $imagine, $buckets);
4343

0 commit comments

Comments
 (0)