1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 02:07:37 +01:00
psalm/src/functions.php
2020-02-24 21:19:16 -05:00

45 lines
907 B
PHP

<?php
namespace Psalm;
use Webmozart\PathUtil\Path;
use function preg_match;
use function ini_get;
use function strtoupper;
/**
* @param string $path
* @return bool
*
* @deprecated Use {@see Webmozart\PathUtil\Path::isAbsolute} instead
*/
function isAbsolutePath($path)
{
return Path::isAbsolute($path);
}
function getMemoryLimitInBytes(): int
{
$limit = ini_get('memory_limit');
// for unlimited = -1
if ($limit < 0) {
return -1;
}
if (preg_match('/^(\d+)(\D?)$/', $limit, $matches)) {
$limit = (int)$matches[1];
switch (strtoupper($matches[2] ?? '')) {
case 'G':
$limit *= 1024 * 1024 * 1024;
break;
case 'M':
$limit *= 1024 * 1024;
break;
case 'K':
$limit *= 1024;
break;
}
}
return (int)$limit;
}