<commit_before><?php
/**
 * This file is part of the php-github package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GitHub\Adapter;

use GitHub\Adapter\Exception\InvalidAuthenticationSchemeException;
use GitHub\Adapter\Exception\MissingCredentialsException;
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;

/**
 * Guzzle-dependent GitHub API adapter.
 *
 * @package GitHub\Adapter
 * @author <NAME> <<EMAIL>>
 */
class GuzzleAdapter extends AdapterAbstract
{
    /**
     * Builds the adapter.
     *
     * When working against an instance of GitHub Enterprise, provide the base
     * URL as this constructor's only argument.
     *
     * @param string $baseUrl OPTIONAL The base URL
     */
    public function __construct($baseUrl = '')
    {
        if (!$baseUrl) {
            $baseUrl = 'https://api.github.com/';
        }
        $httpClient = new Client([
            'base_url' => [$baseUrl, ['version' => 'v3']],
            'defaults' => [
                'headers' => ['Accept' => 'application/vnd.github.v3+json'],
            ]
        ]);
        CacheSubscriber::attach($httpClient);
        $this->setHttpClient($httpClient);
    }

    /**
     * {@inheritdoc}
     */
    public function setAuthentication($username, $password, $authScheme)
    {
        if (is_null($username) || is_null($password)) {
            throw new MissingCredentialsException('Please provide both a valid username and password/token.');
        }
        if (!in_array($authScheme, [self::AUTH_OAUTH_TOKEN, self::AUTH_HTTP_PASSWORD])) {
            throw new InvalidAuthenticationSchemeException('Please provide a valid authentication scheme.');
        }
        $this->getHttpClient()->setDefaultOption('auth', [$username, $password, $authScheme]);
        return $this;
    }

    /**<commit_msg>Check for missing authScheme.<commit_after><?php
/**
 * This file is part of the php-github package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace GitHub\Adapter;

use GitHub\Adapter\Exception\InvalidAuthenticationSchemeException;
use GitHub\Adapter\Exception\MissingCredentialsException;
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;

/**
 * Guzzle-dependent GitHub API adapter.
 *
 * @package GitHub\Adapter
 * @author <NAME> <<EMAIL>>
 */
class GuzzleAdapter extends AdapterAbstract
{
    /**
     * Builds the adapter.
     *
     * When working against an instance of GitHub Enterprise, provide the base
     * URL as this constructor's only argument.
     *
     * @param string $baseUrl OPTIONAL The base URL
     */
    public function __construct($baseUrl = '')
    {
        if (!$baseUrl) {
            $baseUrl = 'https://api.github.com/';
        }
        $httpClient = new Client([
            'base_url' => [$baseUrl, ['version' => 'v3']],
            'defaults' => [
                'headers' => ['Accept' => 'application/vnd.github.v3+json'],
            ]
        ]);
        CacheSubscriber::attach($httpClient);
        $this->setHttpClient($httpClient);
    }

    /**
     * {@inheritdoc}
     */
    public function setAuthentication($username, $password, $authScheme)
    {
        if (is_null($username) || is_null($password) || is_null($authScheme)) {
            throw new MissingCredentialsException('Please provide both a valid username and password/token.');
        }

        if (!in_array($authScheme, [self::AUTH_OAUTH_TOKEN, self::AUTH_HTTP_PASSWORD])) {
            throw new InvalidAuthenticationSchemeException('Please provide a valid authentication scheme.');
        }
        $this->getHttpClient()->setDefaultOption('auth', [$username, $password, $authScheme]);
        return $this;
    }

    /**
{'fraction_non_alphanumeric': 0.12541763042919557, 'fraction_numerical': 0.0010280133641737343, 'mean_word_length': 2.8307086614173227, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '6327970', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1044, 'n_words': 274}