• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

znframework / fullpack-edition / 8716966645

17 Apr 2024 05:48AM UTC coverage: 98.608% (-1.0%) from 99.589%
8716966645

push

github

zntr
Updated test.yml

10341 of 10487 relevant lines covered (98.61%)

33.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.9
/Internal/package-datatypes/Arrays.php
1
<?php namespace ZN\DataTypes;
2
/**
3
 * ZN PHP Web Framework
4
 * 
5
 * "Simplicity is the ultimate sophistication." ~ Da Vinci
6
 * 
7
 * @package ZN
8
 * @license MIT [http://opensource.org/licenses/MIT]
9
 * @author  Ozan UYKUN [ozan@znframework.com]
10
 */
11

12
use ZN\Datatype;
13
use ZN\Controller\Factory;
14
use ZN\Ability\Functionalization;
15

16
class Arrays extends Factory
17
{
18
    use Functionalization;
19

20
    const factory =
21
    [
22
        'methods' =>
23
        [
24
            'casing'                       => 'Arrays\Casing::use',
25
            'lowercase'                    => 'Arrays\Casing::lower',
26
            'uppercase'                    => 'Arrays\Casing::upper',
27
            'titlecase'                    => 'Arrays\Casing::title',
28
            'lowerkeys'                    => 'Arrays\Casing::lowerKeys',
29
            'upperkeys'                    => 'Arrays\Casing::upperKeys',
30
            'titlekeys'                    => 'Arrays\Casing::titleKeys',
31
            'lowervalues'                  => 'Arrays\Casing::lowerValues',
32
            'uppervalues'                  => 'Arrays\Casing::upperValues',
33
            'titlevalues'                  => 'Arrays\Casing::titleValues',
34
            'getfirst'                     => 'Arrays\GetElement::first',
35
            'getlast'                      => 'Arrays\GetElement::last',
36
            'pick'                         => 'Arrays\GetElement::pick',
37
            'addfirst'                     => 'Arrays\AddElement::first',
38
            'addlast'                      => 'Arrays\AddElement::last',
39
            'removekey'                    => 'Arrays\RemoveElement::key',
40
            'removevalue'                  => 'Arrays\RemoveElement::value',
41
            'remove'                       => 'Arrays\RemoveElement::use',
42
            'removelast'                   => 'Arrays\RemoveElement::last',
43
            'removefirst'                  => 'Arrays\RemoveElement::first',
44
            'deleteelement'                => 'Arrays\RemoveElement::element',
45
            'delete'                       => 'Arrays\RemoveElement::element',
46
            'order'                        => 'Arrays\Sort::order',
47
            'sort'                         => 'Arrays\Sort::normal',
48
            'descending'                   => 'Arrays\Sort::descending',
49
            'ascending'                    => 'Arrays\Sort::ascending',
50
            'ascendingkey'                 => 'Arrays\Sort::ascendingKey',
51
            'descendingkey'                => 'Arrays\Sort::descendingKey',
52
            'naturalinsensitive'           => 'Arrays\Sort::insensitive',
53
            'natural'                      => 'Arrays\Sort::natural',
54
            'shuffle'                      => 'Arrays\Sort::shuffle',
55
            'reverse'                      => 'Arrays\Sort::reverse',
56
            'including'                    => 'Arrays\Including::use',
57
            'include'                      => 'Arrays\Including::use',
58
            'excluding'                    => 'Arrays\Excluding::use',
59
            'exclude'                      => 'Arrays\Excluding::use',
60
            'each'                         => 'Arrays\Each::use',
61
            'force'                        => 'Arrays\Force::do',
62
            'forcevalues'                  => 'Arrays\Force::values',
63
            'forcekeys'                    => 'Arrays\Force::keys',
64
            'forcerecursive'               => 'Arrays\Force::recursive',
65
            'keyval'                       => 'Arrays\Element::use',
66
            'element'                      => 'Arrays\Element::use',
67
            'unidimensional'               => 'Arrays\Unidimensional::do',
68
            'flatten'                      => 'Arrays\Unidimensional::do',
69
            'searchbetween'                => 'Arrays\Search::between',
70
            'searchbetweenboth'            => 'Arrays\Search::betweenBoth',
71
            'searchkeybetween'             => 'Arrays\Search::betweenWithKey',
72
            'searchkeybetweenboth'         => 'Arrays\Search::betweenBothWithKey',
73
            'searchkeytovaluebetween'      => 'Arrays\Search::betweenWithKeyToValue',
74
            'searchvaluetokeybetween'      => 'Arrays\Search::betweenWithValueToKey',
75
            'searchkeytovaluebetweenboth'  => 'Arrays\Search::betweenBothWithKeyToValue',
76
            'searchvaluetokeybetweenboth'  => 'Arrays\Search::betweenBothWithValueToKey'
77
        ]
78
    ];
79

80
    /**
81
     * Functionalization
82
     * 
83
     * @var array
84
     */
85
    const functionalization = 
86
    [
87
        'merge'             => 'array_merge',
88
        'recursivemerge'    => 'array_merge_recursive',
89
        'flip'              => 'array_flip',
90
        'transform'         => 'array_flip',
91
        'unique'            => 'array_unique',
92
        'deleterecurrent'   => 'array_unique',
93
        'range'             => 'range',
94
        'series'            => 'range',
95
        'slice'             => 'array_slice',
96
        'section'           => 'array_slice',
97
        'splice'            => 'array_splice',
98
        'resection'         => 'array_splice',
99
        'rand'              => 'array_rand',
100
        'random'            => 'array_rand',
101
        'map'               => 'array_map',
102
        'implementcallback' => 'array_map',
103
        'count'             => 'count',
104
        'length'            => 'count',
105
        'column'            => 'array_column',
106
        'product'           => 'array_product',
107
        'sum'               => 'array_sum',
108
        'intersect'         => 'array_intersect',
109
        'intersectkey'      => 'array_intersect_key',
110
        'chunk'             => 'array_chunk',
111
        'apportion'         => 'array_chunk',
112
        'key'               => 'key',
113
        'current'           => 'current',
114
        'value'             => 'current',
115
        'values'            => 'array_values',
116
        'keys'              => 'array_keys'
117
    ];
118

119
    /**
120
     * Combine
121
     * 
122
     * @param array $keys
123
     * @param array $values = []
124
     * 
125
     * @return array
126
     */
127
    public static function combine(array $keys, array $values = []) : array
128
    {
129
        if( empty($values) )
2✔
130
        {
131
            $values = $keys;
2✔
132
        }
133

134
        return array_combine($keys, $values);
2✔
135
    }
136

137
    /**
138
     * Multiple Key
139
     * 
140
     * @param array  $array
141
     * @param string $keySplit = '|'
142
     * 
143
     * @return array
144
     */
145
    public static function multikey(array $array, string $keySplit = '|') : array
146
    {
147
        return Datatype::multikey($array, $keySplit);
2✔
148
    }
149

150
    /**
151
     * Value Exists
152
     * 
153
     * @param array $array
154
     * @param mixed $element
155
     * @param bool  $strict = false
156
     * 
157
     * @return bool
158
     */
159
    public static function valueExists(array $array, $element, bool $strict = false) : bool
160
    {
161
        return in_array($element, $array, $strict);
4✔
162
    }
163

164
    /**
165
     * Value Exists Insensitive
166
     * 
167
     * @param array $array
168
     * @param mixed $element
169
     * @param bool  $strict = false
170
     * 
171
     * @return bool
172
     */
173
    public static function valueExistsInsensitive(array $array, $element, bool $strict = false) : bool
174
    {
175
        return self::valueExists(array_map('strtolower', $array), strtolower($element ?? ''), $strict);
2✔
176
    }
177

178
    /**
179
     * Key Exists
180
     * 
181
     * @param array $array
182
     * @param mixed $key
183
     * 
184
     * @return bool
185
     */
186
    public static function keyExists(array $array, $key) : bool
187
    {
188
        return isset($array[$key]);
4✔
189
    }
190

191
    /**
192
     * Key Exists Insensitive
193
     * 
194
     * @param array $array
195
     * @param mixed $key
196
     * 
197
     * @return bool
198
     */
199
    public static function keyEsistsInsensitive(array $array, $key) : bool
200
    {
201
        return self::keyExists(array_change_key_case($array), strtolower($key ?? ''));
2✔
202
    }
203

204
    /**
205
     * Search
206
     * 
207
     * @param array $array
208
     * @param mixed $element
209
     * @param bool  $strict = false
210
     * 
211
     * @return bool
212
     */
213
    public static function search(array $array, $element, bool $strict = false)
214
    {
215
        return array_search($element, $array, $strict);
2✔
216
    }
217

218
    /**
219
     * Count Same Values
220
     * 
221
     * @param array $array
222
     * @param mixed $key = NULL
223
     * 
224
     * @return int|false
225
     */
226
    public static function countSameValues(array $array, string $key = NULL)
227
    {
228
        $return = array_count_values($array);
2✔
229

230
        if( ! empty($key) )
2✔
231
        {
232
            return $return[$key] ?? false;
2✔
233
        }
234

235
        return $return;
2✔
236
    }
237

238
    /**
239
     * Fil Keys Range
240
     * 
241
     * @param array
242
     * @param scalar $char = ''
243
     * @param mixed  $min  = NULL
244
     * @param mixed  $max  = NULL
245
     * 
246
     * @return array
247
     */
248
    public static function fillKeysRange(array $array, $char = '', $min = NULL, $max = NULL) : array
249
    {
250
        $rearray = [];
×
251
    
252
        if( ! $array )
×
253
        {
254
            return $rearray;
×
255
        }
256
    
257
        $keys = range($min ?? min(array_keys($array)), $max ?? max(array_keys($array)));
×
258
    
259
        foreach( $keys as $key ) 
×
260
        {
261
            $value = isset($array[$key]) ? $array[$key] : $char;
×
262
    
263
            $rearray[$key] = $value;
×
264
        }
265
    
266
        return $rearray;
×
267
    }
268
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc