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; |
||
11 | |||
12 | View Code Duplication | class MemoryLimit |
|
0 ignored issues
–
show
|
|||
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) { |
||
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 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.