<commit_before><?php
namespace Everyman\Neo4j\Transport;
use Everyman\Neo4j\Transport as BaseTransport,
    Everyman\Neo4j\Version;

/**
 * Class for communicating with an HTTP JSON endpoint
 */
class Curl extends BaseTransport
{
	protected $handle = null;

	/**
	 * @inherit
	 */
	public function __construct($host='localhost', $port=7474)
	{
		if (! function_exists('curl_init')) {
			throw new Exception('cUrl extension not enabled/installed');
		}

		parent::__construct($host, $port);
	}

	/**
	 * Make sure the curl handle closes when we are done with the Transport
	 */
	public function __destruct()
	{
		if ($this->handle) {
			curl_close($this->handle);
		}
	}

	/**
	 * @inherit
	 */
	public function makeRequest($method, $path, $data=array())
	{
		$url = $this->getEndpoint().$path;

		$options = array(
			CURLOPT_URL => $url,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_HEADER => true,
			CURLOPT_HTTPHEADER => array(
				'Accept: application/json',
				'Content-type: application/json',
				'User-Agent: '.Version::userAgent(),
			),
			CURLOPT_CUSTOMREQUEST => self::GET,
			CURLOPT_POST => false,
			CURLOPT_POSTFIELDS => null,
		);

		if ($this->username && $this->password) {
			$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
			$options[CURLOPT_USERPWD] = $this->username.':'.$this->password;
		}

		switch ($method) {
			case self::DELETE :
				$options[CURLOPT_CUSTOMREQUEST] = self::DELETE;
				break;

			case self::POST :
				$dataString = $this->encodeData($data);
				$options[CURLOPT_CUSTOMREQUEST] = self::POST;
				$options[CURLOPT_POST] = true;
				$options[CURLOPT_POSTFIELDS] = $dataString;
				$options[CURLOPT_HTTPHEADER][] = 'Content-Length: '.strlen($dataString);
				break;

			case self::PUT :
				$dataString = $this->encodeData($data);
				$options[CURLOPT_CUSTOMREQUEST] = self::PUT;
				$options[CURLOPT_POSTFIELDS] = $dataString;
				$options[CURLOPT_HTTPHEADER][] = 'Content-Length: '.strlen($dataString);
				break;
		}<commit_msg>Refactorisation<commit_after><?php
namespace Everyman\Neo4j\Transport;
use Everyman\Neo4j\Transport as BaseTransport,
    Everyman\Neo4j\Version;

/**
 * Class for communicating with an HTTP JSON endpoint
 */
class Curl extends BaseTransport
{
	protected $handle = null;

	/**
	 * @inherit
	 */
	public function __construct($host='localhost', $port=7474)
	{
		if (! function_exists('curl_init')) {
			throw new Exception('cUrl extension not enabled/installed');
		}

		parent::__construct($host, $port);
	}

	/**
	 * Make sure the curl handle closes when we are done with the Transport
	 */
	public function __destruct()
	{
		if ($this->handle) {
			curl_close($this->handle);
		}
	}

	/**
	 * @inherit
	 */
	public function makeRequest($method, $path, $data=array())
	{
		$url = $this->getEndpoint().$path;

		$options = array(
			CURLOPT_URL => $url,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_HEADER => true,
			CURLOPT_HTTPHEADER => array(
				'Accept: application/json',
				'Content-type: application/json',
				'User-Agent: '.Version::userAgent(),
			),
			CURLOPT_CUSTOMREQUEST => self::GET,
			CURLOPT_POST => false,
			CURLOPT_POSTFIELDS => null,
		);

		if ($this->username && $this->password) {
			$options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
			$options[CURLOPT_USERPWD] = $this->username.':'.$this->password;
		}

		switch ($method) {
			case self::DELETE :
				$options[CURLOPT_CUSTOMREQUEST] = self::DELETE;
				break;

			case self::POST :
            case self::PUT :
                $dataString = $this->encodeData($data);
                $options[CURLOPT_CUSTOMREQUEST] = $method;
                $options[CURLOPT_POSTFIELDS] = $dataString;
                $options[CURLOPT_HTTPHEADER][] = 'Content-Length: '.strlen($dataString);

                if (self::POST == $method) {
                    $options[CURLOPT_POST] = true;
                }
            break;
		}
{'fraction_non_alphanumeric': 0.1495085359544749, 'fraction_numerical': 0.0036213140196585617, 'mean_word_length': 3.480880648899189, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '3731106', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1291, 'n_words': 247}