forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmark.php
More file actions
40 lines (31 loc) · 913 Bytes
/
Benchmark.php
File metadata and controls
40 lines (31 loc) · 913 Bytes
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
<?php
namespace App\Helpers;
use Illuminate\Support\Arr;
class Benchmark
{
/**
* Validate if the bitrate passes the benchmark.
*/
public static function bitrate(float|int $bytes, array $benchmark): bool
{
$value = Arr::get($benchmark, 'value');
$unit = Arr::get($benchmark, 'unit');
// Pass the benchmark if the value or unit is empty.
if (blank($value) || blank($unit)) {
return true;
}
return Bitrate::bytesToBits($bytes) >= Bitrate::normalizeToBits($value.$unit);
}
/**
* Validate if the ping passes the benchmark.
*/
public static function ping(float|int $ping, array $benchmark): bool
{
$value = Arr::get($benchmark, 'value');
// Pass the benchmark if the value is empty.
if (blank($value)) {
return true;
}
return $ping < $value;
}
}