<commit_before><?php
/**
 * PrettyArray
 * 
 * An object oriented approach to array development.
 * 
 * @author <NAME> <<EMAIL>>
 */

// Dependencies
include('enumerator.php');

/**
 * PrettyArray
 * 
 * This class does not have very much in it, and is planning on staying that way. Instead, it makes magic calls to the 'enumerator' class.
 * All methods in enumerator are static, which allows this class to call them statically or non-statically making PrettyArray very versatile.
 * When you are calling methods in enumerator it will always append the current array to the paramater list.
 * 
 * @see PrettyArray::__call()
 * @see PrettyArray::__callStatic()
 */
class PrettyArray implements ArrayAccess {

	/**
	 * The real data
	 */
	protected $data = array();
	
	/**
	 * Currently only one mixin, but this might change.
	 */
	protected static $mixins = 'enumerator';
	
	/**
	 * Remaps non-destructive methods to their destructive counter parts.
	 */
	protected static $destructiveMap = array(
		'getRange' => 'getRange_',
		'getSet' => 'getSet_'
	);

	/**
	 * The default array can be passed as the first argument in the constructor.
	 * @param array optional $defaults 
	 */
	public function __construct(array $defaults = array()) {
		$this->data = $defaults;
	}


	/**
	 * Method: offsetSet
	 * 
	 * Part of ArrayAccess. Allows PrettyArray to set a value based on the [] operator.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[] = 'new'; // magic of this method
	 * $arr->offsetSet(null, 2);
	 * </code>
	 * 
	 * @param mixed $key 
	 * @param mixed $value 
	 * @return $value
	 */
	public function offsetSet($key, $value) {
		if(is_null($key)) {
			$this->data[] = $value;
		} else {
			$this->data[$key] = $value;
		}
		return $value;
	}

	/**
	 * Method: offsetExists
	 * 
	 * Part of ArrayAccess. If the offest exists.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * var_dump(isset($arr[0])); // true
	 * var_dump($arr->offsetExists(0)); // true
	 * </code>
	 * 
	 * @param mixed $key 
	 * @return boolean
	 */
	public function offsetExists($key) {
		return (isset($this->data[$key]));
	}

	/**
	 * Method: offsetUnset
	 * 
	 * Part of ArrayAccess. Will unset the value if it exists.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * unset($arr[0]);
	 * $arr[1] = 'foo';
	 * $arr->offsetUnset(1);
	 * print_r($arr); // array()
	 * </code>
	 * 
	 * @param mixed $key 
	 * @return void
	 */
	public function offsetUnset($key) {
		if(isset($this->data[$key])) {
			unset($this->data[$key]);
		}
		return;
	}

	/**
	 * Method: offsetGet
	 * 
	 * Part of ArrayAccess. Will get the value of the current offset.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * echo $arr[0]; // foobar
	 * echo $arr->offsetGet(0); // foobar
	 * </code>
	 * 
	 * @param type $key 
	 * @return type
	 */
	public function offsetGet($key) {
		return (isset($this->data[$key])) ? $this->data[$key] : null;
	}

	/**
	 * Methods: __call
	 * 
	 * This serves two purposes.
	 * The first is that it helps the destructive methods in this class become non-destructive giving them aliases.
	 * The second is that is also proxies/mixins the static enumerable methods to non-static calls on this class and appends the current array as the first param.
	 * 
	 * <code>
	 * $arr = [1,2,3];
	 * enumerator::collect_($arr, function($key, &$value) {
	 * 	$value++;
	 * 	return;
	 * });
	 * print_r($arr); // 2,3,4
	 * 
	 * $arr = new PrettyArray($arr);
	 * $arr->collect_(function($key, &$value) {
	 * 	$value--;
	 * 	return;
	 * });
	 * print_r($arr); // 1,2,3
	 * </code>
	 * 
	 * @param string $method 
	 * @param array $params 
	 * @return mixed
	 */
	public function __call($method, $params) {

		if(isset(self::$destructiveMap[$method])) {
			// Destructive
			$ret = call_user_func_array(array($this, self::$destructiveMap[$method]), $params);
		} else {
			// Mixin
			$isDestructive = (substr($method, -1) == '_');
			if($isDestructive) {
				array_unshift($params, 0);
				$params[0] =& $this->data;
			} else {
				array_unshift($params, $this->data);
			}
			$ret = call_user_func_array(array(self::$mixins, $method), $params);
		}
		return $ret;
	}

	/**
	 * Methods: __callStatic
	 * 
	 * A basic proxy for static methods on enumerator.
	 * <commit_msg>__call returns PrettyArray instead of arrays<commit_after><?php
/**
 * PrettyArray
 * 
 * An object oriented approach to array development.
 * 
 * @author <NAME> <<EMAIL>>
 */

// Dependencies
include('enumerator.php');

/**
 * PrettyArray
 * 
 * This class does not have very much in it, and is planning on staying that way. Instead, it makes magic calls to the 'enumerator' class.
 * All methods in enumerator are static, which allows this class to call them statically or non-statically making PrettyArray very versatile.
 * When you are calling methods in enumerator it will always append the current array to the paramater list.
 * 
 * @see PrettyArray::__call()
 * @see PrettyArray::__callStatic()
 */
class PrettyArray implements ArrayAccess {

	/**
	 * The real data
	 */
	protected $data = array();
	
	/**
	 * Currently only one mixin, but this might change.
	 */
	protected static $mixins = 'enumerator';
	
	/**
	 * Remaps non-destructive methods to their destructive counter parts.
	 */
	protected static $destructiveMap = array(
		'getRange' => 'getRange_',
		'getSet' => 'getSet_'
	);

	/**
	 * The default array can be passed as the first argument in the constructor.
	 * @param array optional $defaults 
	 */
	public function __construct(array $defaults = array()) {
		$this->data = $defaults;
	}


	/**
	 * Method: offsetSet
	 * 
	 * Part of ArrayAccess. Allows PrettyArray to set a value based on the [] operator.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[] = 'new'; // magic of this method
	 * $arr->offsetSet(null, 2);
	 * </code>
	 * 
	 * @param mixed $key 
	 * @param mixed $value 
	 * @return $value
	 */
	public function offsetSet($key, $value) {
		if(is_null($key)) {
			$this->data[] = $value;
		} else {
			$this->data[$key] = $value;
		}
		return $value;
	}

	/**
	 * Method: offsetExists
	 * 
	 * Part of ArrayAccess. If the offest exists.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * var_dump(isset($arr[0])); // true
	 * var_dump($arr->offsetExists(0)); // true
	 * </code>
	 * 
	 * @param mixed $key 
	 * @return boolean
	 */
	public function offsetExists($key) {
		return (isset($this->data[$key]));
	}

	/**
	 * Method: offsetUnset
	 * 
	 * Part of ArrayAccess. Will unset the value if it exists.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * unset($arr[0]);
	 * $arr[1] = 'foo';
	 * $arr->offsetUnset(1);
	 * print_r($arr); // array()
	 * </code>
	 * 
	 * @param mixed $key 
	 * @return void
	 */
	public function offsetUnset($key) {
		if(isset($this->data[$key])) {
			unset($this->data[$key]);
		}
		return;
	}

	/**
	 * Method: offsetGet
	 * 
	 * Part of ArrayAccess. Will get the value of the current offset.
	 * 
	 * <code>
	 * $arr = new PrettyArray();
	 * $arr[0] = 'foobar';
	 * echo $arr[0]; // foobar
	 * echo $arr->offsetGet(0); // foobar
	 * </code>
	 * 
	 * @param type $key 
	 * @return type
	 */
	public function offsetGet($key) {
		return (isset($this->data[$key])) ? $this->data[$key] : null;
	}

	/**
	 * Methods: __call
	 * 
	 * This serves two purposes.
	 * The first is that it helps the destructive methods in this class become non-destructive giving them aliases.
	 * The second is that is also proxies/mixins the static enumerable methods to non-static calls on this class and appends the current array as the first param.
	 * 
	 * <code>
	 * $arr = [1,2,3];
	 * enumerator::collect_($arr, function($key, &$value) {
	 * 	$value++;
	 * 	return;
	 * });
	 * print_r($arr); // 2,3,4
	 * 
	 * $arr = new PrettyArray($arr);
	 * $arr->collect_(function($key, &$value) {
	 * 	$value--;
	 * 	return;
	 * });
	 * print_r($arr); // 1,2,3
	 * </code>
	 * 
	 * @param string $method 
	 * @param array $params 
	 * @return mixed
	 */
	public function __call($method, $params) {

		if(isset(self::$destructiveMap[$method])) {
			// Destructive
			$ret = call_user_func_array(array($this, self::$destructiveMap[$method]), $params);
		} else {
			// Mixin
			$isDestructive = (substr($method, -1) == '_');
			if($isDestructive) {
				array_unshift($params, 0);
				$params[0] =& $this->data;
			} else {
				array_unshift($params, $this->data);
			}
			$ret = call_user_func_array(array(self::$mixins, $method), $params);
		}
		if(is_array($ret)) {
			$ret = new PrettyArray($ret);
		}
		return $ret;
	}

	/**
	 * Methods: __callStatic
	 * 
	 * A basic proxy for static methods on enumerator.
	 * 
{'fraction_non_alphanumeric': 0.16351552652687062, 'fraction_numerical': 0.005270998052022459, 'mean_word_length': 3.067101584342964, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 63, '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': '1947796', 'n_tokens_mistral': 3234, 'n_tokens_neox': 2817, 'n_words': 833}