Transform the data into a new data instance.

@param array $data
@param int   $limit
@param int   $time

@throws \InvalidArgumentException

@return \GrahamCampbell\Throttle\Data
770162
public function transform($data, int $limit = 10, int $time = 60)
    {
        if (($ip = array_get($data, 'ip')) && ($route = array_get($data, 'route'))) {
            return new Data((string) $ip, (string) $route, (int) $limit, (int) $time);
        }

        throw new InvalidArgumentException('The data array does not provide the required ip and route information.');
    }
357496
public static function add($key, $data, $time = null)
    {
        if (is_callable($data)) {
            $content = $data();
        } else {
            $content = $data;
        }

        $meta['__bow_meta'] = ['expire_at' => $time == null ? '+' : $time];

        $meta['content'] = $content;

        return (bool) file_put_contents(
            static::makeHashFilename($key, true),
            serialize($meta)
        );
    }
550841
public static function createFromData(array $data)
    {
        if (!isset($data['name'])) {
            throw new DomainException(self::MSG_REQUIRED_NAME);
        }

        if (!isset($data['price'])) {
            throw new DomainException(self::MSG_REQUIRED_NAME);
        }

        if (!isset($data['currency'])) {
            throw new DomainException(self::MSG_REQUIRED_CURRENCY);
        }

        $rate = new self($data);

        return $rate;
    }
544904
public final function expiresAfter($time)
   {
       $this->timeToLive = $time instanceof DateInterval
                         ? (new DateTime())->add($time)->getTimestamp()
                         - time()
                         : (int) $time;
       return $this;
   }
929773
public function setMinValidity($time) {
        if (!is_int($time)) throw new IllegalTypeException('Illegal type of parameter $time: '.gettype($time));
        if ($time < 0)      throw new InvalidArgumentException('Invalid argument $time: '.$time);

        $this->minValidity = $time;

        return $this;
    }
1142231
public static function createFromKeyData(array $data): self
    {
        if (!isset($data['keys'])) {
            throw new InvalidArgumentException('Invalid data.');
        }
        if (!\is_array($data['keys'])) {
            throw new InvalidArgumentException('Invalid data.');
        }
        $jwkset = new self([]);
        foreach ($data['keys'] as $key) {
            $jwk = new JWK($key);
            if ($jwk->has('kid')) {
                $jwkset->keys[$jwk->get('kid')] = $jwk;
            } else {
                $jwkset->keys[] = $jwk;
            }
        }

        return $jwkset;
    }
1035062
public static function createFromData(array $data)
    {
        if (!isset($data['type'])) {
            throw new DomainException(self::MSG_REQUIRED_TYPE);
        }

        switch ($data['type']) {
            case self::TYPE_DISCOUNTS_PER_REDEMPTION:
                $restriction = new Restrictions\DiscountsPerRedemption($data);

                break;
            case self::TYPE_REDEMPTIONS_PER_CUSTOMER:
                $restriction = new Restrictions\RedemptionsPerCustomer($data);

                break;
            case self::TYPE_RESTRICT_TO_INVOICES:
                $restriction = new Restrictions\RestrictToInvoices($data);

                break;
            case self::TYPE_RESTRICT_TO_PLANS:
                $restriction = new Restrictions\RestrictToPlans($data);

                break;
            case self::TYPE_RESTRICT_TO_SUBSCRIPTIONS:
                $restriction = new Restrictions\RestrictToSubscriptions($data);

                break;
            case self::TYPE_TOTAL_REDEMPTIONS:
                $restriction = new Restrictions\TotalRedemptions($data);

                break;
            case self::TYPE_MINIMUM_ORDER_AMOUNT:
                $restriction = new Restrictions\MinimumOrderAmount($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::MSG_UNSUPPORTED_TYPE, implode(',', self::$supportedTypes))
                );
        }

        return $restriction;
    }
552260
public static function createFromData(array $data): self
    {
        if (!isset($data['method'])) {
            throw new DomainException(self::REQUIRED_METHOD);
        }

        switch ($data['method']) {
            case self::METHOD_ACCOUNT_WEIGHTS:
                $instruction = new AccountWeights($data);

                break;
            case self::METHOD_ACQUIRER_WEIGHTS:
                $instruction = new AcquirerWeights($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::UNEXPECTED_METHOD, implode(', ', self::methods()))
                );
        }

        return $instruction;
    }
308004
public static function factory(array $data = []): self
    {
        $type = $data['type'];
        // fix for php7 reserved name (scalar type hint)
        if ('number' === $type) {
            $type = 'numbr';
        }

        /** @var Node $class */
        $class = 'Gdbots\QueryParser\Node\\' . StringUtils::toCamelFromSnake($type);
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Node type [%s] does not exist.', $type));
        }

        return $class::fromArray($data);
    }
573376
public function Limit( $data )
	{
		Deprecation::getInstance()->setExceptionVersion( '0.9' )
			->message(  'use setLimit and setOffset instead' );
		if( !is_array( $data ) )
			throw new InvalidArgumentException( 'Limit must be given as List of Offset and Row Limit.' );
		$offset	= 0;
		$rows	= 10;
		if( isset( $data[0] ) && (int) $data[0] && $data[0] == abs( $data[0] ) )
			$offset	= (int) $data[0];
		if( isset( $data[1] ) && (int) $data[1] && $data[1] == abs( $data[1] ) )
			$rows	= (int) $data[1];
		$this->builder->setLimit( $rows );
		$this->builder->setOffset( $offset );
		return array();
	}
307328
public static function createFromData(array $data)
    {
        if (!isset($data['method'])) {
            throw new DomainException(self::MSG_REQUIRED_METHOD);
        }

        switch ($data['method']) {
            case PaymentMethod::METHOD_ACH:
                $paymentInstrument = new AchInstrument($data);

                break;
            case PaymentMethod::METHOD_CASH:
                $paymentInstrument = new CashInstrument($data);

                break;
            case PaymentMethod::METHOD_PAYMENT_CARD:
                $paymentInstrument = new PaymentCardInstrument($data);

                break;
            case PaymentMethod::METHOD_PAYPAL:
                $paymentInstrument = new PayPalInstrument($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::MSG_UNSUPPORTED_METHOD, implode(',', self::$supportMethods))
                );
        }

        return $paymentInstrument;
    }
1021695
public function setLimit($limit)
    {
        if (!is_scalar($limit)) {
            $this->limit = self::DEFAULT_LIMIT;

            return $this;
        } else {
            $limit = (int)$limit;
        }

        if ($limit > self::MAX_LIMIT) {
            $this->limit = self::MAX_LIMIT;
        } elseif ($limit < 1) {
            $this->limit = self::DEFAULT_LIMIT;
        } else {
            $this->limit = $limit;
        }

        return $this;
    }
1084243
public function limit($limit)
    {
        if (null !== $limit) {
            if (!is_numeric($limit) || $limit != (int) $limit) {
                throw new \InvalidArgumentException('The limit is not valid.');
            }
            $limit = (int) $limit;
        }

        $this->limit = $limit;

        return $this;
    }
1197364
public static function createFromData(array $data)
    {
        if (!isset($data['method'])) {
            throw new DomainException(self::REQUIRED_METHOD);
        }

        if (!in_array($data['method'], self::$availableMethods, true)) {
            throw new DomainException(
                sprintf(self::UNSUPPORTED_METHOD, implode(',', self::$availableMethods))
            );
        }

        return parent::createFromData($data);
    }
307014
public function setData(array $data)
    {
        $this->data = $this->parseData($data);

        $this->setRules($this->initialRules);

        return $this;
    }
149118
function handleRatelimit(?int $limit, ?int $remaining, ?float $resetTime) {
        return $this->get()->then(function ($data) use ($limit, $remaining, $resetTime) {
            if($limit === null && $remaining === null && $resetTime === null) {
                $limit = $data['limit'];
                $remaining = $data['remaining'] + 1; // there is no ratelimit...
                $resetTime = $data['resetTime'];
            } else {
                $limit = $limit ?? $data['limit'];
                $remaining = $remaining ?? $data['remaining'];
                $resetTime = $resetTime ?? $data['resetTime'];
            }
            
            if($remaining === 0 && $resetTime > \microtime(true)) {
                $this->api->client->emit('debug', 'Endpoint "'.$this->endpoint.'" ratelimit encountered, continueing in '.($resetTime - \microtime(true)).' seconds');
            }
            
            return $this->set(array('limit' => $limit, 'remaining' => $remaining, 'resetTime' => $resetTime));
        });
    }
674311
public function setData(array $data)
    {
        $reservedDataKeys = array(
            'from',
            'notification',
            'to',
            'registration_ids',
            'collapse_key',
            'priority',
            'restricted_package_name',
            'content_available',
            'delay_while_idle',
            'dry_run',
            'time_to_live',
            'data',
        );

        foreach ($data as $key => $value) {

            if (!is_string($key)) {
                throw new \InvalidArgumentException('Data keys must be of type string in order to convert data in a valid JSON Object.');
            }

            if (in_array($key, $reservedDataKeys)
                || strpos($key, 'google') === 0
                || strpos($key, 'gcm') === 0
            ) {
                throw new \InvalidArgumentException(sprintf(
                    'The key "%s" is reserved or not recommended. Do not use it as data key.',
                    $key
                ));
            }

        }

        $this->data = $data;

        return $this;
    }