HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/app/Library/RateLimit.php
<?php

namespace Acelle\Library;

use Exception;

class RateLimit
{
    protected $amount;
    protected $periodValue;
    protected $periodUnit;
    protected $description;

    public const UNLIMITED = -1;
    public const ZERO = 0;

    public function __construct(int $amount, int $periodValue, string $periodUnit, $description = null)
    {
        if (self::UNLIMITED == $amount || $amount < self::ZERO || !is_int($amount)) {
            throw new Exception('Invalid RATE LIMIT amount '.$amount);
        }

        $this->amount = $amount;
        $this->periodValue = $periodValue;
        $this->periodUnit = $periodUnit;
        $this->description = $description;
    }

    public function getAmount(): int
    {
        return $this->amount;
    }

    public function getPeriodValue(): int
    {
        return $this->periodValue;
    }

    public function getPeriodUnit(): string
    {
        return $this->periodUnit;
    }

    public function getDescription()
    {
        return $this->description;
    }

    public function getPeriod()
    {
        return sprintf("%s %s", $this->getPeriodValue(), $this->getPeriodUnit());
    }
}