-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMeasurementErrorService.php
More file actions
59 lines (45 loc) · 1.17 KB
/
MeasurementErrorService.php
File metadata and controls
59 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace DragonCode\Benchmark\Services;
use function array_slice;
use function asort;
use function count;
class MeasurementErrorService
{
protected float $percent = 0.1;
protected int $minCount = 10;
public function filter(array $data): array
{
$count = count($data);
if ($this->disabled($count)) {
return $data;
}
return $this->partial($data, $count);
}
protected function partial(array $data, int $count): array
{
return array_slice(
array : $this->sort($data),
offset : $this->offset($count),
length : $this->take($count),
preserve_keys: true
);
}
protected function offset(int $count): int
{
return (int) ($count * $this->percent);
}
protected function take(int $count): int
{
return $count - (2 * $this->offset($count));
}
protected function disabled(int $count): bool
{
return $count < $this->minCount;
}
protected function sort(array $values): array
{
asort($values, SORT_NUMERIC);
return $values;
}
}