<commit_before><?php

/*
 * This file is part of Raven.
 *
 * (c) Sentry Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Raven PHP Client
 *
 * @package raven
 */

class Raven_Client
{
    const DEBUG = 10;
    const INFO = 20;
    const WARN = 30;
    const WARNING = 30;
    const ERROR = 40;

    function __construct($options_or_dsn=null, $options=array())
    {
        if (is_null($options_or_dsn)) {
            // Read from environment
            $options_or_dsn = $_SERVER['SENTRY_DSN'];
        }
        if (!is_array($options_or_dsn)) {
            // Must be a valid DSN
            $options_or_dsn = $this->parseDSN($options_or_dsn);
        }
        $options = array_merge($options_or_dsn, $options);

        $this->servers = $options['servers'];
        $this->secret_key = $options['secret_key'];
        $this->public_key = $options['public_key'];
        $this->project = ($options['project'] ? $options['project'] : 1);
        $this->auto_log_stacks = ($options['auto_log_stacks'] ? $options['auto_log_stacks'] : false);
        $this->name = ($options['name'] ? $options['name'] : gethostname());
        $this->site = ($options['site'] ? $options['site'] : '');
    }

    /**
     * Parses a Raven-compatible DSN and returns an array of its values.
     */
    public function parseDSN($dsn)
    {
        $url = parse_url($dsn);
        $scheme = $url['scheme'];
        if (!in_array($scheme, array('http', 'https'))) {
            throw new InvalidArgumentException('Unsupported Sentry DSN scheme: ' . $scheme);
        }
        $netloc = $url['host'];
        $pos = strrpos($url['path'], '/', 1);
        if ($pos !== false) {
            $path = substr($url['path'], 0, $pos);
            $project = substr($url['path'], $pos + 1);
        }
        else {
            $path = '';
            $project = substr($url['path'], 1);
        }
        $username = $url['user'];
        $password = $url['pass'];
        if (empty($netloc) || empty($project) || empty($username) || empty($password)) {
            throw new InvalidArgumentException('Invalid Sentry DSN: ' . $dsn);
        }
        return array(
            'servers'    => array(sprintf('%s://%s%s/api/store/', $scheme, $netloc, $path)),
            'project'    => $project,
            'public_key' => $username,
            'secret_key' => $password,
        );
    }

    /**<commit_msg>Declare parseDSN as a static function<commit_after><?php

/*
 * This file is part of Raven.
 *
 * (c) Sentry Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Raven PHP Client
 *
 * @package raven
 */

class Raven_Client
{
    const DEBUG = 10;
    const INFO = 20;
    const WARN = 30;
    const WARNING = 30;
    const ERROR = 40;

    function __construct($options_or_dsn=null, $options=array())
    {
        if (is_null($options_or_dsn)) {
            // Read from environment
            $options_or_dsn = $_SERVER['SENTRY_DSN'];
        }
        if (!is_array($options_or_dsn)) {
            // Must be a valid DSN
            $options_or_dsn = self::parseDSN($options_or_dsn);
        }
        $options = array_merge($options_or_dsn, $options);

        $this->servers = $options['servers'];
        $this->secret_key = $options['secret_key'];
        $this->public_key = $options['public_key'];
        $this->project = ($options['project'] ? $options['project'] : 1);
        $this->auto_log_stacks = ($options['auto_log_stacks'] ? $options['auto_log_stacks'] : false);
        $this->name = ($options['name'] ? $options['name'] : gethostname());
        $this->site = ($options['site'] ? $options['site'] : '');
    }

    /**
     * Parses a Raven-compatible DSN and returns an array of its values.
     */
    public static function parseDSN($dsn)
    {
        $url = parse_url($dsn);
        $scheme = $url['scheme'];
        if (!in_array($scheme, array('http', 'https'))) {
            throw new InvalidArgumentException('Unsupported Sentry DSN scheme: ' . $scheme);
        }
        $netloc = $url['host'];
        $pos = strrpos($url['path'], '/', 1);
        if ($pos !== false) {
            $path = substr($url['path'], 0, $pos);
            $project = substr($url['path'], $pos + 1);
        }
        else {
            $path = '';
            $project = substr($url['path'], 1);
        }
        $username = $url['user'];
        $password = $url['pass'];
        if (empty($netloc) || empty($project) || empty($username) || empty($password)) {
            throw new InvalidArgumentException('Invalid Sentry DSN: ' . $dsn);
        }
        return array(
            'servers'    => array(sprintf('%s://%s%s/api/store/', $scheme, $netloc, $path)),
            'project'    => $project,
            'public_key' => $username,
            'secret_key' => $password,
        );
    }

    /**
{'fraction_non_alphanumeric': 0.17053178728508597, 'fraction_numerical': 0.0059976009596161535, 'mean_word_length': 2.252925877763329, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '1960337', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1536, 'n_words': 350}