<commit_before><?php

namespace Parvula;

use Parvula\Exceptions\BadObjectCallException;

/**
 * Plugin Mediator class to handle plugins
 *
 * @package Parvula
 * @version 0.5.0
 * @since 0.4.0
 * @author <NAME>
 * @license MIT License
 */
class PluginMediator {
	/**
	 * @var array Plugins container
	 */
	protected $plugins = [];

	/**
	 * Attach new plugins
	 *
	 * @param array $plugins
	 * @throws BadObjectCallException
	 */
	public function attach(array $plugins) {
		foreach ($plugins as $plugin) {
			if (is_string($plugin)) {
				if (!class_exists($plugin)) {
					throw new BadObjectCallException('Plugin class `' . $plugin . '` not found');
				}
				$plugin = new $plugin;
			}

			if (is_object($plugin)) {
				$id = get_class($plugin);
				if (!isset($this->plugins[$id])) {
					$this->plugins[$id] = $plugin;
				}
			}
		}

		return $this;
	}

	/**
	 * Trigger an event
	 *
	 * @param string $event Event name
	 * @param array ($args) Arguments
	 */
	public function trigger($event, array $args = []) {
		$event = 'on' . ucfirst($event);
		foreach ($this->plugins as $plugin) {
			if (method_exists($plugin, $event)) {
				$this->callFunctionArray($plugin, $event, $args);
			}
		}
	}

	/**
	 * Get specific plugin
	 *
	 * @param string $className
	 * @return Plugin Specific plugin
	 */
	public function &getPlugin($className) {
		return $this->plugins[$className];
	}

	/**
	 * Call function (alias for call_user_func_array)
	 *
	 * @param Object $obj Object
	 * @param callable|string $fun Function
	 * @param array $args Arguments
	 */
	private function callFunctionArray($obj, $fun, array $args) {
		switch (count($args)) {
			case 0:
				$obj->{$fun}();
				break;
			case 1:
				$obj->{$fun}($args[0]);
				break;
			case 2:
				$obj->{$fun}($args[0], $args[1]);
				break;
			case 3:
				$obj->{$fun}($args[0], $args[1], $args[2]);
				break;
			default:
				call_user_func_array([$obj, $fun], $args);
				break;
		}
	}
}<commit_msg>Use php 5.6 argument unpacking<commit_after><?php

namespace Parvula;

use Parvula\Exceptions\BadObjectCallException;

/**
 * Plugin Mediator class to handle plugins
 *
 * @package Parvula
 * @version 0.5.0
 * @since 0.4.0
 * @author <NAME>
 * @license MIT License
 */
class PluginMediator {
	/**
	 * @var array Plugins container
	 */
	protected $plugins = [];

	/**
	 * Attach new plugins
	 *
	 * @param array $plugins
	 * @throws BadObjectCallException
	 */
	public function attach(array $plugins) {
		foreach ($plugins as $plugin) {
			if (is_string($plugin)) {
				if (!class_exists($plugin)) {
					throw new BadObjectCallException('Plugin class `' . $plugin . '` not found');
				}
				$plugin = new $plugin;
			}

			if (is_object($plugin)) {
				$id = get_class($plugin);
				if (!isset($this->plugins[$id])) {
					$this->plugins[$id] = $plugin;
				}
			}
		}

		return $this;
	}

	/**
	 * Trigger an event
	 *
	 * @param string $event Event name
	 * @param array ($args) Arguments
	 */
	public function trigger($event, array $args = []) {
		$event = 'on' . ucfirst($event);
		foreach ($this->plugins as $plugin) {
			if (method_exists($plugin, $event)) {
				$plugin->$event(...$args);
			}
		}
	}

	/**
	 * Get specific plugin
	 *
	 * @param string $className
	 * @return Plugin Specific plugin
	 */
	public function &getPlugin($className) {
		return $this->plugins[$className];
	}
}
{'fraction_non_alphanumeric': 0.167262969588551, 'fraction_numerical': 0.007155635062611807, 'mean_word_length': 3.111519607843137, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7563757', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1112, 'n_words': 281}