mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 12:27:51 +00:00
Utils: use type-safe checks to ensure file validity
this gives the same results while keeping phpstan happy.
This commit is contained in:
parent
917c744266
commit
372202b3dc
@ -179,7 +179,7 @@ class Utils{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$machine = php_uname("a");
|
$machine = php_uname("a");
|
||||||
$machine .= file_exists("/proc/cpuinfo") ? implode(preg_grep("/(model name|Processor|Serial)/", file("/proc/cpuinfo"))) : "";
|
$machine .= ($cpuinfo = @file("/proc/cpuinfo")) !== false ? implode(preg_grep("/(model name|Processor|Serial)/", $cpuinfo)) : "";
|
||||||
$machine .= sys_get_temp_dir();
|
$machine .= sys_get_temp_dir();
|
||||||
$machine .= $extra;
|
$machine .= $extra;
|
||||||
$os = Utils::getOS();
|
$os = Utils::getOS();
|
||||||
@ -321,14 +321,14 @@ class Utils{
|
|||||||
switch(Utils::getOS()){
|
switch(Utils::getOS()){
|
||||||
case "linux":
|
case "linux":
|
||||||
case "android":
|
case "android":
|
||||||
if(file_exists("/proc/cpuinfo")){
|
if(($cpuinfo = @file('/proc/cpuinfo')) !== false){
|
||||||
foreach(file("/proc/cpuinfo") as $l){
|
foreach($cpuinfo as $l){
|
||||||
if(preg_match('/^processor[ \t]*:[ \t]*[0-9]+$/m', $l) > 0){
|
if(preg_match('/^processor[ \t]*:[ \t]*[0-9]+$/m', $l) > 0){
|
||||||
++$processors;
|
++$processors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}elseif(is_readable("/sys/devices/system/cpu/present")){
|
}elseif(($cpuPresent = @file_get_contents("/sys/devices/system/cpu/present")) !== false){
|
||||||
if(preg_match("/^([0-9]+)\\-([0-9]+)$/", trim(file_get_contents("/sys/devices/system/cpu/present")), $matches) > 0){
|
if(preg_match("/^([0-9]+)\\-([0-9]+)$/", trim($cpuPresent), $matches) > 0){
|
||||||
$processors = (int) ($matches[2] - $matches[1]);
|
$processors = (int) ($matches[2] - $matches[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user