1 | <?php |
||
19 | abstract class Byte extends VOFloat implements VOStringable |
||
|
|||
20 | { |
||
21 | use VOStringTrait; |
||
22 | |||
23 | const UNITS = [ |
||
24 | [ 'Byte' => 'Byte' ], |
||
25 | [ 'KB' => 'Kilobyte' ], |
||
26 | [ 'MB' => 'Megabyte' ], |
||
27 | [ 'GB' => 'Gigabyte' ], |
||
28 | [ 'TB' => 'Terabyte' ], |
||
29 | [ 'PB' => 'Pecabyte' ], |
||
30 | [ 'EB' => 'Exabyte' ], |
||
31 | [ 'ZB' => 'Zettabyte' ], |
||
32 | [ 'YB' => 'Yottabyte' ] |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @var integer $power |
||
37 | */ |
||
38 | protected static $power; |
||
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | 3 | public function __toString() |
|
47 | |||
48 | /** |
||
49 | * @param string $string |
||
50 | * @return static |
||
51 | */ |
||
52 | 2 | public static function fromString($string) |
|
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | 3 | public function toString() |
|
72 | |||
73 | /** |
||
74 | * @param null $power |
||
75 | * @return string |
||
76 | */ |
||
77 | 4 | public function getUnit($power = null) |
|
78 | { |
||
79 | 4 | $power = $power ?: $this->getPower(); |
|
80 | 4 | $unit = self::UNITS[ (int) floor($this->base()) ]; |
|
81 | 4 | return Word::fromString(reset($unit))->getPluralised($power); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param int $precision |
||
86 | * @return float |
||
87 | */ |
||
88 | 4 | public function getPower($precision = 2) |
|
92 | |||
93 | /** |
||
94 | * @return float |
||
95 | */ |
||
96 | 4 | private function base() |
|
100 | |||
101 | /** |
||
102 | * @return mixed |
||
103 | */ |
||
104 | 2 | private static function getUnitKeyList() |
|
108 | } |
||
109 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.