From 218c8563a346c180040364caa731e227b7eb0b10 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 18 Nov 2014 12:45:33 -0500 Subject: [PATCH] CRM_Utils_Array - Remove old unused functions --- CRM/Utils/Array.php | 150 +------------------------- tests/phpunit/CRM/Utils/ArrayTest.php | 18 ---- 2 files changed, 1 insertion(+), 167 deletions(-) diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 39d2245aad..b10a5cff86 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -368,102 +368,6 @@ class CRM_Utils_Array { return TRUE; } - /** - * Recursively copies all values of an array into a new array. - * - * If the recursion depth limit is exceeded, the deep copy appears to - * succeed, but the copy process past the depth limit will be shallow. - * - * @params array $array - * The array to copy. - * @params int $maxdepth - * (optional) Recursion depth limit. - * @params int $depth - * (optional) Current recursion depth. - * - * @param $array - * @param int $maxdepth - * @param int $depth - * - * @return array - * The new copy of $array. - * - * @access public - */ - static function array_deep_copy(&$array, $maxdepth = 50, $depth = 0) { - if ($depth > $maxdepth) { - return $array; - } - $copy = array(); - foreach ($array as $key => $value) { - if (is_array($value)) { - array_deep_copy($value, $copy[$key], $maxdepth, ++$depth); - } - else { - $copy[$key] = $value; - } - } - return $copy; - } - - /** - * Makes a shallow copy of a variable, returning the copy by value. - * - * In some cases, functions return an array by reference, but we really don't - * want to receive a reference. - * - * @param $array mixed - * Something to return a copy of. - * @return mixed - * The copy. - * @access public - */ - static function breakReference($array) { - $copy = $array; - return $copy; - } - - /** - * Removes a portion of an array. - * - * This function is similar to PHP's array_splice(), with some differences: - * - Array keys that are not removed are preserved. The PHP built-in - * function only preserves values. - * - The portion of the array to remove is specified by start and end - * index rather than offset and length. - * - There is no ability to specify data to replace the removed portion. - * - * The behavior given an associative array would probably not be useful. - * - * @param array $params - * Array to manipulate. - * @param int $start - * First index to remove. - * @param int $end - * Last index to remove. - * - * @access public - */ - static function crmArraySplice(&$params, $start, $end) { - // verify start and end index - if ($start < 0) { - $start = 0; - } - if ($end > count($params)) { - $end = count($params); - } - - $i = 0; - - // procees unset operation - foreach ($params as $key => $value) { - if ($i >= $start && $i < $end) { - unset($params[$key]); - } - $i++; - } - } - /** * Searches an array recursively in an optionally case-insensitive manner. * @@ -568,37 +472,6 @@ class CRM_Utils_Array { return TRUE; } - /** - * Determines the maximum depth of nested arrays in a multidimensional array. - * - * The mechanism for determining depth will be confused if the array - * contains keys or values with the left brace '{' character. This will - * cause the depth to be over-reported. - * - * @param array $array - * The array to examine. - * - * @return integer - * The maximum nested array depth found. - * - * @access public - */ - static function getLevelsArray($array) { - if (!is_array($array)) { - return 0; - } - $jsonString = json_encode($array); - $parts = explode("}", $jsonString); - $max = 0; - foreach ($parts as $part) { - $countLevels = substr_count($part, "{"); - if ($countLevels > $max) { - $max = $countLevels; - } - } - return $max; - } - /** * Sorts an associative array of arrays by an attribute using strnatcmp(). * @@ -749,27 +622,6 @@ class CRM_Utils_Array { return $result; } - /** - * Generate a string representation of an array. - * - * @param array $pairs - * Array to stringify. - * @param string $l1Delim - * String to use to separate key/value pairs from one another. - * @param string $l2Delim - * String to use to separate keys from values within each key/value pair. - * - * @return string - * Generated string. - */ - static function implodeKeyValue($l1Delim, $l2Delim, $pairs) { - $exprs = array(); - foreach ($pairs as $key => $value) { - $exprs[] = $key . $l2Delim . $value; - } - return implode($l1Delim, $exprs); - } - /** * Trims delimiters from a string and then splits it using explode(). * @@ -945,7 +797,7 @@ class CRM_Utils_Array { } /** - * Get the first elemnet of an array + * Get the first element of an array * * @param array $array * @return mixed|NULL diff --git a/tests/phpunit/CRM/Utils/ArrayTest.php b/tests/phpunit/CRM/Utils/ArrayTest.php index a346dfa79d..ced61fc279 100644 --- a/tests/phpunit/CRM/Utils/ArrayTest.php +++ b/tests/phpunit/CRM/Utils/ArrayTest.php @@ -5,24 +5,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * Class CRM_Utils_ArrayTest */ class CRM_Utils_ArrayTest extends CiviUnitTestCase { - function testBreakReference() { - // Get a reference and make a change - $fooRef1 = self::returnByReference(); - $this->assertEquals('original', $fooRef1['foo']); - $fooRef1['foo'] = 'modified'; - - // Make sure that the referenced item was actually changed - $fooRef2 = self::returnByReference(); - $this->assertEquals('modified', $fooRef1['foo']); - $this->assertEquals('original', $fooRef2['foo']); - - // Get a non-reference, make a change, and make sure the references were unaffected. - $fooNonReference = CRM_Utils_Array::breakReference(self::returnByReference()); - $fooNonReference['foo'] = 'privately-modified'; - $this->assertEquals('modified', $fooRef1['foo']); - $this->assertEquals('original', $fooRef2['foo']); - $this->assertEquals('privately-modified', $fooNonReference['foo']); - } /** * @return null -- 2.25.1