Skip to content

Commit 505a30a

Browse files
committed
fixed PHP 8.5 compatibility
1 parent 0f92a44 commit 505a30a

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/Iterators/CachingIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CachingIterator extends \CachingIterator implements \Countable
3434
public function __construct(iterable|\stdClass $iterable)
3535
{
3636
$iterable = $iterable instanceof \stdClass
37-
? new \ArrayIterator($iterable)
37+
? new \ArrayIterator((array) $iterable)
3838
: Nette\Utils\Iterables::toIterator($iterable);
3939
parent::__construct($iterable, 0);
4040
}

src/Utils/Arrays.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public static function toObject(iterable $array, object $object): object
533533
*/
534534
public static function toKey(mixed $value): int|string
535535
{
536-
return key([$value => null]);
536+
return key(@[$value => null]);
537537
}
538538

539539

src/Utils/Image.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ public static function fromBlank(int $width, int $height, ImageColor|array|null
239239
*/
240240
public static function detectTypeFromFile(string $file, &$width = null, &$height = null): ?int
241241
{
242-
[$width, $height, $type] = @getimagesize($file); // @ - files smaller than 12 bytes causes read error
243-
return isset(self::Formats[$type]) ? $type : null;
242+
[$width, $height, $type] = Helpers::falseToNull(@getimagesize($file)); // @ - files smaller than 12 bytes causes read error
243+
return $type && isset(self::Formats[$type]) ? $type : null;
244244
}
245245

246246

@@ -250,8 +250,8 @@ public static function detectTypeFromFile(string $file, &$width = null, &$height
250250
*/
251251
public static function detectTypeFromString(string $s, &$width = null, &$height = null): ?int
252252
{
253-
[$width, $height, $type] = @getimagesizefromstring($s); // @ - strings smaller than 12 bytes causes read error
254-
return isset(self::Formats[$type]) ? $type : null;
253+
[$width, $height, $type] = Helpers::falseToNull(@getimagesizefromstring($s)); // @ - strings smaller than 12 bytes causes read error
254+
return $type && isset(self::Formats[$type]) ? $type : null;
255255
}
256256

257257

tests/Utils/ArrayHash.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test('recursive conversion transforms nested arrays into ArrayHash', function ()
117117
'j' => 'Jack',
118118
'children' => $list['children'],
119119
'c' => 'Jim',
120-
], iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($list), RecursiveIteratorIterator::SELF_FIRST)));
120+
], @iterator_to_array(new RecursiveIteratorIterator(new RecursiveArrayIterator($list), RecursiveIteratorIterator::SELF_FIRST))); // ArrayIterator($object) is deprecated since PHP 8.5
121121
});
122122

123123

tests/Utils/Arrays.associate().phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Assert::equal(
8181
22 => (object) [
8282
'John' => ['name' => 'John', 'age' => 22],
8383
],
84-
null => (object) [
84+
'' => (object) [
8585
'Mary' => ['name' => 'Mary', 'age' => null],
8686
],
8787
44 => (object) [
@@ -112,7 +112,7 @@ Assert::same(
112112
22 => ['name' => 'John', 'age' => 22],
113113
],
114114
'Mary' => [
115-
null => ['name' => 'Mary', 'age' => null],
115+
'' => ['name' => 'Mary', 'age' => null],
116116
],
117117
'Paul' => [
118118
44 => ['name' => 'Paul', 'age' => 44],
@@ -168,7 +168,7 @@ Assert::same(
168168
[22 => ['name' => 'John', 'age' => 22]],
169169
],
170170
'Mary' => [
171-
[null => ['name' => 'Mary', 'age' => null]],
171+
['' => ['name' => 'Mary', 'age' => null]],
172172
],
173173
'Paul' => [
174174
[44 => ['name' => 'Paul', 'age' => 44]],

tests/Utils/FileSystem.copy.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class RemoteStream /* extends \streamWrapper */
3333
{
3434
return false;
3535
}
36+
37+
38+
public function stream_eof()
39+
{
40+
return false;
41+
}
3642
}
3743

3844
stream_wrapper_register('remote', RemoteStream::class, STREAM_IS_URL);

0 commit comments

Comments
 (0)