<commit_before><?php

if( !function_exists( 'themes_base_path' ) ) {
    /**
     * @return string|boolean
     */
    function themes_base_path()
    {
        if( is_dir( realpath( __DIR__ . '/../../../vendor' ) ) ) {
            return realpath( __DIR__ . '/../../../themes' );
        }
        if( is_dir( realpath( __DIR__ . '/../../../themes' ) ) ) {
            return realpath( __DIR__ . '/../../../themes' );
        }
        if( getenv( 'APP_ENV' ) === 'testing' ) {
            return realpath( __DIR__ . '/tests/themes' );
        }

        return false;
    }
}

if( ! function_exists( 'theme_manager_starter' ) ) {
    /**
     * @return \ThemeManager\Starter
     */
    function theme_manager_starter() {
        return new \ThemeManager\Starter;
    }
}

if( !function_exists( 'theme_manager' ) ) {
    /**
     * @param null    $basePath
     * @param array   $requiredFields
     * @param boolean $exceptionOnInvalid
     *
     * @return \ThemeManager\ThemeManager
     */
    function theme_manager( $basePath = null, Array $requiredFields = [], $exceptionOnInvalid = false )
    {
        if( function_exists( 'app' ) && class_exists( 'Illuminate\Container\Container' ) ) {
            return ThemeManager::returnThis();
        }

        return new \ThemeManager\ThemeManager( theme_manager_starter()->start( $basePath, $requiredFields, $exceptionOnInvalid ) );
    }
}<commit_msg>Simplifying helper functions and adding extra protection to make sure that the ThemeManager facade exists.<commit_after><?php

use Illuminate\Support\Facades\Config;
use ThemeManager\Starter;
use ThemeManager\ThemeManager;

if( !function_exists( 'themes_base_path' ) ) {
    /**
     * @return string|boolean
     */
    function themes_base_path()
    {
        $base = __DIR__ . '/../../../';
        $vendor = realpath( $base . 'vendor' );
        $themes = realpath( $base . 'themes' );

        if( is_dir( $vendor ) ) {

            return $themes;
        }
        if( is_dir( $themes ) ) {

            return $themes;
        }
        if( getenv( 'APP_ENV' ) === 'testing' ) {

            return realpath( __DIR__ . '/tests/themes' );
        }

        return false;
    }
}

if( ! function_exists( 'theme_manager_starter' ) ) {
    /**
     * @return \ThemeManager\Starter
     */
    function theme_manager_starter()
    {
        return new Starter;
    }
}

if( !function_exists( 'theme_manager' ) ) {
    /**
     * @param null    $basePath
     * @param array   $requiredFields
     * @param boolean $exceptionOnInvalid
     *
     * @return \ThemeManager\ThemeManager
     */
    function theme_manager( $basePath = null, Array $requiredFields = [], $exceptionOnInvalid = false )
    {
        if( function_exists( 'app' ) && class_exists( 'Illuminate\Container\Container' ) &&
            class_exists( 'Illuminate\Support\Facades\Config' ) &&
            Config::get( 'app.aliases.ThemeManager' ) == 'ThemeManager\Facade\ThemeManager' )
        {
            return \ThemeManager::returnThis();
        }

        return new ThemeManager( theme_manager_starter()->start( $basePath, $requiredFields, $exceptionOnInvalid ) );
    }
}
{'fraction_non_alphanumeric': 0.14583992407465993, 'fraction_numerical': 0.0, 'mean_word_length': 2.2134146341463414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1112311', 'n_tokens_mistral': 963, 'n_tokens_neox': 945, 'n_words': 191}