<commit_before><?php
/**
 * Detects the user's current active plugins that Shirshu supports
 *
 * Class PluginDetector
 */
class PluginDetector {
    /**
     * A list of Shirshu supported plugins
     *
     * @var array of strings
     */
    private $supportedPlugins = null;

    /**
     * PluginDetector constructor.
     * @param $supportedPlugins
     */
    public function __construct($supportedPlugins) {
        $this->supportedPlugins = $supportedPlugins;
    }

    /**
     * Determines the user's current active plugins that Shirshu supports
     *
     * @return array of strings
     */
    public function getActivePlugins() {
        $plugins = get_option('active_plugins');
        $plugin_keys = array_keys($this->supportedPlugins);
        $activePlugins = array();

        foreach ($plugin_keys as $key) {
            foreach ($plugins as $plugin) {
                if ($this->supportedPlugins[$key] == substr($plugin, 0, strpos($plugin, '/'))) {
                    array_push($activePlugins, $key);
                }
            }
        }

        return $activePlugins;
    }
}<commit_msg>Modified the approach of detecting active plugins to check if a constant or a function exists or not. The reason of avoiding using get_option() is that the get_option() renders the directory name of the active plugin. But there exists edge cases when the directory name may be different based on different setup of the plugin.<commit_after><?php
/**
 * Detects the user's current active plugins that Shirshu supports
 *
 * Class PluginDetector
 */
class PluginDetector {
    /**
     * A list of Shirshu supported plugins
     *
     * @var array of strings
     */
    private $supportedPlugins = null;

    /**
     * PluginDetector constructor.
     * @param $supportedPlugins
     */
    public function __construct($supportedPlugins) {
        $this->supportedPlugins = $supportedPlugins;
    }

    /**
     * Determines the user's current active plugins that Shirshu supports
     *
     * @return array of strings
     */
    public function getActivePlugins() {
        $plugin_keys = array_keys($this->supportedPlugins);
        $activePlugins = array();

        foreach ($plugin_keys as $key) {
            if (defined($this->supportedPlugins[$key]) || function_exists($this->supportedPlugins[$key])) {
                array_push($activePlugins, $key);
            }
        }

        return $activePlugins;
    }
}
{'fraction_non_alphanumeric': 0.10053126277073968, 'fraction_numerical': 0.0004086636697997548, 'mean_word_length': 2.4674220963172804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '7184041', 'n_tokens_mistral': 662, 'n_tokens_neox': 635, 'n_words': 196}