<commit_before><?php

namespace Bugsnag\BugsnagLaravel;

use Bugsnag\BugsnagLaravel\Request\LaravelResolver;
use Bugsnag\Callbacks\CustomUser;
use Bugsnag\Client;
use Bugsnag\Configuration;
use Bugsnag\PsrLogger\MultiLogger;
use GuzzleHttp\Client as Guzzle;
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;

class BugsnagServiceProvider extends ServiceProvider
{
    /**
     * The package version.
     *
     * @var string
     */
    const VERSION = '2.0.1';

    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        $source = realpath(__DIR__.'/../config/bugsnag.php');

        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
            $this->publishes([$source => config_path('bugsnag.php')]);
        } elseif ($this->app instanceof LumenApplication) {
            $this->app->configure('bugsnag');
        }

        $this->mergeConfigFrom($source, 'bugsnag');

        $callback = function () {
            $this->app['bugsnag']->flush();
        };

        $this->app['queue']->after($callback);
        $this->app['queue']->stopping($callback);

        if (method_exists($this->app['queue'], 'exceptionOccurred')) {
            $this->app['queue']->exceptionOccurred($callback);
        } else {
            $this->app['queue']->looping($callback);
        }
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('bugsnag', function (Container $app) {
            $config = $app->config->get('bugsnag');

            $configuration = new Configuration($config['api_key']);

            $resolver = new LaravelResolver($app);

            $options = ['base_uri' => isset($config['endpoint']) ? $config['endpoint'] : Client::ENDPOINT];

            if (isset($config['proxy']) && $config['proxy']) {
                if (isset($config['proxy']['http'])) {
                    unset($config['proxy']['http']);
                }

                $options['proxy'] = $config['proxy'];
            }

            $guzzle = new Guzzle($options);

            $client = new Client($configuration, $resolver, $guzzle);

            if (!isset($config['callbacks']) || $config['callbacks']) {
                $client->registerDefaultCallbacks();
            }

            if (!isset($config['user']) || $config['user']) {
                $client->registerCallback(new CustomUser(function () use ($app) {
                    if ($user = $app->auth->user()) {
                        return $user->toArray();
                    }
                }));
            }

            $client->setStripPath($app->basePath());
            $client->setProjectRoot($app->path());
            $client->setReleaseStage($app->environment());
            $client->setNotifier([
                'name' => 'Bugsnag Laravel',
                'version' => static::VERSION,
                'url' => 'https://github.com/bugsnag/bugsnag-laravel',
            ]);<commit_msg>If not cli<commit_after><?php

namespace Bugsnag\BugsnagLaravel;

use Bugsnag\BugsnagLaravel\Request\LaravelResolver;
use Bugsnag\Callbacks\CustomUser;
use Bugsnag\Client;
use Bugsnag\Configuration;
use Bugsnag\PsrLogger\MultiLogger;
use GuzzleHttp\Client as Guzzle;
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;

class BugsnagServiceProvider extends ServiceProvider
{
    /**
     * The package version.
     *
     * @var string
     */
    const VERSION = '2.0.1';

    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        $source = realpath(__DIR__.'/../config/bugsnag.php');

        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
            $this->publishes([$source => config_path('bugsnag.php')]);
        } elseif ($this->app instanceof LumenApplication) {
            $this->app->configure('bugsnag');
        }

        $this->mergeConfigFrom($source, 'bugsnag');

        $callback = function () {
            $this->app['bugsnag']->flush();
        };

        $this->app['queue']->after($callback);
        $this->app['queue']->stopping($callback);

        if (method_exists($this->app['queue'], 'exceptionOccurred')) {
            $this->app['queue']->exceptionOccurred($callback);
        } else {
            $this->app['queue']->looping($callback);
        }
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('bugsnag', function (Container $app) {
            $config = $app->config->get('bugsnag');

            $configuration = new Configuration($config['api_key']);

            $resolver = new LaravelResolver($app);

            $options = ['base_uri' => isset($config['endpoint']) ? $config['endpoint'] : Client::ENDPOINT];

            if (isset($config['proxy']) && $config['proxy']) {
                if (isset($config['proxy']['http']) && php_sapi_name() != 'cli') {
                    unset($config['proxy']['http']);
                }

                $options['proxy'] = $config['proxy'];
            }

            $guzzle = new Guzzle($options);

            $client = new Client($configuration, $resolver, $guzzle);

            if (!isset($config['callbacks']) || $config['callbacks']) {
                $client->registerDefaultCallbacks();
            }

            if (!isset($config['user']) || $config['user']) {
                $client->registerCallback(new CustomUser(function () use ($app) {
                    if ($user = $app->auth->user()) {
                        return $user->toArray();
                    }
                }));
            }

            $client->setStripPath($app->basePath());
            $client->setProjectRoot($app->path());
            $client->setReleaseStage($app->environment());
            $client->setNotifier([
                'name' => 'Bugsnag Laravel',
                'version' => static::VERSION,
                'url' => 'https://github.com/bugsnag/bugsnag-laravel',
            ]);
{'fraction_non_alphanumeric': 0.16550007777259293, 'fraction_numerical': 0.0009332711152589828, 'mean_word_length': 2.1910669975186106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 2, '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': '3805579', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1761, 'n_words': 296}