<commit_before><?php
namespace Genkgo\Migrations;

use Closure;
use Genkgo\Migrations\Utils\FileList;
use InvalidArgumentException;

/**
 * Class Factory
 * @package Genkgo\Migrations
 */
class Factory
{
    /**
     *
     * @var AdapterInterface
     */
    
    private $adapter;

    /**
     * @var Closure
     */

    private $classLoader;
    
    /**
     *
     * @param AdapterInterface $adapter
     * @param Closure $classLoader
     */
    
    public function __construct(AdapterInterface $adapter, Closure $classLoader = null)
    {
        $this->adapter = $adapter;
        $this->setClassLoader($classLoader);
    }

    /**
     * @param callable $classLoader
     */

    public function setClassLoader(Closure $classLoader = null)
    {
        if (null === $classLoader) {
            $classLoader = function ($classname) {
                return new $classname;
            };
        }
        $this->classLoader = $classLoader;
    }

    /**
     * @param string $namespace
     * @return Collection
     */

    public function newList($namespace = '\\')
    {
        if (substr($namespace, -1) !== '\\') {
            throw new InvalidArgumentException('Namespace incorrect, follow psr-4 namespace rules. Do not forget trailing slashes');
        }
        return (new Collection($this->adapter))->setNamespace($namespace);
    }

    /**
     * @param string $directory
     * @param string $namespace
     * @return Collection
     */

    public function newListFromDirectory($directory, $namespace = '\\')
    {
        $collection = $this->newList($namespace);
        $classloader = $this->classLoader;

        $files = FileList::fromDirectory($directory);
        foreach ($files as $file) {
            require_once $file;
            $classname = basename($file, '.php');
            $fullname = $namespace . $classname;

            if (is_a($fullname, MigrationInterface::class, true)) {
                $collection->attach($classloader($fullname));
            }
        }

        return $collection;
    }
}
<commit_msg>Replace MigrationInterface::class with fqn name for PHP 5.4 compatibility<commit_after><?php
namespace Genkgo\Migrations;

use Closure;
use Genkgo\Migrations\Utils\FileList;
use InvalidArgumentException;

/**
 * Class Factory
 * @package Genkgo\Migrations
 */
class Factory
{
    /**
     *
     * @var AdapterInterface
     */

    private $adapter;

    /**
     * @var Closure
     */

    private $classLoader;

    /**
     *
     * @param AdapterInterface $adapter
     * @param Closure $classLoader
     */

    public function __construct(AdapterInterface $adapter, Closure $classLoader = null)
    {
        $this->adapter = $adapter;
        $this->setClassLoader($classLoader);
    }

    /**
     * @param callable $classLoader
     */

    public function setClassLoader(Closure $classLoader = null)
    {
        if (null === $classLoader) {
            $classLoader = function ($classname) {
                return new $classname;
            };
        }
        $this->classLoader = $classLoader;
    }

    /**
     * @param string $namespace
     * @return Collection
     */

    public function newList($namespace = '\\')
    {
        if (substr($namespace, -1) !== '\\') {
            throw new InvalidArgumentException('Namespace incorrect, follow psr-4 namespace rules. Do not forget trailing slashes');
        }
        return (new Collection($this->adapter))->setNamespace($namespace);
    }

    /**
     * @param string $directory
     * @param string $namespace
     * @return Collection
     */

    public function newListFromDirectory($directory, $namespace = '\\')
    {
        $collection = $this->newList($namespace);
        $classloader = $this->classLoader;

        $files = FileList::fromDirectory($directory);
        foreach ($files as $file) {
            require_once $file;
            $classname = basename($file, '.php');
            $fullname = $namespace . $classname;

            if (is_a($fullname, "\Genkgo\Migrations\MigrationInterface", true)) {
                $collection->attach($classloader($fullname));
            }
        }

        return $collection;
    }
}

{'fraction_non_alphanumeric': 0.12833969465648856, 'fraction_numerical': 0.0014312977099236641, 'mean_word_length': 2.140823970037453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '6838037', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1144, 'n_words': 252}