Completed
Push — master ( 13f9e5...7af3da )
by Lars
60:17
created

Arrayy::mergePrependNewIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Arrayy;
4
5
use ArrayAccess;
6
use voku\helper\UTF8;
7
8
/**
9
 * Methods to manage arrays.
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
class Arrayy extends ArrayyAbstract implements \Countable, \IteratorAggregate, \ArrayAccess
15
{
16
  /**
17
   * Initializes
18
   *
19
   * @param array $array
20
   */
21 352
  public function __construct($array = array())
22
  {
23 352
    if (!$array) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $array of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
24 71
      $array = array();
25 71
    }
26
27
    if (
28 352
        is_string($array)
29
        ||
30 352
        (is_object($array) && method_exists($array, '__toString'))
31 352
    ) {
32 1
      $array = (array)$array;
33 1
    }
34
35 352
    if (!is_array($array)) {
36 2
      throw new \InvalidArgumentException(
37
          'Passed value must be a array'
38 2
      );
39
    }
40
41 350
    $this->array = $array;
42 350
  }
43
44
  /**
45
   * magic to string
46
   *
47
   * @return string
48
   */
49 14
  public function __toString()
50
  {
51 14
    return $this->implode(',');
52
  }
53
54
  /**
55
   * Get a data by key
56
   *
57
   * @param $key
58
   *
59
   * @return mixed
60
   */
61
  public function &__get($key)
62
  {
63
    return $this->array[$key];
64
  }
65
66
  /**
67
   * Assigns a value to the specified data
68
   *
69
   * @param $key
70
   * @param $value
71
   */
72
  public function __set($key, $value)
73
  {
74
    $this->array[$key] = $value;
75
  }
76
77
  /**
78
   * Whether or not an data exists by key
79
   *
80
   * @param $key
81
   *
82
   * @return bool
83
   */
84
  public function __isset($key)
85
  {
86
    return isset($this->array[$key]);
87
  }
88
89
  /**
90
   * Unsets an data by key
91
   *
92
   * @param mixed $key
93
   */
94
  public function __unset($key)
95
  {
96
    unset($this->array[$key]);
97
  }
98
99
  /**
100
   * Assigns a value to the specified offset
101
   *
102
   *
103
   * @param mixed $offset
104
   * @param mixed $value
105
   */
106 1
  public function offsetSet($offset, $value)
107
  {
108 1
    if (null === $offset) {
109
      $this->array[] = $value;
110
    } else {
111 1
      $this->array[$offset] = $value;
112
    }
113 1
  }
114
115
  /**
116
   * Whether or not an offset exists
117
   *
118
   * @param mixed $offset
119
   *
120
   * @return bool
121
   */
122 9
  public function offsetExists($offset)
123
  {
124 9
    return isset($this->array[$offset]);
125
  }
126
127
  /**
128
   * Unsets an offset
129
   *
130
   * @param mixed $offset
131
   */
132 1
  public function offsetUnset($offset)
133
  {
134 1
    if ($this->offsetExists($offset)) {
135 1
      unset($this->array[$offset]);
136 1
    }
137 1
  }
138
139
  /**
140
   * Returns the value at specified offset
141
   *
142
   * @param mixed $offset
143
   *
144
   * @return null
145
   */
146 8
  public function offsetGet($offset)
147
  {
148 8
    return $this->offsetExists($offset) ? $this->array[$offset] : null;
149
  }
150
151
  /**
152
   * Returns a new ArrayIterator, thus implementing the IteratorAggregate
153
   * interface.
154
   *
155
   * @return \ArrayIterator An iterator for the values in the array
156
   */
157 2
  public function getIterator()
158
  {
159 2
    return new \ArrayIterator($this->array);
160
  }
161
162
  /**
163
   * call object as function
164
   *
165
   * @param mixed $key
166
   *
167
   * @return mixed
168
   */
169
  public function __invoke($key = null)
170
  {
171
    if ($key !== null) {
172
      if (isset($this->array[$key])) {
173
        return $this->array[$key];
174
      } else {
175
        return false;
176
      }
177
    }
178
179
    return (array)$this->array;
180
  }
181
182
  /**
183
   * get the current array from the "Arrayy"-object
184
   *
185
   * @return array
186
   */
187 210
  public function getArray()
188
  {
189 210
    return $this->array;
190
  }
191
192
  /**
193
   * Creates a Arrayy object
194
   *
195
   * @param array $array
196
   *
197
   * @return self
198
   */
199 255
  public static function create($array = array())
200
  {
201 255
    return new static($array);
202
  }
203
204
  ////////////////////////////////////////////////////////////////////
205
  ///////////////////////////// ANALYZE //////////////////////////////
206
  ////////////////////////////////////////////////////////////////////
207
208
  /**
209
   * Search for the value of the current array via $index.
210
   *
211
   * @param mixed $index
212
   *
213
   * @return self
214
   */
215 7
  public function searchValue($index)
216
  {
217
    // init
218 7
    $return = array();
219
220 7
    if (null !== $index) {
221 7
      $keyExists = isset($this->array[$index]);
222
223 7
      if ($keyExists !== false) {
224 5
        $return = array($this->array[$index]);
225 5
      }
226 7
    }
227
228 7
    return self::create((array)$return);
229
  }
230
231
  /**
232
   * Search for the first index of the current array via $value.
233
   *
234
   * @param mixed $value
235
   *
236
   * @return self
237
   */
238 7
  public function searchIndex($value)
239
  {
240 7
    $key = array_search($value, $this->array, true);
241
242 7
    if ($key === false) {
243 2
      $return = array();
244 2
    } else {
245 5
      $return = array($key);
246
    }
247
248 7
    return self::create((array)$return);
249
  }
250
251
  /**
252
   * Check if all items in an array match a truth test.
253
   *
254
   * @param \Closure $closure
255
   *
256
   * @return bool
257
   */
258 9 View Code Duplication
  public function matches(\Closure $closure)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
259
  {
260
    // Reduce the array to only booleans
261 9
    $array = $this->each($closure);
262
263
    // Check the results
264 9
    if (count($array) === 0) {
265 2
      return true;
266
    }
267 7
    $array = array_search(false, $array, false);
268
269 7
    return is_bool($array);
270
  }
271
272
  /**
273
   * Check if any item in an array matches a truth test.
274
   *
275
   * @param \Closure $closure
276
   *
277
   * @return bool
278
   */
279 9 View Code Duplication
  public function matchesAny(\Closure $closure)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
280
  {
281
    // Reduce the array to only booleans
282 9
    $array = $this->each($closure);
283
284
    // Check the results
285 9
    if (count($array) === 0) {
286 2
      return true;
287
    }
288 7
    $array = array_search(true, $array, false);
289
290 7
    return is_int($array);
291
  }
292
293
  /**
294
   * Check if an item is in an array.
295
   *
296
   * @param mixed $value
297
   *
298
   * @return bool
299
   */
300 9
  public function contains($value)
301
  {
302 9
    return in_array($value, $this->array, true);
303
  }
304
305
  /**
306
   * Returns the average value of an array.
307
   *
308
   * @param int $decimals The number of decimals to return
309
   *
310
   * @return int|double The average value
311
   */
312 10
  public function average($decimals = null)
313
  {
314 10
    $count = $this->count();
315
316 10
    if (!$count) {
317 2
      return 0;
318
    }
319
320 8
    if (!is_int($decimals)) {
321 3
      $decimals = null;
322 3
    }
323
324 8
    return round(array_sum($this->array) / $count, $decimals);
325
  }
326
327
  /**
328
   * Count the values from the current array.
329
   *
330
   * INFO: only a alias for "$arrayy->size()"
331
   *
332
   * @return int
333
   */
334
  public function length()
335
  {
336
    return $this->size();
337
  }
338
339
  /**
340
   * Count the values from the current array.
341
   *
342
   * INFO: only a alias for "$arrayy->size()"
343
   *
344
   * @return int
345
   */
346 42
  public function count()
347
  {
348 42
    return $this->size();
349
  }
350
351
  /**
352
   * Get the size of an array.
353
   *
354
   * @return int
355
   */
356 42
  public function size()
357
  {
358 42
    return count($this->array);
359
  }
360
361
  /**
362
   * Get the max value from an array.
363
   *
364
   * @return mixed
365
   */
366 10
  public function max()
367
  {
368 10
    if ($this->count() === 0) {
369 1
      return false;
370
    }
371
372 9
    return max($this->array);
373
  }
374
375
  /**
376
   * Get the min value from an array.
377
   *
378
   * @return mixed
379
   */
380 10
  public function min()
381
  {
382 10
    if ($this->count() === 0) {
383 1
      return false;
384
    }
385
386 9
    return min($this->array);
387
  }
388
389
  ////////////////////////////////////////////////////////////////////
390
  //////////////////////////// FETCH FROM ////////////////////////////
391
  ////////////////////////////////////////////////////////////////////
392
393
  /**
394
   * Find the first item in an array that passes the truth test,
395
   *  otherwise return false
396
   *
397
   * @param \Closure $closure
398
   *
399
   * @return mixed|false false if we couldn't find the value
400
   */
401 7
  public function find(\Closure $closure)
402
  {
403 7
    foreach ($this->array as $key => $value) {
404 5
      if ($closure($value, $key)) {
405 4
        return $value;
406
      }
407 4
    }
408
409 3
    return false;
410
  }
411
412
  /**
413
   * Clean all falsy values from an array.
414
   *
415
   * @return self
416
   */
417 7
  public function clean()
418
  {
419 7
    return $this->filter(
420
        function ($value) {
421 6
          return (bool)$value;
422
        }
423 7
    );
424
  }
425
426
  /**
427
   * Get a random string from an array.
428
   *
429
   * @param null|int $take how many values you will take?
430
   *
431
   * @return self
432
   */
433 9
  public function random($take = null)
434
  {
435 9
    if ($take === null) {
436 5
      return Arrayy::create((array)$this->array[array_rand($this->array)]);
437
    }
438
439 4
    shuffle($this->array);
440
441 4
    return $this->first($take);
442
  }
443
444
  /**
445
   * Return an array with all elements found in input array.
446
   *
447
   * @param array $search
448
   *
449
   * @return self
450
   */
451 2
  public function intersection(array $search)
452
  {
453 2
    return self::create(array_values(array_intersect($this->array, $search)));
454
  }
455
456
  /**
457
   * Return a boolean flag which indicates whether the two input arrays have any common elements.
458
   *
459
   * @param array $search
460
   *
461
   * @return bool
462
   */
463 1
  public function intersects(array $search)
464
  {
465 1
    return count($this->intersection($search)->array) > 0;
466
  }
467
468
  ////////////////////////////////////////////////////////////////////
469
  ///////////////////////////// SLICERS //////////////////////////////
470
  ////////////////////////////////////////////////////////////////////
471
472
  /**
473
   * Get the first value from an array.
474
   *
475
   * @param int|null $take how many values you will take?
476
   *
477
   * @return self
478
   */
479 26
  public function first($take = null)
480
  {
481 26
    if ($take === null) {
482 8
      $array = array_shift($this->array);
483 8
    } else {
484 18
      $array = array_splice($this->array, 0, $take, true);
485
    }
486
487 26
    return self::create((array)$array);
488
  }
489
490
  /**
491
   * Get the last value from an array.
492
   *
493
   * @param int|null $take
494
   *
495
   * @return self
496
   */
497 10
  public function last($take = null)
498
  {
499 10
    if ($take === null) {
500 7
      $array = self::create((array)array_pop($this->array));
501 7
    } else {
502 3
      $array = $this->rest(-$take);
503
    }
504
505 10
    return $array;
506
  }
507
508
  /**
509
   * Get everything but the last..$to items.
510
   *
511
   * @param int $to
512
   *
513
   * @return self
514
   */
515 10
  public function initial($to = 1)
516
  {
517 10
    $slice = count($this->array) - $to;
518
519 10
    return $this->first($slice);
520
  }
521
522
  /**
523
   * Get the last elements from index $from until the end of this array.
524
   *
525
   * @param int $from
526
   *
527
   * @return self
528
   */
529 13
  public function rest($from = 1)
530
  {
531 13
    return self::create(array_splice($this->array, $from));
532
  }
533
534
  ////////////////////////////////////////////////////////////////////
535
  ///////////////////////////// ACT UPON /////////////////////////////
536
  ////////////////////////////////////////////////////////////////////
537
538
  /**
539
   * Iterate over an array and execute a callback for each loop.
540
   *
541
   * @param \Closure $closure
542
   *
543
   * @return Arrayy
544
   */
545 1 View Code Duplication
  public function at(\Closure $closure)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
546
  {
547 1
    $array = $this->array;
548
549 1
    foreach ($array as $key => $value) {
550 1
      $closure($value, $key);
551 1
    }
552
553 1
    return self::create($array);
554
  }
555
556
  ////////////////////////////////////////////////////////////////////
557
  ////////////////////////////// ALTER ///////////////////////////////
558
  ////////////////////////////////////////////////////////////////////
559
560
  /**
561
   * Merge the new $array into the current array.
562
   *
563
   * - replace duplicate keys from the current array with the key,values from the new $array
564
   * - create new indexes
565
   *
566
   * @param array $array
567
   *
568
   * @return self
569
   */
570 8
  public function mergeAppendNewIndex(array $array = array())
571
  {
572 8
    return self::create(array_merge($this->array, $array));
573
  }
574
575
  /**
576
   * Merge the current array into the new $array.
577
   *
578
   * - replace duplicate keys from new $array with the key,values from the current array
579
   * - create new indexes
580
   *
581
   * @param array $array
582
   *
583
   * @return self
584
   */
585 8
  public function mergePrependNewIndex(array $array = array())
586
  {
587 8
    return self::create(array_merge($array, $this->array));
588
  }
589
590
  /**
591
   * Merge the new $array into the current array.
592
   *
593
   * - keep key,value from the current array, also if the index is in the new $array
594
   *
595
   * @param array $array
596
   *
597
   * @return self
598
   */
599 8
  public function mergeAppendKeepIndex(array $array = array())
600
  {
601 8
    return self::create(array_replace($array, $this->array));
602
  }
603
604
  /**
605
   * Merge the the current array into the $array.
606
   *
607
   * - use key,value from the new $array, also if the index is in the current array
608
   *
609
   * @param array $array
610
   *
611
   * @return self
612
   */
613 8
  public function mergePrependKeepIndex(array $array = array())
614
  {
615 8
    return self::create(array_replace($this->array, $array));
616
  }
617
618
  /**
619
   * Return values that are only in the current array.
620
   *
621
   * @param array $array
622
   *
623
   * @return self
624
   */
625 8
  public function diff(array $array = array())
626
  {
627 8
    return self::create(array_diff($this->array, $array));
628
  }
629
630
  /**
631
   * Return values that are only in the new $array.
632
   *
633
   * @param array $array
634
   *
635
   * @return self
636
   */
637 8
  public function diffReverse(array $array = array())
638
  {
639 8
    return self::create(array_diff($array, $this->array));
640
  }
641
642
  /**
643
   * Replace the first matched value in an array.
644
   *
645
   * @param string $search The string to replace
646
   * @param string $replacement    What to replace it with
647
   *
648
   * @return self
649
   */
650 3
  public function replaceOneValue($search, $replacement = '')
651
  {
652 3
    $array = $this->array;
653 3
    $key = array_search($search, $array, true);
654
655 3
    if ($key !== false) {
656 3
      $array[$key] = $replacement;
657 3
    }
658
659 3
    return self::create((array)$array);
660
  }
661
662
  /**
663
   * Replace values in an array.
664
   *
665
   * @param string $search The string to replace
666
   * @param string $replacement    What to replace it with
667
   *
668
   * @return self
669
   */
670 1
  public function replaceValues($search, $replacement = '')
671
  {
672 1
    $array = $this->each(
673
        function ($value) use ($search, $replacement) {
674 1
          return UTF8::str_replace($search, $replacement, $value);
675
        }
676 1
    );
677
678 1
    return self::create((array)$array);
679
  }
680
681
  /**
682
   * Replace the keys in an array with another set.
683
   *
684
   * @param array $keys An array of keys matching the array's size
685
   *
686
   * @return self
687
   */
688 1
  public function replaceKeys(array $keys)
689
  {
690 1
    $values = array_values($this->array);
691
692 1
    return self::create(array_combine($keys, $values));
693
  }
694
695
  /**
696
   * Iterate over an array and modify the array's value.
697
   *
698
   * @param \Closure $closure
699
   *
700
   * @return array
701
   */
702 21 View Code Duplication
  public function each(\Closure $closure)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
703
  {
704 21
    $array = $this->array;
705
706 21
    foreach ($array as $key => &$value) {
707 17
      $value = $closure($value, $key);
708 21
    }
709
710 21
    return $array;
711
  }
712
713
  /**
714
   * Shuffle an array.
715
   *
716
   * @return self
717
   */
718 1
  public function shuffle()
719
  {
720 1
    $array = $this->array;
721
722 1
    shuffle($array);
723
724 1
    return self::create($array);
725
  }
726
727
  /**
728
   * Sort an array by key.
729
   *
730
   * @param string $direction
731
   *
732
   * @return self
733
   */
734 8
  public function sortKeys($direction = 'ASC')
735
  {
736 8
    $array = $this->array;
737 8
    $direction = strtolower($direction);
738
739 8
    if ($direction === 'desc') {
740 1
      $directionType = SORT_DESC;
741 1
    } else {
742 7
      $directionType = SORT_ASC;
743
    }
744
745 8
    if ($directionType === SORT_ASC) {
746 7
      ksort($array);
747 7
    } else {
748 1
      krsort($array);
749
    }
750
751 8
    return self::create($array);
752
  }
753
754
  /**
755
   * Implodes an array.
756
   *
757
   * @param string $with What to implode it with
758
   *
759
   * @return string
760
   */
761 22
  public function implode($with = '')
762
  {
763 22
    return implode($with, $this->array);
764
  }
765
766
  /**
767
   * Find all items in an array that pass the truth test.
768
   *
769
   * @param \Closure $closure
770
   *
771
   * @return self
772
   */
773 8
  public function filter($closure = null)
774
  {
775 8
    if (!$closure) {
776
      return $this->clean();
777
    }
778
779 8
    $array = array_filter($this->array, $closure);
780
781 8
    return self::create($array);
782
  }
783
784
  /**
785
   * Invoke a function on all of an array's values.
786
   *
787
   * @param mixed $callable
788
   * @param array $arguments
789
   *
790
   * @return self
791
   */
792 1
  public function invoke($callable, $arguments = array())
793
  {
794
    // If one argument given for each iteration, create an array for it.
795 1
    if (!is_array($arguments)) {
796 1
      $arguments = StaticArrayy::repeat($arguments, count($this->array))->getArray();
797 1
    }
798
799
    // If the callable has arguments, pass them.
800 1
    if ($arguments) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $arguments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
801 1
      $array = array_map($callable, $this->array, $arguments);
802 1
    } else {
803 1
      $array = array_map($callable, $this->array);
804
    }
805
806 1
    return self::create($array);
807
  }
808
809
  /**
810
   * Return all items that fail the truth test.
811
   *
812
   * @param \Closure $closure
813
   *
814
   * @return self
815
   */
816 1 View Code Duplication
  public function reject(\Closure $closure)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
817
  {
818 1
    $filtered = array();
819
820 1
    foreach ($this->array as $key => $value) {
821 1
      if (!$closure($value, $key)) {
822 1
        $filtered[$key] = $value;
823 1
      }
824 1
    }
825
826 1
    return self::create($filtered);
827
  }
828
829
  /**
830
   * Remove the first value from an array.
831
   *
832
   * @return self
833
   */
834 8
  public function removeFirst()
835
  {
836 8
    array_shift($this->array);
837
838 8
    return self::create($this->array);
839
  }
840
841
  /**
842
   * Remove the last value from an array.
843
   *
844
   * @return self
845
   */
846 7
  public function removeLast()
847
  {
848 7
    array_pop($this->array);
849
850 7
    return self::create($this->array);
851
  }
852
853
  /**
854
   * Removes a particular value from an array (numeric or associative).
855
   *
856
   * @param mixed $value
857
   *
858
   * @return self
859
   */
860 7
  public function removeValue($value)
861
  {
862 7
    $isNumericArray = true;
863 7
    foreach ($this->array as $key => $item) {
864 6
      if ($item === $value) {
865 6
        if (!is_int($key)) {
866
          $isNumericArray = false;
867
        }
868 6
        unset($this->array[$key]);
869 6
      }
870 7
    }
871
872 7
    if ($isNumericArray) {
873 7
      $this->array = array_values($this->array);
874 7
    }
875
876 7
    return self::create($this->array);
877
  }
878
879
  /**
880
   * Prepend a value to an array.
881
   *
882
   * @param mixed $value
883
   *
884
   * @return self
885
   */
886 7
  public function prepend($value)
887
  {
888 7
    array_unshift($this->array, $value);
889
890 7
    return self::create($this->array);
891
  }
892
893
  /**
894
   * Append a value to an array.
895
   *
896
   * @param mixed $value
897
   *
898
   * @return self
899
   */
900 8
  public function append($value)
901
  {
902 8
    $this->array[] = $value;
903
904 8
    return self::create($this->array);
905
  }
906
907
  /**
908
   * Return the array in the reverse order.
909
   *
910
   * @return self
911
   */
912 7
  public function reverse()
913
  {
914 7
    $this->array = array_reverse($this->array);
915
916 7
    return self::create($this->array);
917
  }
918
919
  /**
920
   * duplicate free copy of an array
921
   *
922
   * @return self
923
   */
924 7
  public function unique()
925
  {
926 7
    $this->array = array_reduce(
0 ignored issues
show
Documentation Bug introduced by
It seems like array_reduce($this->arra...esultArray; }, array()) of type * is incompatible with the declared type array of property $array.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
927 7
        $this->array,
928 7
        function ($resultArray, $value) {
929 6
          if (in_array($value, $resultArray, true) === false) {
930 6
            $resultArray[] = $value;
931 6
          }
932
933 6
          return $resultArray;
934 7
        },
935 7
        array()
936 7
    );
937
938 7
    return self::create($this->array);
939
  }
940
}
941