Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
- uses: "actions/checkout@v4"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "8.2"
tools: "phpstan:1.12.3"
php-version: "8.4"
tools: "phpstan:2.1.22"
coverage: "none"
- uses: "ramsey/composer-install@v3"
- name: "Run PHPStan"
Expand Down
6 changes: 3 additions & 3 deletions getid3/extension.cache.dbm.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
class getID3_cached_dbm extends getID3
{
/**
* @var resource
* @var null|resource|Dba\Connection
*/
private $dba;
private $dba; // @phpstan-ignore-line

/**
* @var resource|bool
* @var resource|bool|null
*/
private $lock;

Expand Down
11 changes: 6 additions & 5 deletions getid3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public static function trunc($floatnumber) {

/**
* @param int|null $variable
* @param int $increment
* @param-out int $variable
* @param int $increment
*
* @return bool
*/
Expand Down Expand Up @@ -115,7 +116,7 @@ public static function intValueSupported($num) {
// check if integers are 64-bit
static $hasINT64 = null;
if ($hasINT64 === null) { // 10x faster than is_null()
/** @var int|float|false $bigInt */
/** @var int|float|object $bigInt */
$bigInt = pow(2, 31);
$hasINT64 = is_int($bigInt); // 32-bit int are limited to (2^31)-1
if (!$hasINT64 && !defined('PHP_INT_MIN')) {
Expand Down Expand Up @@ -442,7 +443,7 @@ public static function BigEndian2String($number, $minbytes=1, $synchsafe=false,
}

/**
* @param int $number
* @param int|string $number
*
* @return string
*/
Expand Down Expand Up @@ -1741,7 +1742,7 @@ public static function EmbeddedLookup($key, $begin, $end, $file, $name) {
// METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
//$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
$explodedLine = explode("\t", $line, 2);
$ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
$ThisKey = $explodedLine[0];
$ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
$cache[$file][$name][$ThisKey] = trim($ThisValue);
}
Expand Down Expand Up @@ -1810,7 +1811,7 @@ public static function getFileSizeSyscall($path) {
$commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\'';
}
if (isset($commandline)) {
$output = trim(`$commandline`);
$output = trim(shell_exec($commandline));
if (ctype_digit($output)) {
$filesize = (float) $output;
}
Expand Down
8 changes: 4 additions & 4 deletions getid3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function __construct() {
if (strpos($value, ' ') !== false) {
if (!empty($path_so_far)) {
$commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
$dir_listing = `$commandline`;
$dir_listing = shell_exec($commandline);
$lines = explode("\n", $dir_listing);
foreach ($lines as $line) {
$line = trim($line);
Expand Down Expand Up @@ -529,7 +529,7 @@ public function fread_buffer_size() {
* @return bool
*/
public function setOption($optArray) {
if (!is_array($optArray) || empty($optArray)) {
if (empty($optArray)) {
return false;
}
foreach ($optArray as $opt => $val) {
Expand Down Expand Up @@ -1821,7 +1821,7 @@ public function getHashdata($algorithm) {
if (file_exists(GETID3_HELPERAPPSDIR.'vorbiscomment.exe')) {

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

} else {

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

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

}

Expand Down
2 changes: 1 addition & 1 deletion getid3/module.audio-video.asf.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function Analyze() {
// shortcut
$thisfile_asf['codec_list_object'] = array();
/** @var mixed[] $thisfile_asf_codeclistobject */
$thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object'];
$thisfile_asf_codeclistobject = &$thisfile_asf['codec_list_object']; // @phpstan-ignore-line

$thisfile_asf_codeclistobject['offset'] = $NextObjectOffset + $offset;
$thisfile_asf_codeclistobject['objectid'] = $NextObjectGUID;
Expand Down
4 changes: 2 additions & 2 deletions getid3/module.audio-video.real.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ public function ParseOldRAheader($OldRAheaderData, &$ParsedArray) {
$ParsedArray['fourcc'] = $ParsedArray['fourcc3'];

}
/** @var string[]|false[] $value */
foreach ($ParsedArray['comments'] as $key => $value) {
/** @var array<string|false> $value */
foreach ($ParsedArray['comments'] as $key => $value) { // @phpstan-ignore-line
if ($value[0] === false) {
$ParsedArray['comments'][$key][0] = '';
}
Expand Down
4 changes: 2 additions & 2 deletions getid3/module.audio-video.riff.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function Analyze() {
@list($key, $value) = explode(':', $line, 2);
if (substr($value, 0, 3) == '[{"') {
if ($decoded = @json_decode($value, true)) {
if (!empty($decoded) && (count($decoded) == 1)) {
if (count($decoded) === 1) {
$value = $decoded[0];
} else {
$value = $decoded;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ public function Analyze() {
$info['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
}

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

if (!isset($thisfile_audio['bitrate'])) {
$thisfile_audio['bitrate'] = ((($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']) * 8);
Expand Down
2 changes: 1 addition & 1 deletion getid3/module.audio.midi.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function Analyze() {
}
}

if (!is_array($trackdataarray) || count($trackdataarray) === 0) {
if (count($trackdataarray) === 0) {
$this->error('Cannot find MIDI track information');
unset($thisfile_midi);
unset($info['fileformat']);
Expand Down
5 changes: 2 additions & 3 deletions getid3/module.audio.mp3.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
//$info['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
$info['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144;
}
$thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
$thisfile_mpeg_audio['framelength'] = (int) floor($framelengthfloat);
}

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

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

// next frame is OK, get ready to check the one after that
if (isset($nextframetestarray['mpeg']['audio']['framelength']) && ($nextframetestarray['mpeg']['audio']['framelength'] > 0)) {
$nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength'];
$nextframetestoffset += (int) $nextframetestarray['mpeg']['audio']['framelength'];
} else {
$this->error('Frame at offset ('.$offset.') is has an invalid frame length.');
return false;
Expand Down
4 changes: 2 additions & 2 deletions getid3/module.audio.shorten.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function Analyze() {

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

}

$output = `$commandline`;
$output = shell_exec($commandline);

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

Expand Down
1 change: 0 additions & 1 deletion getid3/module.audio.voc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function Analyze() {
$BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 1, 3));
$ThisBlock = array();

/** @phpstan-ignore-next-line */
getid3_lib::safe_inc($thisfile_voc['blocktypes'][$BlockType], 1);
switch ($BlockType) {
case 0: // Terminator
Expand Down
2 changes: 1 addition & 1 deletion getid3/module.graphic.jpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function Analyze() {

if (isset($info['jpg']['exif']['GPS']['GPSDateStamp'])) {
$explodedGPSDateStamp = explode(':', $info['jpg']['exif']['GPS']['GPSDateStamp']);
$computed_time[5] = (isset($explodedGPSDateStamp[0]) ? $explodedGPSDateStamp[0] : '');
$computed_time[5] = $explodedGPSDateStamp[0];
$computed_time[3] = (isset($explodedGPSDateStamp[1]) ? $explodedGPSDateStamp[1] : '');
$computed_time[4] = (isset($explodedGPSDateStamp[2]) ? $explodedGPSDateStamp[2] : '');

Expand Down
2 changes: 1 addition & 1 deletion getid3/module.graphic.png.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function Analyze() {
break;

default:
$this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']); // @phpstan-ignore-line
$this->warning('Unhandled color_type in tRNS chunk: '.$thisfile_png['IHDR']['raw']['color_type']);
break;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion getid3/module.graphic.svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function Analyze() {
$keyvaluepair = trim($keyvaluepair);
if ($keyvaluepair) {
$keyvalueexploded = explode('=', $keyvaluepair);
$key = (isset($keyvalueexploded[0]) ? $keyvalueexploded[0] : '');
$key = $keyvalueexploded[0];
$value = (isset($keyvalueexploded[1]) ? $keyvalueexploded[1] : '');
$info['svg'][$section_to_fix]['sections'][$key] = trim($value, '"');
}
Expand Down
4 changes: 2 additions & 2 deletions getid3/module.misc.cue.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function parseCueSheet($file)
public function parseComment($line, $track_on)
{
$explodedline = explode(' ', $line, 3);
$comment_REM = (isset($explodedline[0]) ? $explodedline[0] : '');
$comment_REM = $explodedline[0];
$comment_type = (isset($explodedline[1]) ? $explodedline[1] : '');
$comment_data = (isset($explodedline[2]) ? $explodedline[2] : '');
if (($comment_REM == 'REM') && $comment_type) {
Expand Down Expand Up @@ -262,7 +262,7 @@ public function parseIndex($line, $track_on)

//extract the minutes, seconds, and frames
$explodedline = explode(':', $line);
$minutes = (isset($explodedline[0]) ? $explodedline[0] : '');
$minutes = $explodedline[0];
$seconds = (isset($explodedline[1]) ? $explodedline[1] : '');
$frames = (isset($explodedline[2]) ? $explodedline[2] : '');

Expand Down
2 changes: 1 addition & 1 deletion getid3/module.tag.id3v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function ParseID3v2Frame(&$parsedFrame) {
// Owner identifier <text string> $00
// Identifier <up to 64 bytes binary data>
$exploded = explode("\x00", $parsedFrame['data'], 2);
$parsedFrame['ownerid'] = (isset($exploded[0]) ? $exploded[0] : '');
$parsedFrame['ownerid'] = $exploded[0];
$parsedFrame['data'] = (isset($exploded[1]) ? $exploded[1] : '');

} elseif ((($id3v2_majorversion >= 3) && ($parsedFrame['frame_name'] == 'TXXX')) || // 4.2.2 TXXX User defined text information frame
Expand Down
6 changes: 3 additions & 3 deletions getid3/module.tag.lyrics3.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function getLyrics3Data($endoffset, $version, $length) {
foreach ($imagestrings as $key => $imagestring) {
if (strpos($imagestring, '||') !== false) {
$imagearray = explode('||', $imagestring);
$ParsedLyrics3['images'][$key]['filename'] = (isset($imagearray[0]) ? $imagearray[0] : '');
$ParsedLyrics3['images'][$key]['filename'] = $imagearray[0];
$ParsedLyrics3['images'][$key]['description'] = (isset($imagearray[1]) ? $imagearray[1] : '');
$ParsedLyrics3['images'][$key]['timestamp'] = $this->Lyrics3Timestamp2Seconds(isset($imagearray[2]) ? $imagearray[2] : '');
}
Expand Down Expand Up @@ -291,13 +291,13 @@ public function Lyrics3LyricsTimestampParse(&$Lyrics3data) {
$notimestamplyricsarray = array();
foreach ($lyricsarray as $key => $lyricline) {
$regs = array();
unset($thislinetimestamps);
$thislinetimestamps = array();
while (preg_match('#^(\\[[0-9]{2}:[0-9]{2}\\])#', $lyricline, $regs)) {
$thislinetimestamps[] = $this->Lyrics3Timestamp2Seconds($regs[0]);
$lyricline = str_replace($regs[0], '', $lyricline);
}
$notimestamplyricsarray[$key] = $lyricline;
if (isset($thislinetimestamps) && is_array($thislinetimestamps)) {
if (count($thislinetimestamps) > 0) {
sort($thislinetimestamps);
foreach ($thislinetimestamps as $timestampkey => $timestamp) {
if (isset($Lyrics3data['comments']['synchedlyrics'][$timestamp])) {
Expand Down
2 changes: 1 addition & 1 deletion getid3/write.apetag.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class getid3_write_apetag
public $filename;

/**
* @var array
* @var array|null
*/
public $tag_data;

Expand Down
8 changes: 4 additions & 4 deletions getid3/write.metaflac.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function WriteMetaFLAC() {
$commandline .= ' --import-picture-from='.escapeshellarg($picturecommand);
}
$commandline .= ' '.escapeshellarg($this->filename).' 2>&1';
$metaflacError = `$commandline`;
$metaflacError = shell_exec($commandline);

if (empty($metaflacError)) {
clearstatcache(true, $this->filename);
Expand All @@ -138,7 +138,7 @@ public function WriteMetaFLAC() {
$commandline .= ' --import-picture-from='.escapeshellarg($picturecommand);
}
$commandline .= ' '.escapeshellarg($this->filename).' 2>&1';
$metaflacError = `$commandline`;
$metaflacError = shell_exec($commandline);

}

Expand Down Expand Up @@ -177,7 +177,7 @@ public function DeleteMetaFLAC() {
$timestampbeforewriting = filemtime($this->filename);

$commandline = GETID3_HELPERAPPSDIR.'metaflac.exe --remove-all-tags "'.$this->filename.'" 2>&1';
$metaflacError = `$commandline`;
$metaflacError = shell_exec($commandline);

if (empty($metaflacError)) {
clearstatcache(true, $this->filename);
Expand All @@ -193,7 +193,7 @@ public function DeleteMetaFLAC() {

// It's simpler on *nix
$commandline = 'metaflac --remove-all-tags "'.$this->filename.'" 2>&1';
$metaflacError = `$commandline`;
$metaflacError = shell_exec($commandline);

}

Expand Down
8 changes: 4 additions & 4 deletions getid3/write.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public function WriteTags() {
return false;
}

if (!is_array($this->tagformats)) {
$this->errors[] = 'tagformats must be an array in getid3_writetags';
if (count($this->tagformats) === 0) {
$this->errors[] = 'tagformats is empty in getid3_writetags';
return false;
}
// prevent duplicate tag formats
Expand Down Expand Up @@ -285,8 +285,8 @@ public function WriteTags() {
}

// Validation of supplied data
if (!is_array($this->tag_data)) {
$this->errors[] = '$this->tag_data is not an array in WriteTags()';
if (count($this->tag_data) === 0) {
$this->errors[] = '$this->tag_data is empty in WriteTags()';
return false;
}
// convert supplied data array keys to upper case, if they're not already
Expand Down
4 changes: 2 additions & 2 deletions getid3/write.vorbiscomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function WriteVorbisComment() {
$timestampbeforewriting = filemtime($this->filename);

$commandline = GETID3_HELPERAPPSDIR.'vorbiscomment.exe -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
$VorbiscommentError = `$commandline`;
$VorbiscommentError = shell_exec($commandline);

if (empty($VorbiscommentError)) {
clearstatcache(true, $this->filename);
Expand All @@ -103,7 +103,7 @@ public function WriteVorbisComment() {
} else {

$commandline = 'vorbiscomment -w --raw -c "'.$tempcommentsfilename.'" "'.$this->filename.'" 2>&1';
$VorbiscommentError = `$commandline`;
$VorbiscommentError = shell_exec($commandline);

}

Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
level: 4
paths:
- getid3
excludes_analyse:
polluteScopeWithLoopInitialAssignments: true
dynamicConstantNames:
- GETID3_OS_ISWINDOWS
Expand Down