<commit_before><?php  namespace Aedart\Testing\Laravel\Traits; 

use Aedart\Testing\Laravel\Exceptions\ApplicationRunningException;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Facade;
use Orchestra\Testbench\Traits\ApplicationTrait;

/**
 * Trait Application Initiator
 *
 * @see \Aedart\Testing\Laravel\Interfaces\IApplicationInitiator
 *
 * @author <NAME> <<EMAIL>>
 * @package Aedart\Testing\Laravel\Traits
 */
trait ApplicationInitiatorTrait {

    use ApplicationTrait;

    /**
     * Instance of the Laravel Application
     *
     * @var Application
     */
    protected $app = null;

    /**
     * The base URL to use while testing the application.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * The Eloquent factory instance.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var \Illuminate\Database\Eloquent\Factory
     */
    protected $factory;

    /**
     * The callbacks that should be run before the application is destroyed.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var array
     */
    protected $beforeApplicationDestroyedCallbacks = [];

    /**
     * Start the application
     *
     * @return void
     *
     * @throws ApplicationRunningException If an application has already been started / initialised and running
     */
    public function startApplication(){
        if($this->hasApplicationBeenStarted()){
            throw new ApplicationRunningException(sprintf('Application has already been started. Please stop the application, before invoking start!'));
        }

        $this->refreshApplication();

        if(! $this->factory) {
            $this->factory = $this->app->make(Factory::class);
        }
    }

    /**
     * Stop the application
     *
     * @return void
     */
    public function stopApplication(){
        if($this->hasApplicationBeenStarted()){
            foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
                call_user_func($callback);
            }

            $this->app->flush();
            $this->app = null;

            Facade::clearResolvedInstances();
            Facade::setFacadeApplication(null);
        }
    }

    /**
     * Refresh the application instance.
     *
     * @return void
     */
    protected function refreshApplication(){
        putenv('APP_ENV=testing');

        $this->app = $this->createApplication();
    }

    /**
     * Get the application instance
     *
     * @return \Illuminate\Foundation\Application|null Instance of the application Or null if none has been started
     */
    public function getApplication(){
        return $this->app;
    }

    /**
     * Check if the application has been started
     *
     * @return bool True if an application instance has been created, initialised and running. False if not.
     */
    public function hasApplicationBeenStarted(){
        if(!is_null($this->app)){
            return true;
        }
        return false;
    }

    /**
     * Define environment setup.
     *
     * @param  \Illuminate\Foundation\Application   $app
     *
     * @return void
     *
     * @see \Orchestra\Testbench\TestCase
     */
    protected function getEnvironmentSetUp($app){
        // Define your environment setup.
    }

    /**
     * Register a callback to be run before the application is destroyed.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @param  callable  $callback
     *
     * @return void
     */
    protected function beforeApplicationDestroyed(callable $callback)
    {
        $this->beforeApplicationDestroyedCallbacks[] = $callback;
    }
}<commit_msg>Fix formatting<commit_after><?php namespace Aedart\Testing\Laravel\Traits;

use Aedart\Testing\Laravel\Exceptions\ApplicationRunningException;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Facade;
use Orchestra\Testbench\Traits\ApplicationTrait;

/**
 * Trait Application Initiator
 *
 * @see \Aedart\Testing\Laravel\Interfaces\IApplicationInitiator
 *
 * @author <NAME> <<EMAIL>>
 * @package Aedart\Testing\Laravel\Traits
 */
trait ApplicationInitiatorTrait
{
    use ApplicationTrait;

    /**
     * Instance of the Laravel Application
     *
     * @var Application
     */
    protected $app = null;

    /**
     * The base URL to use while testing the application.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * The Eloquent factory instance.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var \Illuminate\Database\Eloquent\Factory
     */
    protected $factory;

    /**
     * The callbacks that should be run before the application is destroyed.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @var array
     */
    protected $beforeApplicationDestroyedCallbacks = [];

    /**
     * Start the application
     *
     * @return void
     *
     * @throws ApplicationRunningException If an application has already been started / initialised and running
     */
    public function startApplication()
    {
        if ($this->hasApplicationBeenStarted()) {
            throw new ApplicationRunningException(sprintf('Application has already been started. Please stop the application, before invoking start!'));
        }

        $this->refreshApplication();

        if (!$this->factory) {
            $this->factory = $this->app->make(Factory::class);
        }
    }

    /**
     * Stop the application
     *
     * @return void
     */
    public function stopApplication()
    {
        if ($this->hasApplicationBeenStarted()) {
            foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
                call_user_func($callback);
            }

            $this->app->flush();
            $this->app = null;

            Facade::clearResolvedInstances();
            Facade::setFacadeApplication(null);
        }
    }

    /**
     * Refresh the application instance.
     *
     * @return void
     */
    protected function refreshApplication()
    {
        putenv('APP_ENV=testing');

        $this->app = $this->createApplication();
    }

    /**
     * Get the application instance
     *
     * @return \Illuminate\Foundation\Application|null Instance of the application Or null if none has been started
     */
    public function getApplication()
    {
        return $this->app;
    }

    /**
     * Check if the application has been started
     *
     * @return bool True if an application instance has been created, initialised and running. False if not.
     */
    public function hasApplicationBeenStarted()
    {
        if (!is_null($this->app)) {
            return true;
        }
        return false;
    }

    /**
     * Define environment setup.
     *
     * @param  \Illuminate\Foundation\Application $app
     *
     * @return void
     *
     * @see \Orchestra\Testbench\TestCase
     */
    protected function getEnvironmentSetUp($app)
    {
        // Define your environment setup.
    }

    /**
     * Register a callback to be run before the application is destroyed.
     *
     * @see \Orchestra\Testbench\TestCase
     *
     * @param  callable $callback
     *
     * @return void
     */
    protected function beforeApplicationDestroyed(callable $callback)
    {
        $this->beforeApplicationDestroyedCallbacks[] = $callback;
    }
}
{'fraction_non_alphanumeric': 0.10606658770890906, 'fraction_numerical': 0.0, 'mean_word_length': 2.239556692242114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, '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': '4216121', 'n_tokens_mistral': 2067, 'n_tokens_neox': 2055, 'n_words': 494}