<commit_before><?php namespace Pingpong\Modules;

use Countable;
use Illuminate\Foundation\Application;
use Illuminate\Support\Str;
use Pingpong\Modules\Contracts\RepositoryInterface;
use Pingpong\Modules\Exceptions\ModuleNotFoundException;

class Repository implements RepositoryInterface, Countable {

    /**
     * Application instance.
     *
     * @var Application
     */
    protected $app;

    /**
     * The module path.
     *
     * @var string|null
     */
    protected $path;

    /**
     * The constructor.
     *
     * @param Application $app
     * @param string|null $path
     */
    public function __construct(Application $app, $path = null)
    {
        $this->app = $app;
        $this->path = $path;
    }

    /**
     * Get all modules.
     *
     * @return array
     */
    public function all()
    {
        $modules = [];

        if ( ! $this->app['files']->isDirectory($path = $this->getPath())) return $modules;

        $directories = $this->app['files']->directories($path);

        foreach ($directories as $module)
        {
            if ( ! Str::startsWith($name = basename($module), '.'))
            {
                $modules[$name] = new Module($this->app, $name, $module);
            }
        }

        return $modules;
    }

    /**
     * Get modules by status.
     *
     * @param $status
     * @return array
     */
    public function getByStatus($status)
    {
        $modules = [];

        foreach ($this->all() as $name => $module)
        {
            if ($module->isStatus($status))
            {
                $modules[$name] = $modules;
            }
        }

        return $modules;
    }

    /**
     * Determine whether the given module exist.
     *
     * @param $name
     * @return bool
     */
    public function has($name)
    {
        return array_key_exists($name, $this->all());
    }

    /**
     * Get list of enabled modules.
     *
     * @return array
     */
    public function enabled()
    {
        return $this->getByStatus(1);
    }

    /**
     * Get list of disabled modules.
     *
     * @return array
     */
    public function disabled()
    {
        return $this->getByStatus(0);
    }

    /**
     * Get count from all modules.
     *
     * @return int
     */
    public function count()
    {
        return count($this->all());
    }

    /**
     * Get all ordered modules.
     *
     * @return array
     */
    public function getOrdered()
    {
        $modules = $this->all();

        uasort($modules, function ($a, $b)
        {
            if ($a->priority == $b->priority)
            {
                return 0;
            }

            return $a->priority < $b->priority ? -1 : 1;
        });

        return $modules;
    }

    /**
     * Get a module path.
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path ?: $this->app['config']->get('modules::paths.modules');
    }
<commit_msg>Fix module priority feature<commit_after><?php namespace Pingpong\Modules;

use Countable;
use Illuminate\Foundation\Application;
use Illuminate\Support\Str;
use Pingpong\Modules\Contracts\RepositoryInterface;
use Pingpong\Modules\Exceptions\ModuleNotFoundException;

class Repository implements RepositoryInterface, Countable {

    /**
     * Application instance.
     *
     * @var Application
     */
    protected $app;

    /**
     * The module path.
     *
     * @var string|null
     */
    protected $path;

    /**
     * The constructor.
     *
     * @param Application $app
     * @param string|null $path
     */
    public function __construct(Application $app, $path = null)
    {
        $this->app = $app;
        $this->path = $path;
    }

    /**
     * Get all modules.
     *
     * @return array
     */
    public function all()
    {
        $modules = [];

        if ( ! $this->app['files']->isDirectory($path = $this->getPath())) return $modules;

        $directories = $this->app['files']->directories($path);

        foreach ($directories as $module)
        {
            if ( ! Str::startsWith($name = basename($module), '.'))
            {
                $modules[$name] = new Module($this->app, $name, $module);
            }
        }

        return $modules;
    }

    /**
     * Get modules by status.
     *
     * @param $status
     * @return array
     */
    public function getByStatus($status)
    {
        $modules = [];

        foreach ($this->all() as $name => $module)
        {
            if ($module->isStatus($status))
            {
                $modules[$name] = $modules;
            }
        }

        return $modules;
    }

    /**
     * Determine whether the given module exist.
     *
     * @param $name
     * @return bool
     */
    public function has($name)
    {
        return array_key_exists($name, $this->all());
    }

    /**
     * Get list of enabled modules.
     *
     * @return array
     */
    public function enabled()
    {
        return $this->getByStatus(1);
    }

    /**
     * Get list of disabled modules.
     *
     * @return array
     */
    public function disabled()
    {
        return $this->getByStatus(0);
    }

    /**
     * Get count from all modules.
     *
     * @return int
     */
    public function count()
    {
        return count($this->all());
    }

    /**
     * Get all ordered modules.
     *
     * @return array
     */
    public function getOrdered()
    {
        $modules = $this->all();

        uasort($modules, function ($a, $b)
        {
            if ($a->priority == $b->priority)
            {
                return 0;
            }

            return $a->priority < $b->priority ? 1 : -1;
        });


        return $modules;
    }

    /**
     * Get a module path.
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path ?: $this->app['config']->get('modules::paths.modules');
    }

{'fraction_non_alphanumeric': 0.14197012921631147, 'fraction_numerical': 0.0016781339150864238, 'mean_word_length': 1.581203984408835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, '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': '230481', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1739, 'n_words': 389}