<commit_before><?php

namespace Schema;

class ClientException extends \Exception {}

class Client
{
    /**
     * @var array
     */
    protected $params;

    /**
     * @var Connection
     */
    protected $server;

    /**
     * @var string
     */
    protected $session;

    /**
     * @var bool
     */
    protected $authed;

    /**
     * @var Cache
     */
    public $cache;

    /**
     * @static string
     */
    public static $default_host = "api.schema.io";

    /**
     * @static int
     */
    public static $default_port = 8443;

    /**
     * @static string
     */
    public static $default_rescue_host = "rescue.api.schema.io";

    /**
     * @static int
     */
    public static $default_rescue_port = 8443;

    /**
     * @param  string $client_id
     * @param  string $client_key
     * @param  array $options
     * @return void
     */
    function __construct($client_id, $client_key = null, $options = null)
    {
        if (is_array($client_id)) {
            $options = $client_id;
            $client_id = null;
        } else if (is_array($client_key)) {
            $options = $client_key;
            $client_key = null;
        }
        if ($client_id === null) {
            if (isset($options['client_id'])) {
                $client_id = $options['client_id'];
            } else if (isset($options['id'])) {
                $client_id = $options['id'];
            }
        }
        if ($client_key === null) {
            if (isset($options['client_key'])) {
                $client_key = $options['client_key'];
            } else if (isset($options['key'])) {
                $client_key = $options['key'];
            }
        }
        if (!isset($options['session']) || $options['session']) {
            if (!is_string($options['session'])) {
                $options['session'] = session_id();
            }
        }
        if (isset($options['rescue']) && $options['rescue'] !== false) {
            $options['rescue'] = array(
                'host' => isset($options['rescue']['host']) && $options['rescue']['host']
                    ? $options['rescue']['host'] : self::$default_rescue_host,
                'port' => isset($options['rescue']['port']) && $options['rescue']['port']
                    ? $options['rescue']['port'] : self::$default_rescue_port
            );
        }

        $this->params = array(
            'client_id' => $client_id,
            'client_key' => $client_key,
            'host' => isset($options['host']) ? $options['host'] : self::$default_host,
            'port' => isset($options['port']) ? $options['port'] : self::$default_port,
            'verify_cert' => isset($options['verify_cert']) ? $options['verify_cert'] : true,
            'version' => isset($options['version']) ? $options['version'] : 1,
            'session' => isset($options['session']) ? $options['session'] : null,
            'rescue' => isset($options['rescue']) ? $options['rescue'] : null,
            'api' => isset($options['api']) ? $options['api'] : null,
            'route' => isset($options['route']['client']) ? $options['route'] : null,
            'proxy' => isset($options['proxy']) ? $options['proxy'] : null,
            'cache' => isset($options['cache']) ? $options['cache'] : null
        );

        $this->server = new Connection(array(
            'host' => $this->params['host'],
            'port' => $this->params['port'],
            'verify_cert' => $this->params['verify_cert']
        ));
    }

    /**
     * Get or set client params
     *
     * @param  mixed $merge
     * @param  array
     */
    public function params($merge = null)
    {
        if (is_array($merge)) {
            $this->params = array_merge($this->params, $merge);
        } else if (is_string($key = $merge)) {
            return $this->params[$key];
        } else {
            return $this->params;
        }
    }

    /**
     * Request helper
     *
     * @param  string $method
     * @param  string $url
     * @param  array $data
     * @return mixed
     */
    public function request($method, $url, $data = null)
    {
        $url = (string)$url;
        $data = array('$data' => $data);

        if (!$this->cache && $this->params['cache']) {
            $client_id = isset($this->params['route']['client'])
                ? $this->params['route']['client']
                : $this->params['client_id'];
            $this->cache = new Cache($client_id, $this->params['cache']);
        }

        try {
            if (!$this->server->connected) {
                if ($this->params['proxy']) {
                    $data = $this->request_proxy_data($data);
                }
                if (!$this->authed) {
                    $data['$client'] = isset($this->params['route']['client'])
                        ? $this->params['route']['client']
                        : $this->params['client_id'];
                }
                $this->server->connect();
            }
            $result = $this->server->request($method, $url, $data);
        } catch (NetworkException $e) {<commit_msg>update client<commit_after><?php

namespace Schema;

class ClientException extends \Exception {}

class Client
{
    /**
     * @var array
     */
    protected $params;

    /**
     * @var Connection
     */
    protected $server;

    /**
     * @var string
     */
    protected $session;

    /**
     * @var bool
     */
    protected $authed;

    /**
     * @var Cache
     */
    public $cache;

    /**
     * @static string
     */
    public static $default_host = "api.schema.io";

    /**
     * @static int
     */
    public static $default_port = 8443;

    /**
     * @static string
     */
    public static $default_rescue_host = "rescue.api.schema.io";

    /**
     * @static int
     */
    public static $default_rescue_port = 8443;

    /**
     * @param  string $client_id
     * @param  string $client_key
     * @param  array $options
     * @return void
     */
    function __construct($client_id, $client_key = null, $options = null)
    {
        if (is_array($client_id)) {
            $options = $client_id;
            $client_id = null;
        } else if (is_array($client_key)) {
            $options = $client_key;
            $client_key = null;
        }
        if ($client_id === null) {
            if (isset($options['client_id'])) {
                $client_id = $options['client_id'];
            } else if (isset($options['id'])) {
                $client_id = $options['id'];
            }
        }
        if ($client_key === null) {
            if (isset($options['client_key'])) {
                $client_key = $options['client_key'];
            } else if (isset($options['key'])) {
                $client_key = $options['key'];
            }
        }
        if (!isset($options['session']) || $options['session']) {
            if (isset($options['session']) && is_string($options['session'])) {
                $options['session'] = session_id();
            }
        }
        if (isset($options['rescue']) && $options['rescue'] !== false) {
            $options['rescue'] = array(
                'host' => isset($options['rescue']['host']) && $options['rescue']['host']
                    ? $options['rescue']['host'] : self::$default_rescue_host,
                'port' => isset($options['rescue']['port']) && $options['rescue']['port']
                    ? $options['rescue']['port'] : self::$default_rescue_port
            );
        }

        $this->params = array(
            'client_id' => $client_id,
            'client_key' => $client_key,
            'host' => isset($options['host']) ? $options['host'] : self::$default_host,
            'port' => isset($options['port']) ? $options['port'] : self::$default_port,
            'verify_cert' => isset($options['verify_cert']) ? $options['verify_cert'] : true,
            'version' => isset($options['version']) ? $options['version'] : 1,
            'session' => isset($options['session']) ? $options['session'] : null,
            'rescue' => isset($options['rescue']) ? $options['rescue'] : null,
            'api' => isset($options['api']) ? $options['api'] : null,
            'route' => isset($options['route']['client']) ? $options['route'] : null,
            'proxy' => isset($options['proxy']) ? $options['proxy'] : null,
            'cache' => isset($options['cache']) ? $options['cache'] : null
        );

        $this->server = new Connection(array(
            'host' => $this->params['host'],
            'port' => $this->params['port'],
            'verify_cert' => $this->params['verify_cert']
        ));
    }

    /**
     * Get or set client params
     *
     * @param  mixed $merge
     * @param  array
     */
    public function params($merge = null)
    {
        if (is_array($merge)) {
            $this->params = array_merge($this->params, $merge);
        } else if (is_string($key = $merge)) {
            return $this->params[$key];
        } else {
            return $this->params;
        }
    }

    /**
     * Request helper
     *
     * @param  string $method
     * @param  string $url
     * @param  array $data
     * @return mixed
     */
    public function request($method, $url, $data = null)
    {
        $url = (string)$url;
        $data = array('$data' => $data);

        if (!$this->cache && $this->params['cache']) {
            $client_id = isset($this->params['route']['client'])
                ? $this->params['route']['client']
                : $this->params['client_id'];
            $this->cache = new Cache($client_id, $this->params['cache']);
        }

        try {
            if (!$this->server->connected) {
                if ($this->params['proxy']) {
                    $data = $this->request_proxy_data($data);
                }
                if (!$this->authed) {
                    $data['$client'] = isset($this->params['route']['client'])
                        ? $this->params['route']['client']
                        : $this->params['client_id'];
                    // Perform basic auth by default for secure/non-route based requests
                    if (!isset($this->server->options['clear']) && !isset($this->params['route']['client'])) {
                        $data['$key'] = $this->params['client_key'];
                        if ($this->cache) {
                            $data['$cached'] = $this->cache->get_versions();
                        }
                    }
                }
                $this->server->connect();
            }
            $result = $this->server->request($method, $url, $data);
        } catch (NetworkException $e) {
{'fraction_non_alphanumeric': 0.18413915645749557, 'fraction_numerical': 0.0016833442438978772, 'mean_word_length': 1.7870732342976283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, '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': '239270', 'n_tokens_mistral': 3087, 'n_tokens_neox': 3046, 'n_words': 558}