<commit_before><?php

namespace SimpleNeo4j;

class Client
{
    const CONFIG_HOST = 'host';
    const CONFIG_PORT = 'port';
    const CONFIG_SECURE = 'secure';
    const CONFIG_PROTOCOL = 'protocol';
    const CONFIG_ERROR_MODE = 'error_mode';
    const CONFIG_NO_SSL_VERIFY = 'no_ssl_verify';

    const ERROR_MODE_HIDE_ERRORS = 'hide';
    const ERROR_MODE_THROW_ERRORS = 'throw';

    const NEO4J_CYPHER_ENDPOINT = 'db/data/transaction/commit';

    const DEFAULT_CONFIG = [
        self::CONFIG_HOST => 'localhost',
        self::CONFIG_PORT => 7474,
        self::CONFIG_SECURE => false,
        self::CONFIG_PROTOCOL => 'http',
        self::CONFIG_ERROR_MODE => '',
        self::CONFIG_NO_SSL_VERIFY => false,
    ];

    /**
     * @var \GuzzleHttp\Client
     */
    private $_http_client;

    /**
     * @var array
     */
    private $_config;

    /**
     * @var array
     */
    private $_query_batch = [];

    /**
     * @param array $config
     * @param \GuzzleHttp\Client|null $http_client
     */
    public function __construct(array $config = [], \GuzzleHttp\Client $http_client = null)
    {
        $this->_setConfigFromOptions($config);
        $this->_http_client = $http_client ?: new \GuzzleHttp\Client();
    }

    /**
     * @return string
     */
    public function getHost() : string
    {
        return $this->_config[self::CONFIG_HOST];
    }

    /**
     * @return int
     */
    public function getPort() : int
    {
        return $this->_config[self::CONFIG_PORT];
    }

    /**
     * @return bool
     */
    public function isSecure() : bool
    {
        return $this->_config[self::CONFIG_SECURE];
    }

    /**
     * @return string
     */
    public function getProtocol() : string
    {
        return $this->_config[self::CONFIG_PROTOCOL];
    }

    public function addQueryToBatch(string $query, array $params = [])
    {
        $this->_query_batch[] = [
            'statement' => $query,
            'parameters' => (object)$params,
        ];
    }

    /**
     * @return \SimpleNeo4j\ResultSet
     *
     * @throws \SimpleNeo4j\Exception\CypherQueryException
     */
    public function executeBatchQueries()
    {
        if (!$this->_query_batch) {
            return new ResultSet();
        }

        $send_params = [
            'statements' => $this->_query_batch
        ];

        $result = $this->_sendNeo4jPostRequest( self::NEO4J_CYPHER_ENDPOINT, json_encode($send_params));
        $result_list = new ResultSet($result);

        if ($this->_config[self::CONFIG_ERROR_MODE] == self::ERROR_MODE_THROW_ERRORS && $result_list->hasError()) {
            throw $result_list->getFirstError();
        }

        return $result_list;
        //print_r($result);exit;
    }

    /**
     * @param string $query
     * @param array $params
     *
     * @return \SimpleNeo4j\ResultSet
     */
    public function executeQuery(string $query, array $params = [])
    {
        $this->addQueryToBatch($query, $params);<commit_msg>properly clear batch<commit_after><?php

namespace SimpleNeo4j;

class Client
{
    const CONFIG_HOST = 'host';
    const CONFIG_PORT = 'port';
    const CONFIG_SECURE = 'secure';
    const CONFIG_PROTOCOL = 'protocol';
    const CONFIG_ERROR_MODE = 'error_mode';
    const CONFIG_NO_SSL_VERIFY = 'no_ssl_verify';

    const ERROR_MODE_HIDE_ERRORS = 'hide';
    const ERROR_MODE_THROW_ERRORS = 'throw';

    const NEO4J_CYPHER_ENDPOINT = 'db/data/transaction/commit';

    const DEFAULT_CONFIG = [
        self::CONFIG_HOST => 'localhost',
        self::CONFIG_PORT => 7474,
        self::CONFIG_SECURE => false,
        self::CONFIG_PROTOCOL => 'http',
        self::CONFIG_ERROR_MODE => '',
        self::CONFIG_NO_SSL_VERIFY => false,
    ];

    /**
     * @var \GuzzleHttp\Client
     */
    private $_http_client;

    /**
     * @var array
     */
    private $_config;

    /**
     * @var array
     */
    private $_query_batch = [];

    /**
     * @param array $config
     * @param \GuzzleHttp\Client|null $http_client
     */
    public function __construct(array $config = [], \GuzzleHttp\Client $http_client = null)
    {
        $this->_setConfigFromOptions($config);
        $this->_http_client = $http_client ?: new \GuzzleHttp\Client();
    }

    /**
     * @return string
     */
    public function getHost() : string
    {
        return $this->_config[self::CONFIG_HOST];
    }

    /**
     * @return int
     */
    public function getPort() : int
    {
        return $this->_config[self::CONFIG_PORT];
    }

    /**
     * @return bool
     */
    public function isSecure() : bool
    {
        return $this->_config[self::CONFIG_SECURE];
    }

    /**
     * @return string
     */
    public function getProtocol() : string
    {
        return $this->_config[self::CONFIG_PROTOCOL];
    }

    public function addQueryToBatch(string $query, array $params = [])
    {
        $this->_query_batch[] = [
            'statement' => $query,
            'parameters' => (object)$params,
        ];
    }

    /**
     * @return \SimpleNeo4j\ResultSet
     *
     * @throws \SimpleNeo4j\Exception\CypherQueryException
     */
    public function executeBatchQueries()
    {
        if (!$this->_query_batch) {
            return new ResultSet();
        }

        $send_params = [
            'statements' => $this->_query_batch
        ];

        $this->_query_batch = [];

        $result = $this->_sendNeo4jPostRequest( self::NEO4J_CYPHER_ENDPOINT, json_encode($send_params));
        $result_list = new ResultSet($result);

        if ($this->_config[self::CONFIG_ERROR_MODE] == self::ERROR_MODE_THROW_ERRORS && $result_list->hasError()) {
            throw $result_list->getFirstError();
        }

        return $result_list;
        //print_r($result);exit;
    }

    /**
     * @param string $query
     * @param array $params
     *
     * @return \SimpleNeo4j\ResultSet
     */
    public function executeQuery(string $query, array $params = [])
    {
        $this->addQueryToBatch($query, $params);
{'fraction_non_alphanumeric': 0.13687520688513738, 'fraction_numerical': 0.003641178417742469, 'mean_word_length': 2.259439050701187, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '5850441', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1871, 'n_words': 332}