<commit_before><?php

namespace Omnipay\GoCardlessV2;

use GoCardlessPro\Environment;
use Omnipay\Common\AbstractGateway as BaseAbstractGateway;
use Guzzle\Http\ClientInterface;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\RequestInterface;
use Omnipay\GoCardlessV2\Message\AbstractRequest;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use GoCardlessPro\Client as GoCardlessClient;

/**
 * GoCardless Gateway
 *
 * @method RequestInterface authorize(array $options = array())         (Optional method)
 *         Authorize an amount on the customers card
 * @method RequestInterface completeAuthorize(array $options = array()) (Optional method)
 *         Handle return from off-site gateways after authorization
 * @method RequestInterface capture(array $options = array())           (Optional method)
 *         Capture an amount you have previously authorized
 * @method RequestInterface completePurchase(array $options = array())  (Optional method)
 *         Handle return from off-site gateways after purchase
 * @method RequestInterface void(array $options = array())              (Optional method)
 *         Generally can only be called up to 24 hours after submitting a transaction
 * @method RequestInterface createCard(array $options = array())        (Optional method)
 *         The returned response object includes a cardReference, which can be used for future transactions
 * @method RequestInterface updateCard(array $options = array())        (Optional method)
 *         Update a stored card
 * @method RequestInterface deleteCard(array $options = array())        (Optional method)
 *         Delete a stored card
 */
abstract class AbstractGateway extends BaseAbstractGateway
{
    /**
     * @var GoCardlessClient
     */
    private $gocardless;

    /**
     * Create a new gateway instance
     *
     * @param ClientInterface $httpClient A Guzzle client to make API calls with
     * @param HttpRequest $httpRequest A Symfony HTTP request object
     * @param GoCardlessClient $gocardless The GoCardless Client
     */
    public function __construct(
        ClientInterface $httpClient = null,
        HttpRequest $httpRequest = null,
        GoCardlessClient $gocardless = null
    ) {
        $this->gocardless = $gocardless ?: new GoCardlessClient(
            [
                'access_token' => '',
                'environment' => Environment::SANDBOX, // default a blank to sandbox
            ]
        );

        parent::__construct($httpClient, $httpRequest);
    }

    public function initialize(array $parameters = [])
    {
        parent::initialize($parameters);
        if ($parameters && array_key_exists('access_token', $parameters)) {
            $this->gocardless = new GoCardlessClient(
                [
                    'access_token' => $parameters['access_token'],
                    'environment' => Environment::LIVE,
                ]
            );
        }
    }

    public function setTestMode($value)
    {
        if ($value && $this->getParameter('access_token')) {
            $this->gocardless = new GoCardlessClient(
                    [
                        'access_token' => $this->getParameter('access_token'),
                        'environment' => Environment::SANDBOX,
                    ]
                );
        }

        return parent::setTestMode($value);
    }

    public function setAccessToken($value)
    {
        return $this->setParameter('access_token', $value);
    }

    public function setSecret($value)
    {
        return $this->setParameter('secret', $value);
    }

    /**
     * {@inheritdoc}
     */
    protected function createRequest($class, array $parameters)
    {
        /**
         * @var AbstractRequest $obj
         */
        $obj = new $class($this->httpClient, $this->httpRequest, $this->gocardless);

        return $obj->initialize(array_replace($this->getParameters(), $parameters));
    }

    public function getName()
    {
        return 'GoCardlessV2';
    }

    public function getDefaultParameters()
    {
        return [];
    }

    /**
     * @param string $id
     *
     * @return Message\FindCustomerRequest|Message\AbstractRequest
     */<commit_msg>Set default parameters<commit_after><?php

namespace Omnipay\GoCardlessV2;

use GoCardlessPro\Environment;
use Omnipay\Common\AbstractGateway as BaseAbstractGateway;
use Guzzle\Http\ClientInterface;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\RequestInterface;
use Omnipay\GoCardlessV2\Message\AbstractRequest;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use GoCardlessPro\Client as GoCardlessClient;

/**
 * GoCardless Gateway
 *
 * @method RequestInterface authorize(array $options = array())         (Optional method)
 *         Authorize an amount on the customers card
 * @method RequestInterface completeAuthorize(array $options = array()) (Optional method)
 *         Handle return from off-site gateways after authorization
 * @method RequestInterface capture(array $options = array())           (Optional method)
 *         Capture an amount you have previously authorized
 * @method RequestInterface completePurchase(array $options = array())  (Optional method)
 *         Handle return from off-site gateways after purchase
 * @method RequestInterface void(array $options = array())              (Optional method)
 *         Generally can only be called up to 24 hours after submitting a transaction
 * @method RequestInterface createCard(array $options = array())        (Optional method)
 *         The returned response object includes a cardReference, which can be used for future transactions
 * @method RequestInterface updateCard(array $options = array())        (Optional method)
 *         Update a stored card
 * @method RequestInterface deleteCard(array $options = array())        (Optional method)
 *         Delete a stored card
 */
abstract class AbstractGateway extends BaseAbstractGateway
{
    /**
     * @var GoCardlessClient
     */
    private $gocardless;

    /**
     * Create a new gateway instance
     *
     * @param ClientInterface $httpClient A Guzzle client to make API calls with
     * @param HttpRequest $httpRequest A Symfony HTTP request object
     * @param GoCardlessClient $gocardless The GoCardless Client
     */
    public function __construct(
        ClientInterface $httpClient = null,
        HttpRequest $httpRequest = null,
        GoCardlessClient $gocardless = null
    ) {
        $this->gocardless = $gocardless ?: new GoCardlessClient(
            [
                'access_token' => '',
                'environment' => Environment::SANDBOX, // default a blank to sandbox
            ]
        );

        parent::__construct($httpClient, $httpRequest);
    }

    public function initialize(array $parameters = [])
    {
        parent::initialize($parameters);
        if ($parameters && array_key_exists('access_token', $parameters)) {
            $this->gocardless = new GoCardlessClient(
                [
                    'access_token' => $parameters['access_token'],
                    'environment' => Environment::LIVE,
                ]
            );
        }
    }

    public function setTestMode($value)
    {
        if ($value && $this->getParameter('access_token')) {
            $this->gocardless = new GoCardlessClient(
                    [
                        'access_token' => $this->getParameter('access_token'),
                        'environment' => Environment::SANDBOX,
                    ]
                );
        }

        return parent::setTestMode($value);
    }

    public function setAccessToken($value)
    {
        return $this->setParameter('access_token', $value);
    }

    public function setSecret($value)
    {
        return $this->setParameter('secret', $value);
    }

    /**
     * {@inheritdoc}
     */
    protected function createRequest($class, array $parameters)
    {
        /**
         * @var AbstractRequest $obj
         */
        $obj = new $class($this->httpClient, $this->httpRequest, $this->gocardless);

        return $obj->initialize(array_replace($this->getParameters(), $parameters));
    }

    public function getName()
    {
        return 'GoCardlessV2';
    }

    public function getDefaultParameters()
    {
        return [
            'accessToken' => '',
            'testMode' => false,
        ];
    }

    /**
     * @param string $id
     *
     * @return Message\FindCustomerRequest|Message\AbstractRequest
     */
{'fraction_non_alphanumeric': 0.10037261294829995, 'fraction_numerical': 0.0011644154634373545, 'mean_word_length': 2.4914634146341466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, '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': '5181696', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2136, 'n_words': 575}