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 PRIMARY = 'key'; |
| 8 | |
| 9 | public static $schema = "apikey.json"; |
| 10 | |
| 11 | #[\Override] |
| 12 | public function getDefaults() |
| 13 | { |
| 14 | return [ |
| 15 | 'apiclient' => new Apiclient(), |
| 16 | ]; |
| 17 | } |
| 18 | |
| 19 | public function setApiClient(Apiclient $apiClient) |
| 20 | { |
| 21 | $this['apiclient'] = $apiClient; |
| 22 | } |
| 23 | |
| 24 | public function getApiClient(): Apiclient |
| 25 | { |
| 26 | return $this['apiclient']; |
| 27 | } |
| 28 | |
| 29 | public function getQuotaPositionByRoute($route) |
| 30 | { |
| 31 | return (isset($this->quota) && is_array($this->quota)) ? |
| 32 | array_search($route, array_column($this->quota, 'route')) |
| 33 | : false; |
| 34 | } |
| 35 | |
| 36 | public function addQuota($route, $period) |
| 37 | { |
| 38 | $this->quota[] = [ |
| 39 | 'route' => $route, |
| 40 | 'period' => $period, |
| 41 | 'requests' => 1 |
| 42 | ]; |
| 43 | return $this; |
| 44 | } |
| 45 | |
| 46 | public function updateQuota($position) |
| 47 | { |
| 48 | $this->quota[$position]['requests']++; |
| 49 | return $this; |
| 50 | } |
| 51 | } |