Lines 100.00% 24 / 24
Functions and Methods 100.00% 6 / 6
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Apiquota 100.00% 24 / 24 100.00% 6 / 6 6 100.00% 1 / 1
 getQueryReadApiQuotaListByKey 100.00% 2 / 2 100.00% 1 / 1 1
 getQueryReadApiQuotaExpired 100.00% 8 / 8 100.00% 1 / 1 1
 getEntityMapping 100.00% 8 / 8 100.00% 1 / 1 1
 addConditionQuotaId 100.00% 2 / 2 100.00% 1 / 1 1
 addConditionApikey 100.00% 2 / 2 100.00% 1 / 1 1
 addConditionRoute 100.00% 2 / 2 100.00% 1 / 1 1
1<?php
2
3namespace BO\Zmsbackend\Apikey\Repository;
4
5/**
6 * @SuppressWarnings(Public)
7 */
8class Apiquota extends \BO\Zmsbackend\Query\Base implements \BO\Zmsbackend\Query\MappingInterface
9{
10    /**
11     * @var String TABLE mysql table reference
12     */
13    const string TABLE = 'apiquota';
14
15    public static function getQueryReadApiQuotaListByKey(): string
16    {
17        return '
18            SELECT * FROM `apiquota` WHERE `key` = :key
19        ';
20    }
21
22    public static function getQueryReadApiQuotaExpired(\DateTimeInterface $dateTime): string
23    {
24        $timeStamp = $dateTime->getTimestamp();
25        return '
26        SELECT * FROM apiquota WHERE ts <= (CASE period
27            WHEN "month" THEN UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(' . $timeStamp . '), INTERVAL -1 MONTH))
28            WHEN "week" THEN UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(' . $timeStamp . '), INTERVAL -1 WEEK))
29            WHEN "day" THEN UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(' . $timeStamp . '), INTERVAL -1 DAY))
30            WHEN "hour" THEN UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(' . $timeStamp . '), INTERVAL -1 HOUR))
31            WHEN "minute" THEN UNIX_TIMESTAMP(DATE_ADD(FROM_UNIXTIME(' . $timeStamp . '), INTERVAL -1 MINUTE))
32        END)
33        ';
34    }
35
36    /**
37     * @return string[]
38     *
39     */
40    #[\Override]
41    public function getEntityMapping()
42    {
43        $mapping = [
44            'key' => 'apiquota.key',
45            'route' => 'apiquota.route',
46            'period' => 'apiquota.period',
47            'requests' => 'apiquota.requests',
48            'ts' => 'apiquota.ts'
49        ];
50        return $mapping;
51    }
52
53    public function addConditionQuotaId($quotaId): static
54    {
55        $this->query->where('apiquota.quotaid', '=', $quotaId);
56        return $this;
57    }
58
59    public function addConditionApikey($apikey): static
60    {
61        $this->query->where('apiquota.key', '=', $apikey);
62        return $this;
63    }
64
65    public function addConditionRoute($route): static
66    {
67        $this->query->where('apiquota.route', '=', $route);
68        return $this;
69    }
70}