1 | <?php namespace Arcanedev\Units\Measures; |
||
13 | class FileSize extends UnitMeasure implements FileSizeContract |
||
14 | { |
||
15 | /* ----------------------------------------------------------------- |
||
16 | | Traits |
||
17 | | ----------------------------------------------------------------- |
||
18 | */ |
||
19 | |||
20 | use Calculatable; |
||
21 | |||
22 | /* ----------------------------------------------------------------- |
||
23 | | Getters & Setters |
||
24 | | ----------------------------------------------------------------- |
||
25 | */ |
||
26 | |||
27 | /** |
||
28 | * Get the default names. |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | 63 | public function defaultNames() |
|
33 | { |
||
34 | 63 | return array_combine(static::units(), [ |
|
35 | 63 | 'yotta', |
|
36 | 'zetta', |
||
37 | 'exa', |
||
38 | 'peta', |
||
39 | 'tera', |
||
40 | 'gigabyte', |
||
41 | 'megabyte', |
||
42 | 'kilobyte', |
||
43 | 'byte', |
||
44 | ]); |
||
45 | } |
||
46 | |||
47 | /* ----------------------------------------------------------------- |
||
48 | | Constructor |
||
49 | | ----------------------------------------------------------------- |
||
50 | */ |
||
51 | |||
52 | /** |
||
53 | * Distance constructor. |
||
54 | * |
||
55 | * @param float|int $value |
||
56 | * @param string $unit |
||
57 | * @param array $options |
||
58 | */ |
||
59 | 66 | public function __construct($value = 0, $unit = self::B, array $options = []) |
|
63 | |||
64 | /* ----------------------------------------------------------------- |
||
65 | | Main Methods |
||
66 | | ----------------------------------------------------------------- |
||
67 | */ |
||
68 | |||
69 | /** |
||
70 | * Make a distance instance. |
||
71 | * |
||
72 | * @param float|int $value |
||
73 | * @param string $unit |
||
74 | * @param array $options |
||
75 | * |
||
76 | * @return \Arcanedev\Units\Contracts\Measures\FileSize|\Arcanedev\Units\Contracts\UnitMeasure |
||
77 | */ |
||
78 | 27 | public static function make($value = 0, $unit = self::B, array $options = []) |
|
82 | |||
83 | /* ----------------------------------------------------------------- |
||
84 | | Calculation Methods |
||
85 | | ----------------------------------------------------------------- |
||
86 | */ |
||
87 | |||
88 | /** |
||
89 | * Add the file size. |
||
90 | * |
||
91 | * @param float|int $value |
||
92 | * @param string $unit |
||
93 | * |
||
94 | * @return \Arcanedev\Units\Contracts\Measures\FileSize|\Arcanedev\Units\Contracts\UnitMeasure |
||
95 | */ |
||
96 | 6 | public function addSize($value, $unit = self::B) |
|
100 | |||
101 | /** |
||
102 | * Sub the file size. |
||
103 | * |
||
104 | * @param float|int $value |
||
105 | * @param string $unit |
||
106 | * |
||
107 | * @return \Arcanedev\Units\Contracts\Measures\FileSize|\Arcanedev\Units\Contracts\UnitMeasure |
||
108 | */ |
||
109 | 6 | public function subSize($value, $unit = self::B) |
|
113 | |||
114 | /* ----------------------------------------------------------------- |
||
115 | | Other Methods |
||
116 | | ----------------------------------------------------------------- |
||
117 | */ |
||
118 | |||
119 | /** |
||
120 | * Get all the distance ratios. |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | 9 | protected static function getRatios() |
|
143 | } |
||
144 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.