Total Complexity | 7 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | trait HBuckets |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $bounds = []; |
||
17 | |||
18 | /** |
||
19 | * @param float ...$bounds |
||
20 | * @return static |
||
21 | */ |
||
22 | public function fixed(float ...$bounds) : self |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param float $start |
||
29 | * @param float $width |
||
30 | * @param int $count |
||
31 | * @return static |
||
32 | */ |
||
33 | public function linear(float $start, float $width, int $count) : self |
||
34 | { |
||
35 | $bounds = []; |
||
36 | |||
37 | for ($i = 0; $i < $count; $i ++) { |
||
38 | $bounds[] = $start; |
||
39 | $start += $width; |
||
40 | } |
||
41 | |||
42 | return $this->bucketing($bounds); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param float $start |
||
47 | * @param float $factor |
||
48 | * @param int $count |
||
49 | * @return static |
||
50 | */ |
||
51 | public function exponential(float $start, float $factor, int $count) : self |
||
52 | { |
||
53 | $bounds = []; |
||
54 | |||
55 | for ($i = 0; $i < $count; $i ++) { |
||
56 | $bounds[] = $start; |
||
57 | $start *= $factor; |
||
58 | } |
||
59 | |||
60 | return $this->bucketing($bounds); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param array $bounds |
||
65 | * @return static |
||
66 | */ |
||
67 | private function bucketing(array $bounds) : self |
||
76 | } |
||
77 | } |
||
78 |