Skip to content

Commit 4c32d6b

Browse files
committed
PHP 8.4 compatibility
1 parent aa19335 commit 4c32d6b

File tree

6 files changed

+50
-36
lines changed

6 files changed

+50
-36
lines changed

.github/workflows/tests.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ jobs:
1111
continue-on-error: ${{ !matrix.stable }}
1212
strategy:
1313
matrix:
14-
php-versions: ['7.3', '7.4', '8.0']
14+
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1515
stable: [true]
1616
coverage: [true]
1717
composer-flags: ['']
18-
include:
19-
- php-versions: '8.1'
20-
stable: false
21-
coverage: false
22-
composer-flags: '--ignore-platform-reqs'
18+
# include:
19+
# - php-versions: '8.1'
20+
# stable: false
21+
# coverage: false
22+
# composer-flags: '--ignore-platform-reqs'
2323

2424
steps:
2525
- uses: actions/checkout@v2

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
44
to [Semantic Versioning] (http://semver.org/). For change log format,
55
use [Keep a Changelog] (http://keepachangelog.com/).
66

7+
## [1.10.0] - 2025-03-14
8+
9+
### Changed
10+
11+
- PHP 8.4 compatibility
12+
713
## [1.9.0] - 2022-10-26
814

915
### Added

src/ImageHelper.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public static function gradientColor(string $color, string $colorToAdd, float $p
116116
public static function size(
117117
int $originalWidth,
118118
int $originalHeight,
119-
int $newWidth = null,
120-
int $newHeight = null,
119+
?int $newWidth = null,
120+
?int $newHeight = null,
121121
int $mode = self::SIZE_RATIO
122122
): array {
123123
// No size given, we keep original sizes!
@@ -217,7 +217,7 @@ public static function getImageSize($img): array
217217
* @return resource|GdImage
218218
* @throws InvalidArgumentException if not valid input resource or file name
219219
*/
220-
public static function resize($img, int $newWidth = null, int $newHeight = null, int $mode = self::SIZE_RATIO)
220+
public static function resize($img, ?int $newWidth = null, ?int $newHeight = null, int $mode = self::SIZE_RATIO)
221221
{
222222
if (!extension_loaded('gd')) {
223223
throw new RuntimeException('Need GD extension');
@@ -270,13 +270,13 @@ public static function resize($img, int $newWidth = null, int $newHeight = null,
270270
* Resize support of image.
271271
*
272272
* @param string|resource|GdImage $img File name or image resource
273-
* @param int $newWidth New width
274-
* @param int $newHeight New height
273+
* @param int|null $newWidth New width
274+
* @param int|null $newHeight New height
275275
*
276276
* @return resource|GdImage
277277
* @throws InvalidArgumentException if not valid input resource or file name
278278
*/
279-
public static function resizeSupport($img, int $newWidth = null, int $newHeight = null)
279+
public static function resizeSupport($img, ?int $newWidth = null, ?int $newHeight = null)
280280
{
281281
if (!extension_loaded('gd')) {
282282
throw new RuntimeException('Need GD extension');

src/StringHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public static function parseStr(string $str, bool $keepDots = true): array
299299
}
300300

301301
$result = reset($result);
302-
if (false === $result) {
302+
if (false === $result && null !== ($split[1] ?: null)) {
303303
$result = urldecode($split[1] ?? '');
304304
}
305305
$final = b_array_merge_recursive($final, [urldecode($split[0]) => $result]);

src/bootstrap.php

+30-23
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ function b_array_traverse_exists(&$mixed, string $path)
102102
*
103103
* @param iterable $mixed Source
104104
* @param string $path Path
105-
* @param mixed $default Default value
105+
* @param mixed|null $default Default value
106106
*
107107
* @return mixed|null
108108
* @throws InvalidArgumentException if first argument is not a traversable data
109109
*/
110-
function b_array_traverse_get(&$mixed, string $path, $default = null)
110+
function b_array_traverse_get(iterable &$mixed, string $path, $default = null)
111111
{
112112
return ArrayHelper::traverseGet($mixed, $path, $default);
113113
}
@@ -122,7 +122,7 @@ function b_array_traverse_get(&$mixed, string $path, $default = null)
122122
* @return bool
123123
* @throws InvalidArgumentException if first argument is not a traversable data
124124
*/
125-
function b_array_traverse_set(&$mixed, string $path, $value): bool
125+
function b_array_traverse_set(iterable &$mixed, string $path, $value): bool
126126
{
127127
return ArrayHelper::traverseSet($mixed, $path, $value);
128128
}
@@ -148,7 +148,7 @@ function b_array_simple(array $array, ?string $prefix = null): array
148148
/**
149149
* Get a human see file size.
150150
*
151-
* @param int|float $size
151+
* @param float|int $size
152152
* @param int $precision
153153
*
154154
* @return string
@@ -242,7 +242,7 @@ function b_ftruncate($resource, int $size, ?int $offset = null): bool
242242
* @return mixed
243243
* @throws ReflectionException
244244
*/
245-
function b_get_property_value($object, string $property, &$exists = null)
245+
function b_get_property_value(object $object, string $property, ?bool &$exists = null)
246246
{
247247
return ObjectHelper::getPropertyValue($object, $property, $exists);
248248
}
@@ -257,7 +257,7 @@ function b_get_property_value($object, string $property, &$exists = null)
257257
* @return bool
258258
* @throws ReflectionException
259259
*/
260-
function b_set_property_value($object, string $property, $value): bool
260+
function b_set_property_value(object$object, string $property, $value): bool
261261
{
262262
return ObjectHelper::setPropertyValue($object, $property, $value);
263263
}
@@ -267,14 +267,14 @@ function b_set_property_value($object, string $property, $value): bool
267267
/// STRING HELPER ///
268268
/////////////////////
269269

270-
define('B_STR_RANDOM_ALPHA', 1);
271-
define('B_STR_RANDOM_NUMERIC', 2);
272-
define('B_STR_RANDOM_SPECIAL_CHARACTERS', 4);
273-
define('B_STR_RANDOM_LOWER_CASE', 8);
274-
define('B_STR_RANDOM_NEED_ALL', 16);
275-
define('B_TRUNCATE_LEFT', 1);
276-
define('B_TRUNCATE_MIDDLE', 2);
277-
define('B_TRUNCATE_RIGHT', 3);
270+
const B_STR_RANDOM_ALPHA = 1;
271+
const B_STR_RANDOM_NUMERIC = 2;
272+
const B_STR_RANDOM_SPECIAL_CHARACTERS = 4;
273+
const B_STR_RANDOM_LOWER_CASE = 8;
274+
const B_STR_RANDOM_NEED_ALL = 16;
275+
const B_TRUNCATE_LEFT = 1;
276+
const B_TRUNCATE_MIDDLE = 2;
277+
const B_TRUNCATE_RIGHT = 3;
278278

279279

280280
/**
@@ -428,9 +428,9 @@ function b_spinal_case(string $str): string
428428
/// IMAGE HELPER ///
429429
/////////////////////
430430

431-
define('B_IMG_SIZE_RATIO', 1);
432-
define('B_IMG_SIZE_LARGER_EDGE', 2);
433-
define('B_IMG_RESIZE_COVER', 4);
431+
const B_IMG_SIZE_RATIO = 1;
432+
const B_IMG_SIZE_LARGER_EDGE = 2;
433+
const B_IMG_RESIZE_COVER = 4;
434434

435435
/**
436436
* Calculate a gradient destination color.
@@ -460,8 +460,8 @@ function b_gradient_color(string $color, string $colorToAdd, float $percentToAdd
460460
function b_img_size(
461461
int $originalWidth,
462462
int $originalHeight,
463-
int $newWidth = null,
464-
int $newHeight = null,
463+
?int $newWidth = null,
464+
?int $newHeight = null,
465465
int $mode = B_IMG_SIZE_RATIO
466466
): array {
467467
return ImageHelper::size($originalWidth, $originalHeight, $newWidth, $newHeight, $mode);
@@ -477,8 +477,12 @@ function b_img_size(
477477
*
478478
* @return resource|GdImage
479479
*/
480-
function b_img_resize($img, int $newWidth = null, int $newHeight = null, int $mode = B_IMG_SIZE_RATIO)
481-
{
480+
function b_img_resize(
481+
$img,
482+
?int $newWidth = null,
483+
?int $newHeight = null,
484+
int $mode = B_IMG_SIZE_RATIO
485+
) {
482486
return ImageHelper::resize($img, $newWidth, $newHeight, $mode);
483487
}
484488

@@ -491,7 +495,10 @@ function b_img_resize($img, int $newWidth = null, int $newHeight = null, int $mo
491495
*
492496
* @return resource|GdImage
493497
*/
494-
function b_img_support($img, int $newWidth = null, int $newHeight = null)
495-
{
498+
function b_img_support(
499+
$img,
500+
?int $newWidth = null,
501+
?int $newHeight = null
502+
) {
496503
return ImageHelper::resizeSupport($img, $newWidth, $newHeight);
497504
}

tests/StringHelperTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function testParseStr()
171171

172172
$this->assertEquals([], StringHelper::parseStr(''));
173173
$this->assertEquals([], StringHelper::parseStr('=foo'));
174+
$this->assertSame(['foo' => ''], StringHelper::parseStr('foo'));
174175
}
175176

176177
public function testParseStr_dontKeepDots()

0 commit comments

Comments
 (0)