-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMeasurementError.php
More file actions
56 lines (42 loc) · 1.14 KB
/
MeasurementError.php
File metadata and controls
56 lines (42 loc) · 1.14 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
<?php
declare(strict_types=1);
namespace DragonCode\Benchmark\Services;
use function array_slice;
use function count;
class MeasurementError
{
protected float $percent = 0.1;
protected int $minCount = 10;
public function __construct(
protected Arr $arr = new Arr
) {}
public function filter(array $data): array
{
$count = $this->count($data);
return $this->disabled($count) ? $data : $this->partial($data, $count);
}
protected function partial(array $data, int $count): array
{
return array_slice($this->sort($data), $this->take($count), $this->offset($count));
}
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 count(array $values): int
{
return count($values);
}
protected function disabled(int $count): bool
{
return $count <= $this->minCount;
}
protected function sort(array $values): array
{
return $this->arr->sort($values);
}
}