Timezone: use false checks instead of file existing for static analysis

This commit is contained in:
Dylan K. Taylor 2020-04-15 10:55:26 +01:00
parent 83c40f4502
commit 5c9419b55c
2 changed files with 17 additions and 16 deletions

View File

@ -150,19 +150,16 @@ abstract class Timezone{
return self::parseOffset($offset);
case 'linux':
// Ubuntu / Debian.
if(file_exists('/etc/timezone')){
$data = file_get_contents('/etc/timezone');
if($data !== false){
return trim($data);
}
$data = @file_get_contents('/etc/timezone');
if($data !== false){
return trim($data);
}
// RHEL / CentOS
if(file_exists('/etc/sysconfig/clock')){
$data = parse_ini_file('/etc/sysconfig/clock');
if($data !== false and isset($data['ZONE']) and is_string($data['ZONE'])){
return trim($data['ZONE']);
}
$data = @parse_ini_file('/etc/sysconfig/clock');
if($data !== false and isset($data['ZONE']) and is_string($data['ZONE'])){
return trim($data['ZONE']);
}
//Portable method for incompatible linux distributions.
@ -175,12 +172,10 @@ abstract class Timezone{
return self::parseOffset($offset);
case 'mac':
if(is_link('/etc/localtime')){
$filename = readlink('/etc/localtime');
if(strpos($filename, '/usr/share/zoneinfo/') === 0){
$timezone = substr($filename, 20);
return trim($timezone);
}
$filename = @readlink('/etc/localtime');
if($filename !== false and strpos($filename, '/usr/share/zoneinfo/') === 0){
$timezone = substr($filename, 20);
return trim($timezone);
}
return false;

View File

@ -48,6 +48,12 @@ parameters:
count: 1
path: ../../../src/pocketmine/network/mcpe/protocol/DataPacket.php
-
#readlink() can return false but phpstan doesn't know this
message: "#^Strict comparison using \\!\\=\\= between string and false will always evaluate to true\\.$#"
count: 1
path: ../../../src/pocketmine/utils/Timezone.php
-
#phpstan doesn't understand that SplFixedArray may contain null
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with int and string will always evaluate to true\\.$#"