Skip to content

Commit 70f7ca7

Browse files
committed
Fix PHPStan warnings
1 parent dbda40d commit 70f7ca7

19 files changed

+33
-35
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: 5 additions & 4 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
}

getid3/getid3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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) {

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.voc.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function Analyze() {
6969
$BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3));
7070
$ThisBlock = array();
7171

72-
/** @phpstan-ignore-next-line */
7372
getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1);
7473
switch ($BlockType) {
7574
case 0: // Terminator

0 commit comments

Comments
 (0)