<commit_before><?php

namespace Nexy\PayboxDirect\HttpClient;

use Nexy\PayboxDirect\Exception\PayboxException;
use Nexy\PayboxDirect\Paybox;
use Nexy\PayboxDirect\Response\ResponseInterface;

/**
 * @author <NAME> <<EMAIL>>
 *
 * @see http://www1.paybox.com/espace-integrateur-documentation/les-solutions-paybox-direct-et-paybox-direct-plus/
 */
abstract class AbstractHttpClient
{
    /**
     * @var int
     */
    protected $timeout;

    /**
     * @var int
     */
    protected $baseUrl = Paybox::API_URL_TEST;

    /**
     * @var string[]
     */
    private $baseParameters;

    /**
     * @var int
     */
    private $defaultDevise;

    /**
     * @var int
     */
    private $questionNumber;

    /**
     * Constructor.
     */
    final public function __construct()
    {
        $this->questionNumber = rand(0, time());
    }

    /**
     * @param array $options
     */
    final public function setOptions($options)
    {
        $this->timeout = $options['timeout'];
        $this->baseUrl = true === $options['production'] ? Paybox::API_URL_PRODUCTION : Paybox::API_URL_TEST;
        $this->baseParameters = [
            'VERSION' => $options['paybox_version'],
            'SITE' => $options['paybox_site'],
            'RANG' => $options['paybox_rank'],
            'IDENTIFIANT' => $options['paybox_identifier'],
            'CLE' => $options['paybox_key'],
        ];
        $this->defaultDevise = $options['paybox_default_currency'];
    }

    /**
     * Calls PayBox Direct platform with given operation type and parameters.
     *
     * @param int      $type          Request type
     * @param string[] $parameters    Request parameters
     * @param string   $responseClass
     *
     * @return ResponseInterface The response content
     *
     * @throws PayboxException
     */
    public function call($type, array $parameters, $responseClass)
    {
        if (!in_array(ResponseInterface::class, class_implements($responseClass))) {
            throw new \InvalidArgumentException('The response class must implement '.ResponseInterface::class.'.');
        }

        $bodyParams = array_merge($parameters, $this->baseParameters);
        $bodyParams['TYPE'] = $type;
        $bodyParams['NUMQUESTION'] = $this->questionNumber;
        $bodyParams['DATEQ'] = null !== $parameters['DATEQ'] ? $parameters['DATEQ'] : date('dmYHis');
        // Restore default_currency from parameters if given
        if (array_key_exists('DEVISE', $parameters)) {
            $bodyParams['DEVISE'] = null !== $parameters['DEVISE'] ? $parameters['DEVISE'] : $this->defaultDevise;
        }

        $response = $this->request($bodyParams);

        // Generate results array
        $results = [];
        foreach (explode('&', $response) as $element) {<commit_msg>Make `AbstractHttpClient::call` final (#37)<commit_after><?php

namespace Nexy\PayboxDirect\HttpClient;

use Nexy\PayboxDirect\Exception\PayboxException;
use Nexy\PayboxDirect\Paybox;
use Nexy\PayboxDirect\Response\ResponseInterface;

/**
 * @author <NAME> <<EMAIL>>
 *
 * @see http://www1.paybox.com/espace-integrateur-documentation/les-solutions-paybox-direct-et-paybox-direct-plus/
 */
abstract class AbstractHttpClient
{
    /**
     * @var int
     */
    protected $timeout;

    /**
     * @var int
     */
    protected $baseUrl = Paybox::API_URL_TEST;

    /**
     * @var string[]
     */
    private $baseParameters;

    /**
     * @var int
     */
    private $defaultDevise;

    /**
     * @var int
     */
    private $questionNumber;

    /**
     * Constructor.
     */
    final public function __construct()
    {
        $this->questionNumber = rand(0, time());
    }

    /**
     * @param array $options
     */
    final public function setOptions($options)
    {
        $this->timeout = $options['timeout'];
        $this->baseUrl = true === $options['production'] ? Paybox::API_URL_PRODUCTION : Paybox::API_URL_TEST;
        $this->baseParameters = [
            'VERSION' => $options['paybox_version'],
            'SITE' => $options['paybox_site'],
            'RANG' => $options['paybox_rank'],
            'IDENTIFIANT' => $options['paybox_identifier'],
            'CLE' => $options['paybox_key'],
        ];
        $this->defaultDevise = $options['paybox_default_currency'];
    }

    /**
     * Calls PayBox Direct platform with given operation type and parameters.
     *
     * @param int      $type          Request type
     * @param string[] $parameters    Request parameters
     * @param string   $responseClass
     *
     * @return ResponseInterface The response content
     *
     * @throws PayboxException
     */
    final public function call($type, array $parameters, $responseClass)
    {
        if (!in_array(ResponseInterface::class, class_implements($responseClass))) {
            throw new \InvalidArgumentException('The response class must implement '.ResponseInterface::class.'.');
        }

        $bodyParams = array_merge($parameters, $this->baseParameters);
        $bodyParams['TYPE'] = $type;
        $bodyParams['NUMQUESTION'] = $this->questionNumber;
        $bodyParams['DATEQ'] = null !== $parameters['DATEQ'] ? $parameters['DATEQ'] : date('dmYHis');
        // Restore default_currency from parameters if given
        if (array_key_exists('DEVISE', $parameters)) {
            $bodyParams['DEVISE'] = null !== $parameters['DEVISE'] ? $parameters['DEVISE'] : $this->defaultDevise;
        }

        $response = $this->request($bodyParams);

        // Generate results array
        $results = [];
        foreach (explode('&', $response) as $element) {
{'fraction_non_alphanumeric': 0.14720541117835528, 'fraction_numerical': 0.001067995728017088, 'mean_word_length': 2.6135048231511253, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6799539', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1599, 'n_words': 318}