-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.php
57 lines (48 loc) · 1002 Bytes
/
helpers.php
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
<?php
declare(strict_types=1);
use Carbon\Carbon;
use Faker\Generator;
function carbon(
int|string|null $year = 0,
?int $month = 1,
?int $day = 1,
?int $hour = 0,
?int $minute = 0,
?int $second = 0,
DateTimeZone|string|null $tz = null,
): ?Carbon {
return Carbon::create(...func_get_args()) ?: null;
}
function roman(int $number): string
{
$map = [
'M' => 1000,
'CM' => 900,
'D' => 500,
'CD' => 400,
'C' => 100,
'XC' => 90,
'L' => 50,
'XL' => 40,
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'I' => 1,
];
$returnValue = '';
while ($number > 0) {
foreach ($map as $roman => $int) {
if ($number >= $int) {
$number -= $int;
$returnValue .= $roman;
break;
}
}
}
return $returnValue;
}
function faker(): Generator
{
return app(Generator::class);
}