<commit_before><?php

namespace ParserReflection\Locator;


use Composer\Autoload\ClassLoader;
use ParserReflection\LocatorInterface;

class ComposerLocator implements LocatorInterface
{
    /**
     * @var ClassLoader
     */
    private $loader;

    public function __construct(ClassLoader $loader)
    {
        $this->loader = $loader;
    }

    /**
     * Returns a path to the file for given class name
     *
     * @param string $className Name of the class
     *
     * @return string|false Path to the file with given class or false if not found
     */
    public function locateClass($className)
    {
        return $this->loader->findFile($className);
    }
}<commit_msg>Add auto-detection of composer loader from spl stack<commit_after><?php

namespace ParserReflection\Locator;


use Composer\Autoload\ClassLoader;
use ParserReflection\LocatorInterface;
use ParserReflection\ReflectionException;

class ComposerLocator implements LocatorInterface
{
    /**
     * @var ClassLoader
     */
    private $loader;

    public function __construct(ClassLoader $loader = null)
    {
        if (!$loader) {
            $loaders = spl_autoload_functions();
            foreach ($loaders as $loader) {
                if (is_array($loader) && $loader[0] instanceof ClassLoader) {
                    $loader = $loader[0];
                }
            }
            if (!$loader) {
                throw new ReflectionException("Can not found a correct composer loader");
            }
        }
        $this->loader = $loader;
    }

    /**
     * Returns a path to the file for given class name
     *
     * @param string $className Name of the class
     *
     * @return string|false Path to the file with given class or false if not found
     */
    public function locateClass($className)
    {
        return $this->loader->findFile($className);
    }
}
{'fraction_non_alphanumeric': 0.0928, 'fraction_numerical': 0.0010666666666666667, 'mean_word_length': 2.355992844364937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '498555', 'n_tokens_mistral': 508, 'n_tokens_neox': 499, 'n_words': 150}