Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Apikey | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
8 | |
100.00% |
1 / 1 |
| getDefaults | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| setApiClient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getApiClient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getQuotaPositionByRoute | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| addQuota | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| updateQuota | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | class Apikey extends Schema\Entity |
| 6 | { |
| 7 | public const string PRIMARY = 'key'; |
| 8 | |
| 9 | public static $schema = "apikey.json"; |
| 10 | |
| 11 | /** |
| 12 | * @return Apiclient[] |
| 13 | * |
| 14 | */ |
| 15 | #[\Override] |
| 16 | public function getDefaults() |
| 17 | { |
| 18 | return [ |
| 19 | 'apiclient' => new Apiclient(), |
| 20 | ]; |
| 21 | } |
| 22 | |
| 23 | public function setApiClient(Apiclient $apiClient): void |
| 24 | { |
| 25 | $this['apiclient'] = $apiClient; |
| 26 | } |
| 27 | |
| 28 | public function getApiClient(): Apiclient |
| 29 | { |
| 30 | return $this['apiclient']; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return false|int |
| 35 | * |
| 36 | */ |
| 37 | public function getQuotaPositionByRoute($route): int|false |
| 38 | { |
| 39 | return (isset($this->quota) && is_array($this->quota)) ? |
| 40 | array_search($route, array_column($this->quota, 'route')) |
| 41 | : false; |
| 42 | } |
| 43 | |
| 44 | public function addQuota($route, $period): static |
| 45 | { |
| 46 | $this->quota[] = [ |
| 47 | 'route' => $route, |
| 48 | 'period' => $period, |
| 49 | 'requests' => 1 |
| 50 | ]; |
| 51 | return $this; |
| 52 | } |
| 53 | |
| 54 | public function updateQuota($position): static |
| 55 | { |
| 56 | $this->quota[$position]['requests']++; |
| 57 | return $this; |
| 58 | } |
| 59 | } |