<commit_before><?php
namespace Bpost\BpostApiClient;

use Bpost\BpostApiClient\Exception\ApiResponseException\BpostCurlException;
use Bpost\BpostApiClient\Exception\ApiResponseException\BpostInvalidXmlResponseException;
use Bpost\BpostApiClient\Exception\ApiResponseException\BpostTaxipostLocatorException;
use Bpost\BpostApiClient\Geo6\Poi;

/**
 * Geo6 class
 *
 * @author    <NAME> <<EMAIL>>
 * @version   3.0.0
 * @copyright Copyright (c), <NAME>. All rights reserved.
 * @license   BSD License
 */
class Geo6
{
    // URL for the api
    const API_URL = 'https://taxipost.geo6.be/Locator';

    // current version
    const VERSION = '3';

    /**
     * @var string
     */
    private $appId;

    /**
     * @var string
     */
    private $partner;

    /**
     * The timeout
     *
     * @var int
     */
    private $timeOut = 10;

    /**
     * The user agent
     *
     * @var string
     */
    private $userAgent;

    /**
     * Constructor
     * @param string $partner Static parameter used for protection/statistics
     * @param string $appId   Static parameter used for protection/statistics
     */
    public function __construct($partner, $appId)
    {
        $this->setPartner((string) $partner);
        $this->setAppId((string) $appId);
    }

    /**
     * Build the url to be called
     *
     * @param  string     $method
     * @param  array|null $parameters
     * @return string
     */
    private function buildUrl($method, $parameters = null)
    {
        // add credentials
        $parameters['Function'] = $method;
        $parameters['Partner'] = $this->getPartner();
        $parameters['AppId'] = $this->getAppId();
        $parameters['Format'] = 'xml';

        return self::API_URL . '?' . http_build_query($parameters);
    }

    /**
     * Make the real call
     *
     * @param  string     $method
     * @param  array|null $parameters
     * @return \SimpleXMLElement
     * @throws BpostCurlException
     * @throws BpostInvalidXmlResponseException
     * @throws BpostTaxipostLocatorException
     */
    private function doCall($method, $parameters = null)
    {
        $options[CURLOPT_URL] = $this->buildUrl($method, $parameters);
        $options[CURLOPT_USERAGENT] = $this->getUserAgent();
        $options[CURLOPT_FOLLOWLOCATION] = true;
        $options[CURLOPT_SSL_VERIFYPEER] = false;
        $options[CURLOPT_SSL_VERIFYHOST] = false;
        $options[CURLOPT_RETURNTRANSFER] = true;
        $options[CURLOPT_TIMEOUT] = (int) $this->getTimeOut();

        $curl = curl_init();

        // set options<commit_msg>refactor (Geo6): Externalize a part of buildUrl() into buildParameters()<commit_after><?php
namespace Bpost\BpostApiClient;

use Bpost\BpostApiClient\Exception\ApiResponseException\BpostCurlException;
use Bpost\BpostApiClient\Exception\ApiResponseException\BpostInvalidXmlResponseException;
use Bpost\BpostApiClient\Exception\ApiResponseException\BpostTaxipostLocatorException;
use Bpost\BpostApiClient\Geo6\Poi;

/**
 * Geo6 class
 *
 * @author    <NAME> <<EMAIL>>
 * @version   3.0.0
 * @copyright Copyright (c), <NAME>. All rights reserved.
 * @license   BSD License
 */
class Geo6
{
    // URL for the api
    const API_URL = 'https://taxipost.geo6.be/Locator';

    // current version
    const VERSION = '3';

    /**
     * @var string
     */
    private $appId;

    /**
     * @var string
     */
    private $partner;

    /**
     * The timeout
     *
     * @var int
     */
    private $timeOut = 10;

    /**
     * The user agent
     *
     * @var string
     */
    private $userAgent;

    /**
     * Constructor
     * @param string $partner Static parameter used for protection/statistics
     * @param string $appId   Static parameter used for protection/statistics
     */
    public function __construct($partner, $appId)
    {
        $this->setPartner((string) $partner);
        $this->setAppId((string) $appId);
    }

    /**
     * Build the url to be called
     *
     * @param string $method
     * @param array  $parameters
     * @return string
     */
    private function buildUrl($method, array $parameters = array())
    {
        return self::API_URL . '?' . $this->buildParameters($method, $parameters);
    }

    /**
     * Build the parameters to send (URL-encoded string)
     *
     * @param  string $method
     * @param  array  $parameters
     * @return string
     */
    private function buildParameters($method, array $parameters = array())
    {
        // add credentials
        $parameters['Function'] = $method;
        $parameters['Partner'] = $this->getPartner();
        $parameters['AppId'] = $this->getAppId();
        $parameters['Format'] = 'xml';

        return http_build_query($parameters);
    }

    /**
     * Make the real call
     *
     * @param  string     $method
     * @param  array|null $parameters
     * @return \SimpleXMLElement
     * @throws BpostCurlException
     * @throws BpostInvalidXmlResponseException
     * @throws BpostTaxipostLocatorException
     */
    private function doCall($method, $parameters = null)
    {
        $options[CURLOPT_URL] = $this->buildUrl($method, $parameters);
        $options[CURLOPT_USERAGENT] = $this->getUserAgent();
        $options[CURLOPT_FOLLOWLOCATION] = true;
        $options[CURLOPT_SSL_VERIFYPEER] = false;
        $options[CURLOPT_SSL_VERIFYHOST] = false;
        $options[CURLOPT_RETURNTRANSFER] = true;
        $options[CURLOPT_TIMEOUT] = (int) $this->getTimeOut();

        $curl = curl_init();

        // set options
{'fraction_non_alphanumeric': 0.1254739122585304, 'fraction_numerical': 0.003791298068243365, 'mean_word_length': 2.5765009683666884, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3337454', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1696, 'n_words': 360}