Completed
Pull Request — master (#243)
by Дмитрий
05:05
created

Size::humanToPlain()   D

Complexity

Conditions 9
Paths 8

Size

Total Lines 34
Code Lines 17

Duplication

Lines 33
Ratio 97.06 %
Metric Value
cc 9
eloc 17
nc 8
nop 1
dl 33
loc 34
rs 4.909
1
<?php
2
namespace PHPDaemon\Config\Entry;
3
4
use PHPDaemon\Config\Entry\Generic;
5
6
/**
7
 * Size config entry
8
 *
9
 * @package    Core
10
 * @subpackage Config
11
 *
12
 * @author     Vasily Zorin <[email protected]>
13
 */
14
class Size extends Generic
15
{
16
17
    /**
18
     * Converts human-readable value to plain
19
     * @param $value
20
     * @return int
21
     */
22 View Code Duplication
    public static function humanToPlain($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
23
    {
24
        $l = substr($value, -1);
25
26
        if ($l === 'b' || $l === 'B') {
27
            return ((int)substr($value, 0, -1));
28
        }
29
30
        if ($l === 'k') {
31
            return ((int)substr($value, 0, -1) * 1000);
32
        }
33
34
        if ($l === 'K') {
35
            return ((int)substr($value, 0, -1) * 1024);
36
        }
37
38
        if ($l === 'm') {
39
            return ((int)substr($value, 0, -1) * 1000 * 1000);
40
        }
41
42
        if ($l === 'M') {
43
            return ((int)substr($value, 0, -1) * 1024 * 1024);
44
        }
45
46
        if ($l === 'g') {
47
            return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000);
48
        }
49
50
        if ($l === 'G') {
51
            return ((int)substr($value, 0, -1) * 1024 * 1024 * 1024);
52
        }
53
54
        return (int)$value;
55
    }
56
}
57