<commit_before><?php
namespace LeagueWrap;

use LeagueWrap\Api\Champion;
use LeagueWrap\Api\Summoner;
use LeagueWrap\Api\Game;
use LeagueWrap\Api\League;
use LeagueWrap\Api\Stats;
use LeagueWrap\Api\Team;

class Api {

	/**
	 * Default api url.
	 *
	 * @var string
	 */
	protected $url = 'https://prod.api.pvp.net/api/lol/';

	/**
	 * The region to be used. Defaults to 'na'.
	 *
	 * @var string
	 */
	protected $region = 'na';

	/**
	 * The client used to connect with the riot API.
	 *
	 * @var object
	 */
	protected $client;

	/**
	 * This is the api key, very important.
	 *
	 * @var string
	 */
	private $key;

	/**
	 * Initiat the default client and key.
	 *
	 * @param string $key
	 */
	public function __construct($key = null, ClientInterface $client = null)
	{
		if (is_null($key))
		{
			throw new Exception('We need a key... it\'s very important!');
		}

		if (is_null($client))
		{
			// set up the default client
			$client = new Client;
		}
		$this->client = $client;
		$this->client->baseUrl($this->url);

		// add the key
		$this->key = $key;
	}

	/**
	 * Change the url for the client.
	 *
	 * @param string $url
	 * @chainable
	 */
	public function resetUrl($url)
	{
		$this->client->baseUrl($url);
		return $this;
	}

	/**
	 * Set the region code to a valid string.
	 *
	 * @param string $region
	 * @chainable
	 */
	public function setRegion($region)
	{
		$this->region = $region;
		return $this;
	}

	/**
	 * Start a champion request.
	 *
	 * @return Champion
	 */
	public function champion()
	{
		$champion = new Champion($this->client);
		$champion->setKey($this->key)
		         ->setRegion($this->region);

		return $champion;
	}

	/**
	 * Start a summoner request. We need either the summoner name
	 * or id for most of the requests in this object.
	 *
	 * @return Summoner;
	 */
	public function summoner()
	{
		$summoner = new Summoner($this->client);
		$summoner->setKey($this->key)
		         ->setRegion($this->region);

		return $summoner;
	}

	/**
	 * Start a game request. We need the summoner id for all
	 * requests in this object.
	 *
	 * @return Game;
	 */
	public function game()
	{
		$game = new Game($this->client);
		$game->setKey($this->key)
		     ->setRegion($this->region);

		return $game;
	}

	/**
	 * Starts a league request. We need the summoner id for all
	 * requests in this object.
	 *
	 * @return League
	 */
	public function league()
	{
		$league = new League($this->client);
		$league->setKey($this->key)
		       ->setRegion($this->region);
		
		return $league;
	}

	/**
	 * Starts a stats request. We need the summoner id for all
	 * requests in this object.
	 *
	 * @return Stats
	 */
	public function stats()
	{
		$stats = new Stats($this->client);
		$stats->setKey($this->key)
		      ->setRegion($this->region);
		
		return $stats;
	}

	/**
	 * Starts a team request. We need the summoner id for all
	 * requests in this object.
	 *
	 * @return Team
	 */
	public function team()
	{
		$team = new Team($this->client);
		$team->setKey($this->key)
		     ->setRegion($this->region);
	    
	    return $team;
	}
}<commit_msg>Removed some duplicate code in the Api<commit_after><?php
namespace LeagueWrap;

use LeagueWrap\Api\AbstractApi;

class Api {

	/**
	 * Default api url.
	 *
	 * @var string
	 */
	protected $url = 'https://prod.api.pvp.net/api/lol/';

	/**
	 * The region to be used. Defaults to 'na'.
	 *
	 * @var string
	 */
	protected $region = 'na';

	/**
	 * The client used to connect with the riot API.
	 *
	 * @var object
	 */
	protected $client;

	/**
	 * Should we even try to cache any of the requests?
	 *
	 * @var bool
	 */
	protected $cache = false;

	/**
	 * How long, in seconds, should we remember a query's response.
	 *
	 * @var int
	 */
	protected $remember = null;

	/**
	 * This is the api key, very important.
	 *
	 * @var string
	 */
	private $key;

	/**
	 * Initiat the default client and key.
	 *
	 * @param string $key
	 */
	public function __construct($key = null, ClientInterface $client = null)
	{
		if (is_null($key))
		{
			throw new Exception('We need a key... it\'s very important!');
		}

		if (is_null($client))
		{
			// set up the default client
			$client = new Client;
		}
		$this->client = $client;
		$this->client->baseUrl($this->url);

		// add the key
		$this->key = $key;
	}

	/**
	 * This is the primary service locater if you utilize the api (which you should) to 
	 * load instance of the abstractApi. This is the method that is called when you attempt
	 * to invoke "Champion()", "League()", etc.
	 *
	 * @param string $method
	 * @param array $arguments
	 * @return AbstractApi
	 */
	public function __call($method, $arguments)
	{
		$className = 'LeagueWrap\\Api\\'.ucwords(strtolower($method));
		$api       = new $className($this->client);
		if ( ! $api instanceof AbstractApi)
		{
			// This is not an api class.
			throw new Exception('The api class "'.$className.'" was not found.');
		}

		$api->setKey($this->key)
		    ->setRegion($this->region);

		if ($this->cache)
		{
			$api->remember($this->remember);
		}

		return $api;
	}

	/**
	 * Change the url for the client.
	 *
	 * @param string $url
	 * @chainable
	 */
	public function resetUrl($url)
	{
		$this->client->baseUrl($url);
		return $this;
	}

	/**
	 * Set the region code to a valid string.
	 *
	 * @param string $region
	 * @chainable
	 */
	public function setRegion($region)
	{
		$this->region = $region;
		return $this;
	}

	/**
	 * Sets the amount of seconds we should remember the response for.
	 * Leave it empty (or null) if you want to use the default set for 
	 * each api request.
	 *
	 * @param int $seconds
	 * @chainable
	 */
	public function remember($seconds = null)
	{
		$this->cache    = true;
		$this->remember = $seconds;
		return $this;
	}
}
{'fraction_non_alphanumeric': 0.1508088363193599, 'fraction_numerical': 0.0, 'mean_word_length': 2.681177976952625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 2, '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': '4516720', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1880, 'n_words': 586}