<commit_before><?php

namespace Tacker;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Tacker\Loader\CacheLoader;
use Tacker\Loader\IniFileLoader;
use Tacker\Loader\JsonFileLoader;
use Tacker\Loader\NormalizerLoader;
use Tacker\Loader\PhpFileLoader;
use Tacker\Loader\YamlFileLoader;
use Tacker\Normalizer\ChainNormalizer;
use Tacker\Normalizer\EnvfileNormalizer;
use Tacker\Normalizer\EnvironmentNormalizer;

/**
 * Helps building a Loader with Cache, Normalization etc.
 *
 * @package Tacker
 */
final class LoaderBuilder
{
    private $paths;
    private $normalizer;
    private $resolver;
    private $locator;
    private $debug;
    private $cacheDir;
    private $normalizerConfigured = false;
    private $resolverConfigured = false;

    public function __construct(array $paths, $cacheDir = null, $debug = false)
    {
        $this->cacheDir   = $cacheDir;
        $this->debug      = $debug;
        $this->locator    = new FileLocator($paths);
        $this->normalizer = new ChainNormalizer;
        $this->resolver   = new LoaderResolver;
        $this->resources  = new ResourceCollection;
    }

    public static function create(array $paths, $cacheDir = null, $debug = false)
    {
        return new self($paths, $cacheDir, $debug);
    }

    public function configureNormalizers(callable $callable)
    {
        $this->normalizerConfigured = true;

        $callable($this->normalizer);
    }

    public function configureLoaders(callable $callable)
    {
        $this->resolverConfigured = true;

        $callable($this->resolver, $this->locator, $this->resources);
    }

    public function setCacheDir($cacheDir)
    {
        $this->cacheDir = $cacheDir;
    }

    public function setDebug($debug)
    {
        $this->debug = $debug;
    }

    public function build()
    {
        if (false == $this->resolverConfigured) {
            $this->addDefaultLoaders();
        }

        if (false == $this->normalizerConfigured) {
            $this->addDefaultNormalizers();
        }

        $loader = new CacheLoader($this->createNormalizerLoader(), $this->resources);
        $loader->setCacheDir($this->cacheDir);
        $loader->setDebug($this->debug);

        return $loader;
    }

    public function addDefaultLoaders()
    {
        $this->resolverConfigured = true;

        if (class_exists('Symfony\Component\Yaml\Yaml')) {
            $this->resolver->addLoader(new YamlFileLoader($this->locator, $this->resources));
        }

        $this->resolver->addLoader(new JsonFileLoader($this->locator, $this->resources));
        $this->resolver->addLoader(new PhpFileLoader($this->locator, $this->resources));
        $this->resolver->addLoader(new IniFileLoader($this->locator, $this->resources));
    }

    public function addDefaultNormalizers()
    {
        $this->normalizerConfigured = true;

        $this->normalizer->add(new EnvironmentNormalizer);
        $this->normalizer->add(new EnvfileNormalizer($this->locator));
    }

    private function createNormalizerLoader()
    {
        return new NormalizerLoader(new DelegatingLoader($this->resolver), $this->normalizer);
    }
}<commit_msg>return $this in all methods<commit_after><?php

namespace Tacker;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Tacker\Loader\CacheLoader;
use Tacker\Loader\IniFileLoader;
use Tacker\Loader\JsonFileLoader;
use Tacker\Loader\NormalizerLoader;
use Tacker\Loader\PhpFileLoader;
use Tacker\Loader\YamlFileLoader;
use Tacker\Normalizer\ChainNormalizer;
use Tacker\Normalizer\EnvfileNormalizer;
use Tacker\Normalizer\EnvironmentNormalizer;

/**
 * Helps building a Loader with Cache, Normalization etc.
 *
 * @package Tacker
 */
final class LoaderBuilder
{
    private $paths;
    private $normalizer;
    private $resolver;
    private $locator;
    private $debug;
    private $cacheDir;
    private $normalizerConfigured = false;
    private $resolverConfigured = false;

    public function __construct(array $paths, $cacheDir = null, $debug = false)
    {
        $this->cacheDir   = $cacheDir;
        $this->debug      = $debug;
        $this->locator    = new FileLocator($paths);
        $this->normalizer = new ChainNormalizer;
        $this->resolver   = new LoaderResolver;
        $this->resources  = new ResourceCollection;
    }

    public static function create(array $paths, $cacheDir = null, $debug = false)
    {
        return new self($paths, $cacheDir, $debug);
    }

    public function configureNormalizers(callable $callable)
    {
        $this->normalizerConfigured = true;

        $callable($this->normalizer);

        return $this;
    }

    public function configureLoaders(callable $callable)
    {
        $this->resolverConfigured = true;

        $callable($this->resolver, $this->locator, $this->resources);

        return $this;
    }

    public function setCacheDir($cacheDir)
    {
        $this->cacheDir = $cacheDir;

        return $this;
    }

    public function setDebug($debug)
    {
        $this->debug = $debug;

        return $this;
    }

    public function build()
    {
        if (false == $this->resolverConfigured) {
            $this->addDefaultLoaders();
        }

        if (false == $this->normalizerConfigured) {
            $this->addDefaultNormalizers();
        }

        $loader = new CacheLoader($this->createNormalizerLoader(), $this->resources);
        $loader->setCacheDir($this->cacheDir);
        $loader->setDebug($this->debug);

        return $loader;
    }

    public function addDefaultLoaders()
    {
        $this->resolverConfigured = true;

        if (class_exists('Symfony\Component\Yaml\Yaml')) {
            $this->resolver->addLoader(new YamlFileLoader($this->locator, $this->resources));
        }

        $this->resolver->addLoader(new JsonFileLoader($this->locator, $this->resources));
        $this->resolver->addLoader(new PhpFileLoader($this->locator, $this->resources));
        $this->resolver->addLoader(new IniFileLoader($this->locator, $this->resources));

        return $this;
    }

    public function addDefaultNormalizers()
    {
        $this->normalizerConfigured = true;

        $this->normalizer->add(new EnvironmentNormalizer);
        $this->normalizer->add(new EnvfileNormalizer($this->locator));

        return $this;
    }

    private function createNormalizerLoader()
    {
        return new NormalizerLoader(new DelegatingLoader($this->resolver), $this->normalizer);
    }
}
{'fraction_non_alphanumeric': 0.1247373161212849, 'fraction_numerical': 0.0, 'mean_word_length': 3.045537340619308, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '4081584', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1934, 'n_words': 370}