Skip to content

Commit dcf5fac

Browse files
authored
feat: use ini_parse_quantity if available (#222)
1 parent f4e45fd commit dcf5fac

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Components/Health/Checker/HealthChecker/PhpChecker.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function checkMaxExecutionTime(HealthCollection $collection): void
8080

8181
private function checkMemoryLimit(HealthCollection $collection): void
8282
{
83-
$minMemoryLimit = $this->decodePhpSize('512m');
83+
$minMemoryLimit = $this->parseQuantity('512m');
8484
$currentMemoryLimit = \ini_get('memory_limit');
8585
if ($currentMemoryLimit === false) {
8686
$collection->add(
@@ -95,7 +95,7 @@ private function checkMemoryLimit(HealthCollection $collection): void
9595
return;
9696
}
9797

98-
$currentMemoryLimit = $this->decodePhpSize($currentMemoryLimit);
98+
$currentMemoryLimit = $this->parseQuantity($currentMemoryLimit);
9999
if ($currentMemoryLimit < $minMemoryLimit) {
100100
$collection->add(
101101
SettingsResult::error(
@@ -143,8 +143,13 @@ private function checkPcreJitActive(HealthCollection $collection): void
143143
$collection->add(SettingsResult::warning('pcre-jit', $snippet, 'not active', 'active'));
144144
}
145145

146-
private function decodePhpSize(string $val): float
146+
private function parseQuantity(string $val): float
147147
{
148+
//TODO: remove condition and own calculation when min php version is 8.2
149+
if (\function_exists('ini_parse_quantity')) {
150+
return (float) \ini_parse_quantity($val);
151+
}
152+
148153
$val = mb_strtolower(trim($val));
149154
$last = mb_substr($val, -1);
150155

0 commit comments

Comments
 (0)