These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of the ApiGen (http://apigen.org) |
||
5 | * |
||
6 | * For the full copyright and license information, please view |
||
7 | * the file LICENSE that was distributed with this source code. |
||
8 | */ |
||
9 | |||
10 | namespace ApiGen\Console\Environment; |
||
11 | |||
12 | View Code Duplication | class MemoryLimit |
|
13 | { |
||
14 | |||
15 | /** |
||
16 | * @param string $newMemoryLimit |
||
17 | */ |
||
18 | public function setMemoryLimitTo($newMemoryLimit) |
||
19 | { |
||
20 | if (function_exists('ini_set')) { |
||
21 | $memoryLimit = trim(ini_get('memory_limit')); |
||
22 | if ($memoryLimit !== -1 && $this->getMemoryInBytes($memoryLimit) < 512 * 1024 * 1024) { |
||
0 ignored issues
–
show
Unused Code
Bug
introduced
by
![]() |
|||
23 | @ini_set('memory_limit', $newMemoryLimit); |
||
24 | } |
||
25 | unset($memoryInBytes, $memoryLimit); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @param string $value |
||
32 | * @return int |
||
33 | */ |
||
34 | private function getMemoryInBytes($value) |
||
35 | { |
||
36 | $unit = strtolower(substr($value, -1, 1)); |
||
37 | $value = (int) $value; |
||
38 | if ($unit === 'g') { |
||
39 | return $value * 1024 * 1024 * 1024; |
||
40 | } |
||
41 | if ($unit === 'm') { |
||
42 | return $value * 1024 * 1024; |
||
43 | } |
||
44 | if ($unit === 'k') { |
||
45 | return $value * 1024; |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 |