<commit_before><?php
/**
 * Created by PhpStorm.
 * User: <NAME> <<EMAIL>>
 * Date: 3/14/17
 * Time: 6:14 PM
 */

namespace ItvisionSy\Laravel\Modules;

use DirectoryIterator;
use ErrorException;
use Exception;
use ItvisionSy\Laravel\Modules\Interfaces\KeyValueStoreInterface;
use ItvisionSy\Laravel\Modules\Interfaces\StaticAndInstanceAccessInterface;
use ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler;
use ItvisionSy\Laravel\Modules\Traits\StaticAndInstanceAccessTrait;
use SplFileInfo;

/**
 * Class Modules
 * @package App\Modules
 */
class Modules implements StaticAndInstanceAccessInterface
{

    use StaticAndInstanceAccessTrait;

    protected static $modules;
    protected static $filtered = [];
    protected static $storeHandler;

    public static function grantAccess()
    {
        return [
            'get', 'all', 'find', 'enabled', 'disabled', 'getStoreHandler', 'setStoreHandler', 'setStoredValue', 'getStoredValue'
        ];
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function isModuleEnabled(Module $module)
    {
        return (bool)@static::getStoredValue("module_is_enabled|" . $module->id(), config('modules.modules_enabled_by_default', 0));
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function disableModule(Module $module)
    {
        static::setStoredValue("module_is_enabled|" . $module->id(), 0);
        if (array_key_exists($module->id(), static::$filtered['enabled'])) {
            unset(static::$filtered['enabled'][$module->id()]);
        }
        static::$filtered['disabled'][$module->id()] = $module;
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function enableModule(Module $module)
    {
        static::setStoredValue("module_is_enabled|" . $module->id(), 1);
        if (array_key_exists($module->id(), static::$filtered['disabled'])) {
            unset(static::$filtered['disabled'][$module->id()]);
        }
        static::$filtered['enabled'][$module->id()] = $module;
    }

    /**
     * @param $key
     * @param null $default
     * @param Module $module
     * @return mixed
     */
    protected function getStoredValue($key, $default = null, Module $module = null)
    {
        return static::getStoreHandler()->get(($module ? $module->id() : config("modules.store_public_prefix_key", "modules")) . '|' . $key, $default);
    }

    /**
     * @param $key
     * @param null $value
     * @param Module $module
     * @return mixed
     */
    protected function setStoredValue($key, $value = null, Module $module = null)
    {
        return static::getStoreHandler()->set(($module ? $module->id() : config("modules.store_public_prefix_key", "modules")) . '|' . $key, $value);
    }

    /**
     * @return KeyValueStoreInterface
     * @throws ErrorException
     */
    protected static function getStoreHandler()
    {
        if (!static::$storeHandler) {
            $handler = config('modules.store_handler');
            if (!$handler) {
                $handler = SimpleDbStoreHandler::class;
            }
            if (is_callable($handler)) {
                $handler = $handler();
            }
            if (is_string($handler) && class_exists($handler)) {
                $handler = new $handler();
            }
            if (!is_object($handler) || !($handler instanceof KeyValueStoreInterface)) {<commit_msg>Fix store methods visiblity<commit_after><?php
/**
 * Created by PhpStorm.
 * User: <NAME> <<EMAIL>>
 * Date: 3/14/17
 * Time: 6:14 PM
 */

namespace ItvisionSy\Laravel\Modules;

use DirectoryIterator;
use ErrorException;
use Exception;
use ItvisionSy\Laravel\Modules\Interfaces\KeyValueStoreInterface;
use ItvisionSy\Laravel\Modules\Interfaces\StaticAndInstanceAccessInterface;
use ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler;
use ItvisionSy\Laravel\Modules\Traits\StaticAndInstanceAccessTrait;
use SplFileInfo;

/**
 * Class Modules
 * @package App\Modules
 */
class Modules implements StaticAndInstanceAccessInterface
{

    use StaticAndInstanceAccessTrait;

    protected static $modules;
    protected static $filtered = [];
    protected static $storeHandler;

    public static function grantAccess()
    {
        return [
            'get', 'all', 'find', 'enabled', 'disabled', 'getStoreHandler', 'setStoreHandler', 'setStoredValue', 'getStoredValue'
        ];
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function isModuleEnabled(Module $module)
    {
        return (bool)@static::getStoredValue("module_is_enabled|" . $module->id(), config('modules.modules_enabled_by_default', 0));
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function disableModule(Module $module)
    {
        static::setStoredValue("module_is_enabled|" . $module->id(), 0);
        if (array_key_exists($module->id(), static::$filtered['enabled'])) {
            unset(static::$filtered['enabled'][$module->id()]);
        }
        static::$filtered['disabled'][$module->id()] = $module;
    }

    /**
     * @param Module $module
     * @return mixed
     */
    public static function enableModule(Module $module)
    {
        static::setStoredValue("module_is_enabled|" . $module->id(), 1);
        if (array_key_exists($module->id(), static::$filtered['disabled'])) {
            unset(static::$filtered['disabled'][$module->id()]);
        }
        static::$filtered['enabled'][$module->id()] = $module;
    }

    /**
     * @param $key
     * @param null $default
     * @param Module $module
     * @return mixed
     */
    protected static function getStoredValue($key, $default = null, Module $module = null)
    {
        return static::getStoreHandler()->get(($module ? $module->id() : config("modules.store_public_prefix_key", "modules")) . '|' . $key, $default);
    }

    /**
     * @param $key
     * @param null $value
     * @param Module $module
     * @return mixed
     */
    protected static function setStoredValue($key, $value = null, Module $module = null)
    {
        return static::getStoreHandler()->set(($module ? $module->id() : config("modules.store_public_prefix_key", "modules")) . '|' . $key, $value);
    }

    /**
     * @return KeyValueStoreInterface
     * @throws ErrorException
     */
    protected static function getStoreHandler()
    {
        if (!static::$storeHandler) {
            $handler = config('modules.store_handler');
            if (!$handler) {
                $handler = SimpleDbStoreHandler::class;
            }
            if (is_callable($handler)) {
                $handler = $handler();
            }
            if (is_string($handler) && class_exists($handler)) {
                $handler = new $handler();
            }
            if (!is_object($handler) || !($handler instanceof KeyValueStoreInterface)) {
{'fraction_non_alphanumeric': 0.14927953890489915, 'fraction_numerical': 0.003170028818443804, 'mean_word_length': 2.873325892857143, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '7271337', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1994, 'n_words': 399}