Skip to content

Commit 646c1ab

Browse files
Merge pull request #197 from StudioMaX/fix-phpstan
Fixes found by PHPStan
2 parents f8c9309 + 1b836c5 commit 646c1ab

35 files changed

+143
-168
lines changed

.travis.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ matrix:
1818
- php: 7.2
1919
- php: 7.3
2020
env: PHPSTAN=1
21-
- php: 7.4snapshot
22-
allow_failures:
23-
- php: 7.4snapshot
21+
- php: 7.4
2422

2523
before_script:
2624
- travis_retry composer install --prefer-source --quiet --no-interaction
27-
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.11; fi
25+
- if [[ $PHPSTAN = 1 ]]; then composer require --dev phpstan/phpstan:^0.12; fi
2826

2927
script:
3028
- composer lint

getid3/extension.cache.dbm.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,14 @@ public function clear_cache() {
215215
/**
216216
* clear cache
217217
*
218-
* @param string $filename
219-
* @param int $filesize
220-
* @param string $original_filename
218+
* @param string $filename
219+
* @param int $filesize
220+
* @param string $original_filename
221+
* @param resource $fp
221222
*
222223
* @return mixed
223224
*/
224-
public function analyze($filename, $filesize=null, $original_filename='') {
225+
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
225226

226227
if (file_exists($filename)) {
227228

@@ -238,7 +239,7 @@ public function analyze($filename, $filesize=null, $original_filename='') {
238239
}
239240

240241
// Miss
241-
$result = parent::analyze($filename);
242+
$result = parent::analyze($filename, $filesize, $original_filename, $fp);
242243

243244
// Save result
244245
if (isset($key) && file_exists($filename)) {

getid3/extension.cache.mysql.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ public function clear_cache() {
159159
/**
160160
* analyze file
161161
*
162-
* @param string $filename
163-
* @param int $filesize
164-
* @param string $original_filename
162+
* @param string $filename
163+
* @param int $filesize
164+
* @param string $original_filename
165+
* @param resource $fp
165166
*
166167
* @return mixed
167168
*/
168-
public function analyze($filename, $filesize=null, $original_filename='') {
169+
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
169170

170171
$filetime = 0;
171172
if (file_exists($filename)) {
@@ -189,7 +190,7 @@ public function analyze($filename, $filesize=null, $original_filename='') {
189190
}
190191

191192
// Miss
192-
$analysis = parent::analyze($filename, $filesize, $original_filename);
193+
$analysis = parent::analyze($filename, $filesize, $original_filename, $fp);
193194

194195
// Save result
195196
if (file_exists($filename)) {

getid3/extension.cache.mysqli.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function __construct($host, $database, $username, $password, $table='geti
114114

115115
// Connect to database
116116
$this->mysqli = new mysqli($host, $username, $password);
117-
if (!$this->mysqli) {
118-
throw new Exception('mysqli_connect() failed - check permissions and spelling.');
117+
if ($this->mysqli->connect_error) {
118+
throw new Exception('Connect Error (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
119119
}
120120

121121
// Select database
@@ -192,13 +192,14 @@ public function migrate_db_structure() {
192192
/**
193193
* analyze file
194194
*
195-
* @param string $filename
196-
* @param int $filesize
197-
* @param string $original_filename
195+
* @param string $filename
196+
* @param int $filesize
197+
* @param string $original_filename
198+
* @param resource $fp
198199
*
199200
* @return mixed
200201
*/
201-
public function analyze($filename, $filesize=null, $original_filename='') {
202+
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
202203

203204
$filetime = 0;
204205
if (file_exists($filename)) {
@@ -220,7 +221,7 @@ public function analyze($filename, $filesize=null, $original_filename='') {
220221
}
221222

222223
// Miss
223-
$analysis = parent::analyze($filename, $filesize, $original_filename);
224+
$analysis = parent::analyze($filename, $filesize, $original_filename, $fp);
224225

225226
// Save result
226227
if (file_exists($filename)) {

getid3/extension.cache.sqlite3.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,14 @@ private function clear_cache() {
172172
/**
173173
* analyze file and cache them, if cached pull from the db
174174
*
175-
* @param string $filename
176-
* @param integer $filesize
177-
* @param string $original_filename
175+
* @param string $filename
176+
* @param integer $filesize
177+
* @param string $original_filename
178+
* @param resource $fp
178179
*
179180
* @return mixed|false
180181
*/
181-
public function analyze($filename, $filesize=null, $original_filename='') {
182+
public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
182183
if (!file_exists($filename)) {
183184
return false;
184185
}
@@ -201,7 +202,7 @@ public function analyze($filename, $filesize=null, $original_filename='') {
201202
return unserialize(base64_decode($result));
202203
}
203204
// if it hasn't been analyzed before, then do it now
204-
$analysis = parent::analyze($filename, $filesize, $original_filename);
205+
$analysis = parent::analyze($filename, $filesize, $original_filename, $fp);
205206
// Save result
206207
$sql = $this->getQuery('cache_file');
207208
$stmt = $db->prepare($sql);
@@ -262,25 +263,18 @@ public function getQuery($name)
262263
switch ($name) {
263264
case 'version_check':
264265
return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = '-1' AND filetime = '-1' AND analyzetime = '-1'";
265-
break;
266266
case 'delete_cache':
267267
return "DELETE FROM $this->table";
268-
break;
269268
case 'set_version':
270269
return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, -1, -1, -1, :val)";
271-
break;
272270
case 'get_id3_data':
273271
return "SELECT val FROM $this->table WHERE filename = :filename AND filesize = :filesize AND filetime = :filetime";
274-
break;
275272
case 'cache_file':
276273
return "INSERT INTO $this->table (filename, dirname, filesize, filetime, analyzetime, val) VALUES (:filename, :dirname, :filesize, :filetime, :atime, :val)";
277-
break;
278274
case 'make_table':
279275
return "CREATE TABLE IF NOT EXISTS $this->table (filename VARCHAR(255) DEFAULT '', dirname VARCHAR(255) DEFAULT '', filesize INT(11) DEFAULT '0', filetime INT(11) DEFAULT '0', analyzetime INT(11) DEFAULT '0', val text, PRIMARY KEY (filename, filesize, filetime))";
280-
break;
281276
case 'get_cached_dir':
282277
return "SELECT val FROM $this->table WHERE dirname = :dirname";
283-
break;
284278
default:
285279
return null;
286280
}

getid3/getid3.lib.php

+16-20
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
class getid3_lib
1616
{
1717
/**
18-
* @param string $string
19-
* @param bool $hex
20-
* @param bool $spaces
21-
* @param string $htmlencoding
18+
* @param string $string
19+
* @param bool $hex
20+
* @param bool $spaces
21+
* @param string|bool $htmlencoding
2222
*
2323
* @return string
2424
*/
@@ -216,7 +216,6 @@ public static function Float2String($floatvalue, $bits) {
216216

217217
default:
218218
return false;
219-
break;
220219
}
221220
if ($floatvalue >= 0) {
222221
$signbit = '0';
@@ -284,11 +283,9 @@ public static function BigEndian2Float($byteword) {
284283
$floatvalue *= -1;
285284
}
286285
return $floatvalue;
287-
break;
288286

289287
default:
290288
return false;
291-
break;
292289
}
293290
$exponentstring = substr($bitword, 1, $exponentbits);
294291
$fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
@@ -500,8 +497,8 @@ public static function LittleEndian2String($number, $minbytes=1, $synchsafe=fals
500497
}
501498

502499
/**
503-
* @param array $array1
504-
* @param array $array2
500+
* @param mixed $array1
501+
* @param mixed $array2
505502
*
506503
* @return array|false
507504
*/
@@ -523,8 +520,8 @@ public static function array_merge_clobber($array1, $array2) {
523520
}
524521

525522
/**
526-
* @param array $array1
527-
* @param array $array2
523+
* @param mixed $array1
524+
* @param mixed $array2
528525
*
529526
* @return array|false
530527
*/
@@ -544,8 +541,8 @@ public static function array_merge_noclobber($array1, $array2) {
544541
}
545542

546543
/**
547-
* @param array $array1
548-
* @param array $array2
544+
* @param mixed $array1
545+
* @param mixed $array2
549546
*
550547
* @return array|false|null
551548
*/
@@ -735,9 +732,9 @@ public static function XML2array($XMLstring) {
735732
}
736733

737734
/**
738-
* @param SimpleXMLElement|array $XMLobject
735+
* @param SimpleXMLElement|array|mixed $XMLobject
739736
*
740-
* @return array
737+
* @return mixed
741738
*/
742739
public static function SimpleXMLelement2array($XMLobject) {
743740
if (!is_object($XMLobject) && !is_array($XMLobject)) {
@@ -1496,12 +1493,11 @@ public static function GetDataImageSize($imgData, &$imageinfo=array()) {
14961493

14971494
// yes this is ugly, feel free to suggest a better way
14981495
if (include_once(dirname(__FILE__).'/getid3.php')) {
1499-
if ($getid3_temp = new getID3()) {
1500-
if ($getid3_temp_tempdir = $getid3_temp->tempdir) {
1501-
$tempdir = $getid3_temp_tempdir;
1502-
}
1503-
unset($getid3_temp, $getid3_temp_tempdir);
1496+
$getid3_temp = new getID3();
1497+
if ($getid3_temp_tempdir = $getid3_temp->tempdir) {
1498+
$tempdir = $getid3_temp_tempdir;
15041499
}
1500+
unset($getid3_temp, $getid3_temp_tempdir);
15051501
}
15061502
}
15071503
$GetDataImageSize = false;

getid3/getid3.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,16 @@ public function __construct() {
266266
}
267267

268268
// Check memory
269-
$this->memory_limit = ini_get('memory_limit');
270-
if (preg_match('#([0-9]+) ?M#i', $this->memory_limit, $matches)) {
269+
$memoryLimit = ini_get('memory_limit');
270+
if (preg_match('#([0-9]+) ?M#i', $memoryLimit, $matches)) {
271271
// could be stored as "16M" rather than 16777216 for example
272-
$this->memory_limit = $matches[1] * 1048576;
273-
} elseif (preg_match('#([0-9]+) ?G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
272+
$memoryLimit = $matches[1] * 1048576;
273+
} elseif (preg_match('#([0-9]+) ?G#i', $memoryLimit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
274274
// could be stored as "2G" rather than 2147483648 for example
275-
$this->memory_limit = $matches[1] * 1073741824;
275+
$memoryLimit = $matches[1] * 1073741824;
276276
}
277+
$this->memory_limit = $memoryLimit;
278+
277279
if ($this->memory_limit <= 0) {
278280
// memory limits probably disabled
279281
} elseif ($this->memory_limit <= 4194304) {
@@ -287,7 +289,7 @@ public function __construct() {
287289
$this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
288290
}
289291

290-
if (($mbstring_func_overload = ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) {
292+
if (($mbstring_func_overload = (int) ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) {
291293
// http://php.net/manual/en/mbstring.overload.php
292294
// "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions"
293295
// getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those.
@@ -400,8 +402,9 @@ public function setOption($optArray) {
400402
}
401403

402404
/**
403-
* @param string $filename
404-
* @param int $filesize
405+
* @param string $filename
406+
* @param int $filesize
407+
* @param resource $fp
405408
*
406409
* @return bool
407410
*
@@ -511,9 +514,10 @@ public function openfile($filename, $filesize=null, $fp=null) {
511514
/**
512515
* analyze file
513516
*
514-
* @param string $filename
515-
* @param int $filesize
516-
* @param string $original_filename
517+
* @param string $filename
518+
* @param int $filesize
519+
* @param string $original_filename
520+
* @param resource $fp
517521
*
518522
* @return array
519523
*/
@@ -1534,7 +1538,6 @@ public function getHashdata($algorithm) {
15341538

15351539
default:
15361540
return $this->error('bad algorithm "'.$algorithm.'" in getHashdata()');
1537-
break;
15381541
}
15391542

15401543
if (!empty($this->info['fileformat']) && !empty($this->info['dataformat']) && ($this->info['fileformat'] == 'ogg') && ($this->info['audio']['dataformat'] == 'vorbis')) {

getid3/module.audio-video.asf.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public function Analyze() {
363363
$thisfile_audio['codec'] = $this->TrimConvert($thisfile_asf_codeclistobject_codecentries_current['name']);
364364

365365
if (!isset($thisfile_audio['bitrate']) && strstr($AudioCodecBitrate, 'kbps')) {
366-
$thisfile_audio['bitrate'] = (int) (trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000);
366+
$thisfile_audio['bitrate'] = (int) trim(str_replace('kbps', '', $AudioCodecBitrate)) * 1000;
367367
}
368368
//if (!isset($thisfile_video['bitrate']) && isset($thisfile_audio['bitrate']) && isset($thisfile_asf['file_properties_object']['max_bitrate']) && ($thisfile_asf_codeclistobject['codec_entries_count'] > 1)) {
369369
if (empty($thisfile_video['bitrate']) && !empty($thisfile_audio['bitrate']) && !empty($info['bitrate'])) {
@@ -807,7 +807,7 @@ public function Analyze() {
807807

808808
case 'wm/track':
809809
if (empty($thisfile_asf_comments['track_number'])) {
810-
$thisfile_asf_comments['track_number'] = array(1 + $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
810+
$thisfile_asf_comments['track_number'] = array(1 + (int) $this->TrimConvert($thisfile_asf_extendedcontentdescriptionobject_contentdescriptor_current['value']));
811811
}
812812
break;
813813

getid3/module.audio-video.bink.php

-6
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,14 @@ public function Analyze() {
2929
switch ($fileTypeID) {
3030
case 'BIK':
3131
return $this->ParseBink();
32-
break;
3332

3433
case 'SMK':
3534
return $this->ParseSmacker();
36-
break;
3735

3836
default:
3937
$this->error('Expecting "BIK" or "SMK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($fileTypeID).'"');
4038
return false;
41-
break;
4239
}
43-
44-
return true;
45-
4640
}
4741

4842
/**

getid3/module.audio-video.flv.php

-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ public function readData() {
597597
// null
598598
case 6:
599599
return null;
600-
break;
601600

602601
// Mixed array
603602
case 8:

getid3/module.audio-video.mpeg.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public function Analyze() {
519519
* @param int $bits_to_read
520520
* @param bool $return_singlebit_as_boolean
521521
*
522-
* @return bool|float|int
522+
* @return bool|int
523523
*/
524524
private function readBitsFromStream(&$bitstream, &$bitstreamoffset, $bits_to_read, $return_singlebit_as_boolean=true) {
525525
$return = bindec(substr($bitstream, $bitstreamoffset, $bits_to_read));

getid3/module.audio-video.nsv.php

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function Analyze() {
5151
default:
5252
$this->error('Expecting "NSVs" or "NSVf" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($NSVheader).'"');
5353
return false;
54-
break;
5554
}
5655

5756
if (!isset($info['nsv']['NSVf'])) {

0 commit comments

Comments
 (0)