<commit_before><?php
namespace Laranix\Themer;

use Illuminate\Foundation\Application;
use Illuminate\Contracts\Config\Repository;
use Laranix\AntiSpam\Recaptcha\Recaptcha;
use Laranix\Themer\Script\Scripts;
use Laranix\Themer\Style\Styles;
use Laranix\Themer\Image\Images;

trait LoadsThemer
{
    /**
     * @var \Laranix\Themer\ThemerResource
     */
    protected $styles;

    /**
     * @var \Laranix\Themer\ThemerResource
     */
    protected $scripts;

    /**
     * Initialise and load themer components
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function loadThemer(Application $app)
    {
        $this->styles     = $app->make(Styles::class);
        $this->scripts    = $app->make(Scripts::class);

        if (method_exists($this, 'share')) {
            $this->share([
                 'styles'  => $this->styles,
                 'scripts' => $this->scripts,
                 'images'  => $app->make(Images::class),
             ]);
        }
    }

    /**
     * Load the default themer files
     *
     * @param \Illuminate\Contracts\Config\Repository $config
     */
    protected function loadThemerDefaultFiles(Repository $config)
    {
        $this->loadStylesheets($config->get('themerdefaultfiles.styles.global'));
        $this->loadScripts($config->get('themerdefaultfiles.scripts.global'));
    }

    /**
     * Load the default themer files
     *
     * @param \Illuminate\Contracts\Config\Repository $config
     * @param \Laranix\AntiSpam\Recaptcha\Recaptcha   $recaptcha
     */
    protected function loadThemerDefaultFormFiles(Repository $config, Recaptcha $recaptcha)
    {
        $this->loadStylesheets($config->get('themerdefaultfiles.styles.form'));
        $this->loadScripts($config->get('themerdefaultfiles.scripts.form'));

        if ($recaptcha->enabled()) {
            $this->loadScript([
                'key'       => 'recaptcha',
                'filename'  => 'api.js',
                'url'       => 'https://www.google.com/recaptcha',
                'order'     => 10,
                'async'     => true,
            ]);
        }
    }

    /**
     * Add a stylesheet
     *
     * @param \Laranix\Themer\Style\Settings|array|null $settings
     * @return $this
     */
    protected function loadStylesheet($settings)
    {
        if ($settings === null) {
            return $this;
        }

        $this->styles->add($settings);

        return $this;
    }

    /**
     * Add multiple stylesheets
     *
     * @param mixed ...$styles
     */
    protected function loadStylesheets(...$styles)
    {
        $files = $this->getFilePayload($styles[0] ?? null);

        if (empty($files)) {
            return;
        }

        foreach ($files as $style) {
            $this->loadStylesheet($style);
        }
    }

    /**
     * Add a script
     *
     * @param \Laranix\Themer\ResourceSettings|array|null $settings
     * @return $this
     */
    protected function loadScript($settings)
    {
        if ($settings === null || !is_array($settings)) {
            return $this;
        }

        $this->scripts->add($settings);

        return $this;
    }

    /**
     * Add multiple scripts
     *
     * @param array $scripts
     */
    protected function loadScripts(...$scripts)
    {
        $files = $this->getFilePayload($scripts[0] ?? null);

        if (empty($files)) {
            return;
        }

        foreach ($files as $script) {
            $this->loadScript($script);
        }
    }

    /**
     * Get the file payload
     *
     * @param array|null $files
     * @return array|null
     */
    protected function getFilePayload(?array $files) : ?array
    {<commit_msg>Remove null checks Will be handled by themer<commit_after><?php
namespace Laranix\Themer;

use Illuminate\Foundation\Application;
use Illuminate\Contracts\Config\Repository;
use Laranix\AntiSpam\Recaptcha\Recaptcha;
use Laranix\Themer\Script\Scripts;
use Laranix\Themer\Style\Styles;
use Laranix\Themer\Image\Images;

trait LoadsThemer
{
    /**
     * @var \Laranix\Themer\ThemerResource
     */
    protected $styles;

    /**
     * @var \Laranix\Themer\ThemerResource
     */
    protected $scripts;

    /**
     * Initialise and load themer components
     *
     * @param \Illuminate\Foundation\Application $app
     */
    protected function loadThemer(Application $app)
    {
        $this->styles     = $app->make(Styles::class);
        $this->scripts    = $app->make(Scripts::class);

        if (method_exists($this, 'share')) {
            $this->share([
                 'styles'  => $this->styles,
                 'scripts' => $this->scripts,
                 'images'  => $app->make(Images::class),
             ]);
        }
    }

    /**
     * Load the default themer files
     *
     * @param \Illuminate\Contracts\Config\Repository $config
     */
    protected function loadThemerDefaultFiles(Repository $config)
    {
        $this->loadStylesheets($config->get('themerdefaultfiles.styles.global'));
        $this->loadScripts($config->get('themerdefaultfiles.scripts.global'));
    }

    /**
     * Load the default themer files
     *
     * @param \Illuminate\Contracts\Config\Repository $config
     * @param \Laranix\AntiSpam\Recaptcha\Recaptcha   $recaptcha
     */
    protected function loadThemerDefaultFormFiles(Repository $config, Recaptcha $recaptcha)
    {
        $this->loadStylesheets($config->get('themerdefaultfiles.styles.form'));
        $this->loadScripts($config->get('themerdefaultfiles.scripts.form'));

        if ($recaptcha->enabled()) {
            $this->loadScript([
                'key'       => 'recaptcha',
                'filename'  => 'api.js',
                'url'       => 'https://www.google.com/recaptcha',
                'order'     => 10,
                'async'     => true,
            ]);
        }
    }

    /**
     * Add a stylesheet
     *
     * @param \Laranix\Themer\Style\Settings|array|null $settings
     * @return $this
     */
    protected function loadStylesheet($settings)
    {
        $this->styles->add($settings);

        return $this;
    }

    /**
     * Add multiple stylesheets
     *
     * @param mixed ...$styles
     */
    protected function loadStylesheets(...$styles)
    {
        $files = $this->getFilePayload($styles[0] ?? null);

        if (empty($files)) {
            return;
        }

        foreach ($files as $style) {
            $this->loadStylesheet($style);
        }
    }

    /**
     * Add a script
     *
     * @param \Laranix\Themer\ResourceSettings|array|null $settings
     * @return $this
     */
    protected function loadScript($settings)
    {
        $this->scripts->add($settings);

        return $this;
    }

    /**
     * Add multiple scripts
     *
     * @param array $scripts
     */
    protected function loadScripts(...$scripts)
    {
        $files = $this->getFilePayload($scripts[0] ?? null);

        if (empty($files)) {
            return;
        }

        foreach ($files as $script) {
            $this->loadScript($script);
        }
    }

    /**
     * Get the file payload
     *
     * @param array|null $files
     * @return array|null
     */
    protected function getFilePayload(?array $files) : ?array
    {
{'fraction_non_alphanumeric': 0.14115389886254626, 'fraction_numerical': 0.001096340962039194, 'mean_word_length': 1.9403706688154714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '7558614', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2165, 'n_words': 376}