<commit_before><?php

/**
 * This file is part of Laravel Throttle by <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace GrahamCampbell\Throttle\Classes;

use Illuminate\Http\Request;
use Illuminate\Cache\CacheManager;

/**
 * This is the throttle class.
 *
 * @package    Laravel-Throttle
 * @author     <NAME>
 * @copyright  Copyright 2013-2014 <NAME>
 * @license    https://github.com/GrahamCampbell/Laravel-Throttle/blob/develop/LICENSE.md
 * @link       https://github.com/GrahamCampbell/Laravel-Throttle
 */
class Throttle
{
    /**
     * The cache instance.
     *
     * @var \Illuminate\Cache\CacheManager
     */
    protected $cache;

    /**
     * The throttler.
     *
     * @var string
     */
    protected $throttler;

    /**
     * Create a new instance.
     *
     * @param  \Illuminate\Cache\CacheManager  $cache
     * @param  string  $throttler
     * @return void
     */
    public function __construct(CacheManager $cache, $throttler)
    {
        $this->cache = $cache;
        $this->throttler = $throttler;
    }

    /**
     * Get the throttler.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @param  int  $limit
     * @param  int  $time
     * @return \GrahamCampbell\Throttle\Throttlers\ThrottlerInterface
     */
    public function get($data, $limit = 10, $time = 60)
    {
        $data = $this->parseData($data);
        $store = $this->getStore($data['ip']);
        $key = $this->getKey($data['route']);

        $throttler = $this->throttler;

        return new $throttler($store, $key, $limit, $time);
    }

    /**
     * Hit the the throttle.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @param  int  $limit
     * @param  int  $time
     * @return \GrahamCampbell\Throttle\Throttlers\ThrottlerInterface
     */
    public function hit($data, $limit = 10, $time = 60)
    {
        return $this->get($data, $limit, $time)->hit();
    }

    /**
     * Parse the data.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @return array
     */
    protected function parseData($data)
    {
        if ($data instanceof Request) {
            $parsed = array('ip' => $request->getClientIp(), 'route' => $request->path());
        } elseif (is_array($data)) {
            $parsed = array('ip' => $data['ip'], 'route' => $data['route']);
        } else {
            throw new \InvalidArgumentException('An array, or an instance of Illuminate\Http\Request was expected.');
        }

        return $parsed;
    }

    /**
     * Get the store.
     *
     * @param  string  $ip
     * @return \Illuminate\Cache\StoreInterface
     */
    protected function getStore($ip)
    {
        return $this->cache->tags('throttle', $ip);
    }

    /**
     * Get the key.
     *
     * @param  string  $path
     * @return string
     */
    protected function getKey($path)<commit_msg>Fixed derp<commit_after><?php

/**
 * This file is part of Laravel Throttle by <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace GrahamCampbell\Throttle\Classes;

use Illuminate\Http\Request;
use Illuminate\Cache\CacheManager;

/**
 * This is the throttle class.
 *
 * @package    Laravel-Throttle
 * @author     <NAME>
 * @copyright  Copyright 2013-2014 <NAME>
 * @license    https://github.com/GrahamCampbell/Laravel-Throttle/blob/develop/LICENSE.md
 * @link       https://github.com/GrahamCampbell/Laravel-Throttle
 */
class Throttle
{
    /**
     * The cache instance.
     *
     * @var \Illuminate\Cache\CacheManager
     */
    protected $cache;

    /**
     * The throttler.
     *
     * @var string
     */
    protected $throttler;

    /**
     * Create a new instance.
     *
     * @param  \Illuminate\Cache\CacheManager  $cache
     * @param  string  $throttler
     * @return void
     */
    public function __construct(CacheManager $cache, $throttler)
    {
        $this->cache = $cache;
        $this->throttler = $throttler;
    }

    /**
     * Get the throttler.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @param  int  $limit
     * @param  int  $time
     * @return \GrahamCampbell\Throttle\Throttlers\ThrottlerInterface
     */
    public function get($data, $limit = 10, $time = 60)
    {
        $data = $this->parseData($data);
        $store = $this->getStore($data['ip']);
        $key = $this->getKey($data['route']);

        $throttler = $this->throttler;

        return new $throttler($store, $key, $limit, $time);
    }

    /**
     * Hit the the throttle.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @param  int  $limit
     * @param  int  $time
     * @return \GrahamCampbell\Throttle\Throttlers\ThrottlerInterface
     */
    public function hit($data, $limit = 10, $time = 60)
    {
        return $this->get($data, $limit, $time)->hit();
    }

    /**
     * Parse the data.
     *
     * @param  array|\Illuminate\Http\Request  $data
     * @return array
     */
    protected function parseData($data)
    {
        if ($data instanceof Request) {
            $parsed = array('ip' => $data->getClientIp(), 'route' => $data->path());
        } elseif (is_array($data)) {
            $parsed = array('ip' => $data['ip'], 'route' => $data['route']);
        } else {
            throw new \InvalidArgumentException('An array, or an instance of Illuminate\Http\Request was expected.');
        }

        return $parsed;
    }

    /**
     * Get the store.
     *
     * @param  string  $ip
     * @return \Illuminate\Cache\StoreInterface
     */
    protected function getStore($ip)
    {
        return $this->cache->tags('throttle', $ip);
    }

    /**
     * Get the key.
     *
     * @param  string  $path
     * @return string
     */
    protected function getKey($path)
{'fraction_non_alphanumeric': 0.13239898613388998, 'fraction_numerical': 0.005367526464887431, 'mean_word_length': 2.291462217860648, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808748', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2085, 'n_words': 546}