-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRandomDateScheduleBasis.php
More file actions
57 lines (44 loc) · 1.25 KB
/
RandomDateScheduleBasis.php
File metadata and controls
57 lines (44 loc) · 1.25 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
<?php
namespace Skywarth\ChaoticSchedule\Enums;
use Skywarth\ChaoticSchedule\Exceptions\InvalidScheduleBasisProvided;
class RandomDateScheduleBasis
{
//TODO: Change to PHP 8.X Enum
public const WEEK=10;
public const MONTH=20;
public const YEAR=30;
private const DAYS_PER_PERIOD=[
self::WEEK=>7,
self::MONTH=>30,
self::YEAR=>365,
];
/**
* @throws InvalidScheduleBasisProvided
*/
public static function validate(int $basis):void{
if(!self::isValid($basis)){
throw new InvalidScheduleBasisProvided("Provided schedule basis is invalid, '$basis' given.");
}
}
public static function isValid(int $basis):bool{
return in_array($basis,self::getAll());
}
/**
* @return int[]
*/
public static function getAll():array{
return[
'WEEK'=>self::WEEK,
'MONTH'=>self::MONTH,
'YEAR'=>self::YEAR,
];
}
public static function getString(int $enumVal):string{
self::validate($enumVal);
return array_flip(self::getAll())[$enumVal];
}
public static function getDayCount(int $enumVal):int{
self::validate($enumVal);
return self::DAYS_PER_PERIOD[$enumVal];
}
}