PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
← All changes | src/Helpers/ArrayDataSet.php +92 -98 2.31.12.13.1 View file →
@@ -1,112 +1,106 @@
1 1 <?php
2 2
3 3 namespace Give\Helpers;
4 4
5 -class ArrayDataSet
6 -{
7 - /**
8 - * This function will return array with renamed keys.
9 - *
10 - * This function only support one dimensional array.
11 - * You can pass a multi dimensional array but only zero level array keys will be renamed.
12 - *
13 - * @since 2.7.0
14 - *
15 - * @param array $renameTo Pass array of existing key name as key and new key name as value.
16 - *
17 - * @param array $array
18 - *
19 - * @return array
20 - */
21 - public static function renameKeys($array, $renameTo)
22 - {
23 - // Rename key if property name exist for them.
24 - foreach ($renameTo as $oldKey => $newKey) {
25 - if (array_key_exists($oldKey, $array)) {
26 - $array[$newKey] = $array[$oldKey];
27 - unset($array[$oldKey]);
28 - }
29 - }
5 +class ArrayDataSet {
6 + /**
7 + * This function will return array with renamed keys.
8 + *
9 + * This function only support one dimensional array.
10 + * You can pass a multi dimensional array but only zero level array keys will be renamed.
11 + *
12 + * @since 2.7.0
13 + *
14 + * @param array $renameTo Pass array of existing key name as key and new key name as value.
15 + *
16 + * @param array $array
17 + *
18 + * @return array
19 + */
20 + public static function renameKeys( $array, $renameTo ) {
21 + // Rename key if property name exist for them.
22 + foreach ( $renameTo as $oldKey => $newKey ) {
23 + if ( array_key_exists( $oldKey, $array ) ) {
24 + $array[ $newKey ] = $array[ $oldKey ];
25 + unset( $array[ $oldKey ] );
26 + }
27 + }
30 28
31 - return $array;
32 - }
29 + return $array;
30 + }
33 31
34 - /**
35 - * Return whether or not array contains required keys.
36 - *
37 - * This function only support one dimensional array.
38 - *
39 - * @since 2.7.0
40 - *
41 - * @param array $array
42 - * @param array $requiredKeys Array of required keys.
43 - *
44 - * @return bool
45 - */
46 - public static function hasRequiredKeys($array, $requiredKeys)
47 - {
48 - return (bool)array_intersect_key($array, array_flip($requiredKeys));
49 - }
32 + /**
33 + * Return whether or not array contains required keys.
34 + *
35 + * This function only support one dimensional array.
36 + *
37 + * @since 2.7.0
38 + *
39 + * @param array $array
40 + * @param array $requiredKeys Array of required keys.
41 + *
42 + * @return bool
43 + */
44 + public static function hasRequiredKeys( $array, $requiredKeys ) {
45 + return (bool) array_intersect_key( $array, array_flip( $requiredKeys ) );
46 + }
50 47
51 - /**
52 - * Return array with grouped under specific key.
53 - *
54 - * @param array $array
55 - * @param array $itemsToMove
56 - * @param string $arrayKey
57 - *
58 - * @return mixed
59 - */
60 - public static function moveArrayItemsUnderArrayKey($array, $itemsToMove, $arrayKey)
61 - {
62 - foreach ($itemsToMove as $key) {
63 - if (array_key_exists($key, $array)) {
64 - $array[$arrayKey][$key] = $array[$key];
65 - unset($array[$key]);
66 - }
67 - }
48 + /**
49 + * Return array with grouped under specific key.
50 + *
51 + * @param array $array
52 + * @param array $itemsToMove
53 + * @param string $arrayKey
54 + *
55 + * @return mixed
56 + */
57 + public static function moveArrayItemsUnderArrayKey( $array, $itemsToMove, $arrayKey ) {
58 + foreach ( $itemsToMove as $key ) {
59 + if ( array_key_exists( $key, $array ) ) {
60 + $array[ $arrayKey ][ $key ] = $array[ $key ];
61 + unset( $array[ $key ] );
62 + }
63 + }
68 64
69 - return $array;
70 - }
65 + return $array;
66 + }
71 67
72 - /**
73 - * Creates a new array from the old one with all of the index keys converted to camel case.
74 - * This is only intended for associative arrays.
75 - *
76 - * @since 2.8.0
77 - *
78 - * @param $array
79 - *
80 - * @return array
81 - */
82 - public static function camelCaseKeys($array)
83 - {
84 - $newArray = [];
85 68
86 - foreach ($array as $key => $value) {
87 - $studlyKey = ucwords(str_replace(['-', '_'], ' ', $key));
88 - $studlyKey = lcfirst(str_replace(' ', '', $studlyKey));
69 + /**
70 + * Creates a new array from the old one with all of the index keys converted to camel case.
71 + * This is only intended for associative arrays.
72 + *
73 + * @since 2.8.0
74 + *
75 + * @param $array
76 + *
77 + * @return array
78 + */
79 + public static function camelCaseKeys( $array ) {
80 + $newArray = [];
89 81
90 - $newArray[$studlyKey] = $value;
91 - }
82 + foreach ( $array as $key => $value ) {
83 + $studlyKey = ucwords( str_replace( [ '-', '_' ], ' ', $key ) );
84 + $studlyKey = lcfirst( str_replace( ' ', '', $studlyKey ) );
92 85
93 - return $newArray;
94 - }
86 + $newArray[ $studlyKey ] = $value;
87 + }
95 88
96 - /**
97 - * Creates a comma separated string and each value enclosed with single quote from array.
98 - *
99 - * @since 2.10.0
100 - *
101 - * @param array $array
102 - *
103 - * @return string
104 - */
105 - public static function getStringSeparatedByCommaEnclosedWithSingleQuote($array)
106 - {
107 - return sprintf(
108 - '\'%s\'',
109 - implode('\',\'', $array)
110 - );
111 - }
89 + return $newArray;
90 + }
91 +
92 + /**
93 + * Creates a comma separated string and each value enclosed with single quote from array.
94 + *
95 + * @since 2.10.0
96 + * @param array $array
97 + *
98 + * @return string
99 + */
100 + public static function getStringSeparatedByCommaEnclosedWithSingleQuote( $array ) {
101 + return sprintf(
102 + '\'%s\'',
103 + implode( '\',\'', $array )
104 + );
105 + }
112 106 }