Skip to content

Commit 4a586c4

Browse files
Merge pull request #470 from StudioMaX/php85-deprecations
Fix PHPStan warnings and PHP 8.5 deprecations
2 parents 8cb2923 + 70f7ca7 commit 4a586c4

22 files changed

+45
-47
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ jobs:
5151
- uses: "actions/checkout@v4"
5252
- uses: "shivammathur/setup-php@v2"
5353
with:
54-
php-version: "8.2"
55-
tools: "phpstan:1.12.3"
54+
php-version: "8.4"
55+
tools: "phpstan:2.1.22"
5656
coverage: "none"
5757
- uses: "ramsey/composer-install@v3"
5858
- name: "Run PHPStan"

getid3/extension.cache.dbm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
class getID3_cached_dbm extends getID3
7474
{
7575
/**
76-
* @var resource
76+
* @var null|resource|Dba\Connection
7777
*/
78-
private $dba;
78+
private $dba; // @phpstan-ignore-line
7979

8080
/**
81-
* @var resource|bool
81+
* @var resource|bool|null
8282
*/
8383
private $lock;
8484

getid3/getid3.lib.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public static function trunc($floatnumber) {
7373

7474
/**
7575
* @param int|null $variable
76-
* @param int $increment
76+
* @param-out int $variable
77+
* @param int $increment
7778
*
7879
* @return bool
7980
*/
@@ -115,7 +116,7 @@ public static function intValueSupported($num) {
115116
// check if integers are 64-bit
116117
static $hasINT64 = null;
117118
if ($hasINT64 === null) { // 10x faster than is_null()
118-
/** @var int|float|false $bigInt */
119+
/** @var int|float|object $bigInt */
119120
$bigInt = pow(2, 31);
120121
$hasINT64 = is_int($bigInt); // 32-bit int are limited to (2^31)-1
121122
if (!$hasINT64 && !defined('PHP_INT_MIN')) {
@@ -442,7 +443,7 @@ public static function BigEndian2String($number, $minbytes=1, $synchsafe=false,
442443
}
443444

444445
/**
445-
* @param int $number
446+
* @param int|string $number
446447
*
447448
* @return string
448449
*/
@@ -1741,7 +1742,7 @@ public static function EmbeddedLookup($key, $begin, $end, $file, $name) {
17411742
// METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
17421743
//$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
17431744
$explodedLine = explode("\t", $line, 2);
1744-
$ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
1745+
$ThisKey = $explodedLine[0];
17451746
$ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
17461747
$cache[$file][$name][$ThisKey] = trim($ThisValue);
17471748
}
@@ -1810,7 +1811,7 @@ public static function getFileSizeSyscall($path) {
18101811
$commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\'';
18111812
}
18121813
if (isset($commandline)) {
1813-
$output = trim(`$commandline`);
1814+
$output = trim(shell_exec($commandline));
18141815
if (ctype_digit($output)) {
18151816
$filesize = (float) $output;
18161817
}

getid3/getid3.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public function __construct() {
481481
if (strpos($value, ' ') !== false) {
482482
if (!empty($path_so_far)) {
483483
$commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
484-
$dir_listing = `$commandline`;
484+
$dir_listing = shell_exec($commandline);
485485
$lines = explode("\n", $dir_listing);
486486
foreach ($lines as $line) {
487487
$line = trim($line);
@@ -529,7 +529,7 @@ public function fread_buffer_size() {
529529
* @return bool
530530
*/
531531
public function setOption($optArray) {
532-
if (!is_array($optArray) || empty($optArray)) {
532+
if (empty($optArray)) {
533533
return false;
534534
}
535535
foreach ($optArray as $opt => $val) {
@@ -1821,7 +1821,7 @@ public function getHashdata($algorithm) {
18211821
if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {
18221822

18231823
$commandline = '"'.GETID3_HELPERAPPSDIR.'vorbiscomment.exe" -w -c "'.$empty.'" "'.$file.'" "'.$temp.'"';
1824-
$VorbisCommentError = `$commandline`;
1824+
$VorbisCommentError = shell_exec($commandline);
18251825

18261826
} else {
18271827

@@ -1832,7 +1832,7 @@ public function getHashdata($algorithm) {
18321832
} else {
18331833

18341834
$commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
1835-
$VorbisCommentError = `$commandline`;
1835+
$VorbisCommentError = shell_exec($commandline);
18361836

18371837
}
18381838

getid3/module.audio-video.asf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function Analyze() {
336336
// shortcut
337337
$thisfile_asf['codec_list_object'] = array();
338338
/** @var mixed[] $thisfile_asf_codeclistobject */
339-
$thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object'];
339+
$thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object']; // @phpstan-ignore-line
340340

341341
$thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset;
342342
$thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;

getid3/module.audio-video.real.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ public function ParseOldRAheader($OldRAheaderData, &$ParsedArray) {
492492
$ParsedArray['fourcc'] = $ParsedArray['fourcc3'];
493493

494494
}
495-
/** @var string[]|false[] $value */
496-
foreach ($ParsedArray['comments'] as $key => $value) {
495+
/** @var array<string|false> $value */
496+
foreach ($ParsedArray['comments'] as $key => $value) { // @phpstan-ignore-line
497497
if ($value[0] === false) {
498498
$ParsedArray['comments'][$key][0] = '';
499499
}

getid3/module.audio-video.riff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public function Analyze() {
473473
@list($key, $value) = explode(':', $line, 2);
474474
if (substr($value, 0, 3) == '[{"') {
475475
if ($decoded = @json_decode($value, true)) {
476-
if (!empty($decoded) && (count($decoded) == 1)) {
476+
if (count($decoded) === 1) {
477477
$value = $decoded[0];
478478
} else {
479479
$value = $decoded;
@@ -1375,7 +1375,7 @@ public function Analyze() {
13751375
$info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
13761376
}
13771377

1378-
} elseif ($thisfile_riff_audio !== null && $thisfile_riff_video === null) {
1378+
} elseif ($thisfile_riff_audio !== null && $thisfile_riff_video === null) { // @phpstan-ignore-line
13791379

13801380
if (!isset($thisfile_audio['bitrate'])) {
13811381
$thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);

getid3/module.audio.midi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function Analyze() {
8888
}
8989
}
9090

91-
if (!is_array($trackdataarray) || count($trackdataarray) === 0) {
91+
if (count($trackdataarray) === 0) {
9292
$this->error('Cannot find MIDI track information');
9393
unset($thisfile_midi);
9494
unset($info['fileformat']);

getid3/module.audio.mp3.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
716716
//$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
717717
$info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144;
718718
}
719-
$thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
719+
$thisfile_mpeg_audio['framelength'] = (int) floor($framelengthfloat);
720720
}
721721

722722
if ($thisfile_mpeg_audio['xing_flags']['toc']) {
@@ -1178,7 +1178,6 @@ public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsC
11781178

11791179
$nextframetestarray = array('error' => array(), 'warning' => array(), 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
11801180
if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) {
1181-
/** @phpstan-ignore-next-line */
11821181
getid3_lib::safe_inc($info['mp3_validity_check_bitrates'][$nextframetestarray['mpeg']['audio']['bitrate']]);
11831182
if ($ScanAsCBR) {
11841183
// force CBR mode, used for trying to pick out invalid audio streams with valid(?) VBR headers, or VBR streams with no VBR header
@@ -1190,7 +1189,7 @@ public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsC
11901189

11911190
// next frame is OK, get ready to check the one after that
11921191
if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) {
1193-
$nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength'];
1192+
$nextframetestoffset += (int) $nextframetestarray['mpeg']['audio']['framelength'];
11941193
} else {
11951194
$this->error('Frame at offset ('.$offset.') is has an invalid frame length.');
11961195
return false;

getid3/module.audio.shorten.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function Analyze() {
139139

140140
static $shorten_present;
141141
if (!isset($shorten_present)) {
142-
$shorten_present = file_exists('/usr/local/bin/shorten') || `which shorten`;
142+
$shorten_present = file_exists('/usr/local/bin/shorten') || shell_exec('which shorten');
143143
}
144144
if (!$shorten_present) {
145145
$this->error('shorten binary was not found in path or /usr/local/bin');
@@ -149,7 +149,7 @@ public function Analyze() {
149149

150150
}
151151

152-
$output = `$commandline`;
152+
$output = shell_exec($commandline);
153153

154154
if (!empty($output) && (substr($output, 12, 4) == 'fmt ')) {
155155

0 commit comments

Comments
 (0)