Completed
Push — master ( 7af3da...12a071 )
by Lars
05:45
created

Arrayy::offsetExists()   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 0
Metric Value
c 1
b 0
f 0
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 376
  public function __construct($array = array())
22
  {
23 376
    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 376
        is_string($array)
29
        ||
30 376
        (is_object($array) && method_exists($array, '__toString'))
31 376
    ) {
32 1
      $array = (array)$array;
33 1
    }
34
35 376
    if (!is_array($array)) {
36 2
      throw new \InvalidArgumentException(
37
          'Passed value must be a array'
38 2
      );
39
    }
40
41 374
    $this->array = $array;
42 374
  }
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 279
  public static function create($array = array())
200
  {
201 279
    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 current 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 the current 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 we have named keys in the current array.
295
   *
296
   * @return bool
297
   */
298 11
  public function isAssoc()
299
  {
300 11
    if (count($this->array) === 0) {
301
      return false;
302
    }
303
304 11
    return (bool)count(array_filter(array_keys($this->array), 'is_string'));
305
  }
306
307
  /**
308
   * Check if the current array is a multi-array.
309
   *
310
   * @return bool
311
   */
312 13
  public function isMultiArray()
313
  {
314 13
    return !(count($this->array) === count($this->array, COUNT_RECURSIVE));
315
  }
316
317
  /**
318
   * Check if an item is in the current array.
319
   *
320
   * @param mixed $value
321
   *
322
   * @return bool
323
   */
324 9
  public function contains($value)
325
  {
326 9
    return in_array($value, $this->array, true);
327
  }
328
329
  /**
330
   * Returns the average value of the current array.
331
   *
332
   * @param int $decimals The number of decimals to return
333
   *
334
   * @return int|double The average value
335
   */
336 10
  public function average($decimals = null)
337
  {
338 10
    $count = $this->count();
339
340 10
    if (!$count) {
341 2
      return 0;
342
    }
343
344 8
    if (!is_int($decimals)) {
345 3
      $decimals = null;
346 3
    }
347
348 8
    return round(array_sum($this->array) / $count, $decimals);
349
  }
350
351
  /**
352
   * Count the values from the current array.
353
   *
354
   * INFO: only a alias for "$arrayy->size()"
355
   *
356
   * @return int
357
   */
358
  public function length()
359
  {
360
    return $this->size();
361
  }
362
363
  /**
364
   * Count the values from the current array.
365
   *
366
   * INFO: only a alias for "$arrayy->size()"
367
   *
368
   * @return int
369
   */
370 42
  public function count()
371
  {
372 42
    return $this->size();
373
  }
374
375
  /**
376
   * Get the size of an array.
377
   *
378
   * @return int
379
   */
380 42
  public function size()
381
  {
382 42
    return count($this->array);
383
  }
384
385
  /**
386
   * Get the max value from an array.
387
   *
388
   * @return mixed
389
   */
390 10
  public function max()
391
  {
392 10
    if ($this->count() === 0) {
393 1
      return false;
394
    }
395
396 9
    return max($this->array);
397
  }
398
399
  /**
400
   * Get the min value from an array.
401
   *
402
   * @return mixed
403
   */
404 10
  public function min()
405
  {
406 10
    if ($this->count() === 0) {
407 1
      return false;
408
    }
409
410 9
    return min($this->array);
411
  }
412
413
  ////////////////////////////////////////////////////////////////////
414
  //////////////////////////// FETCH FROM ////////////////////////////
415
  ////////////////////////////////////////////////////////////////////
416
417
  /**
418
   * Find the first item in an array that passes the truth test,
419
   *  otherwise return false
420
   *
421
   * @param \Closure $closure
422
   *
423
   * @return mixed|false false if we couldn't find the value
424
   */
425 7
  public function find(\Closure $closure)
426
  {
427 7
    foreach ($this->array as $key => $value) {
428 5
      if ($closure($value, $key)) {
429 4
        return $value;
430
      }
431 4
    }
432
433 3
    return false;
434
  }
435
436
  /**
437
   * Clean all falsy values from an array.
438
   *
439
   * @return self
440
   */
441 7
  public function clean()
442
  {
443 7
    return $this->filter(
444
        function ($value) {
445 6
          return (bool)$value;
446
        }
447 7
    );
448
  }
449
450
  /**
451
   * Get a random string from an array.
452
   *
453
   * @param null|int $take how many values you will take?
454
   *
455
   * @return self
456
   */
457 9
  public function random($take = null)
458
  {
459 9
    if ($take === null) {
460 5
      return Arrayy::create((array)$this->array[array_rand($this->array)]);
461
    }
462
463 4
    shuffle($this->array);
464
465 4
    return $this->first($take);
466
  }
467
468
  /**
469
   * Return an array with all elements found in input array.
470
   *
471
   * @param array $search
472
   *
473
   * @return self
474
   */
475 2
  public function intersection(array $search)
476
  {
477 2
    return self::create(array_values(array_intersect($this->array, $search)));
478
  }
479
480
  /**
481
   * Return a boolean flag which indicates whether the two input arrays have any common elements.
482
   *
483
   * @param array $search
484
   *
485
   * @return bool
486
   */
487 1
  public function intersects(array $search)
488
  {
489 1
    return count($this->intersection($search)->array) > 0;
490
  }
491
492
  ////////////////////////////////////////////////////////////////////
493
  ///////////////////////////// SLICERS //////////////////////////////
494
  ////////////////////////////////////////////////////////////////////
495
496
  /**
497
   * Get the first value from an array.
498
   *
499
   * @param int|null $take how many values you will take?
500
   *
501
   * @return self
502
   */
503 26
  public function first($take = null)
504
  {
505 26
    if ($take === null) {
506 8
      $array = array_shift($this->array);
507 8
    } else {
508 18
      $array = array_splice($this->array, 0, $take, true);
509
    }
510
511 26
    return self::create((array)$array);
512
  }
513
514
  /**
515
   * Get the last value from an array.
516
   *
517
   * @param int|null $take
518
   *
519
   * @return self
520
   */
521 10
  public function last($take = null)
522
  {
523 10
    if ($take === null) {
524 7
      $array = self::create((array)array_pop($this->array));
525 7
    } else {
526 3
      $array = $this->rest(-$take);
527
    }
528
529 10
    return $array;
530
  }
531
532
  /**
533
   * Get everything but the last..$to items.
534
   *
535
   * @param int $to
536
   *
537
   * @return self
538
   */
539 10
  public function initial($to = 1)
540
  {
541 10
    $slice = count($this->array) - $to;
542
543 10
    return $this->first($slice);
544
  }
545
546
  /**
547
   * Get the last elements from index $from until the end of this array.
548
   *
549
   * @param int $from
550
   *
551
   * @return self
552
   */
553 13
  public function rest($from = 1)
554
  {
555 13
    return self::create(array_splice($this->array, $from));
556
  }
557
558
  ////////////////////////////////////////////////////////////////////
559
  ///////////////////////////// ACT UPON /////////////////////////////
560
  ////////////////////////////////////////////////////////////////////
561
562
  /**
563
   * Iterate over an array and execute a callback for each loop.
564
   *
565
   * @param \Closure $closure
566
   *
567
   * @return Arrayy
568
   */
569 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...
570
  {
571 1
    $array = $this->array;
572
573 1
    foreach ($array as $key => $value) {
574 1
      $closure($value, $key);
575 1
    }
576
577 1
    return self::create($array);
578
  }
579
580
  ////////////////////////////////////////////////////////////////////
581
  ////////////////////////////// ALTER ///////////////////////////////
582
  ////////////////////////////////////////////////////////////////////
583
584
  /**
585
   * Merge the new $array into the current array.
586
   *
587
   * - replace duplicate keys from the current array with the key,values from the new $array
588
   * - create new indexes
589
   *
590
   * @param array $array
591
   *
592
   * @return self
593
   */
594 8
  public function mergeAppendNewIndex(array $array = array())
595
  {
596 8
    return self::create(array_merge($this->array, $array));
597
  }
598
599
  /**
600
   * Merge the current array into the new $array.
601
   *
602
   * - replace duplicate keys from new $array with the key,values from the current array
603
   * - create new indexes
604
   *
605
   * @param array $array
606
   *
607
   * @return self
608
   */
609 8
  public function mergePrependNewIndex(array $array = array())
610
  {
611 8
    return self::create(array_merge($array, $this->array));
612
  }
613
614
  /**
615
   * Merge the new $array into the current array.
616
   *
617
   * - keep key,value from the current array, also if the index is in the new $array
618
   *
619
   * @param array $array
620
   *
621
   * @return self
622
   */
623 8
  public function mergeAppendKeepIndex(array $array = array())
624
  {
625 8
    return self::create(array_replace($array, $this->array));
626
  }
627
628
  /**
629
   * Merge the the current array into the $array.
630
   *
631
   * - use key,value from the new $array, also if the index is in the current array
632
   *
633
   * @param array $array
634
   *
635
   * @return self
636
   */
637 8
  public function mergePrependKeepIndex(array $array = array())
638
  {
639 8
    return self::create(array_replace($this->array, $array));
640
  }
641
642
  /**
643
   * Return values that are only in the current array.
644
   *
645
   * @param array $array
646
   *
647
   * @return self
648
   */
649 8
  public function diff(array $array = array())
650
  {
651 8
    return self::create(array_diff($this->array, $array));
652
  }
653
654
  /**
655
   * Return values that are only in the new $array.
656
   *
657
   * @param array $array
658
   *
659
   * @return self
660
   */
661 8
  public function diffReverse(array $array = array())
662
  {
663 8
    return self::create(array_diff($array, $this->array));
664
  }
665
666
  /**
667
   * Replace the first matched value in an array.
668
   *
669
   * @param string $search The string to replace
670
   * @param string $replacement    What to replace it with
671
   *
672
   * @return self
673
   */
674 3
  public function replaceOneValue($search, $replacement = '')
675
  {
676 3
    $array = $this->array;
677 3
    $key = array_search($search, $array, true);
678
679 3
    if ($key !== false) {
680 3
      $array[$key] = $replacement;
681 3
    }
682
683 3
    return self::create((array)$array);
684
  }
685
686
  /**
687
   * Replace values in an array.
688
   *
689
   * @param string $search The string to replace
690
   * @param string $replacement    What to replace it with
691
   *
692
   * @return self
693
   */
694 1
  public function replaceValues($search, $replacement = '')
695
  {
696 1
    $array = $this->each(
697
        function ($value) use ($search, $replacement) {
698 1
          return UTF8::str_replace($search, $replacement, $value);
699
        }
700 1
    );
701
702 1
    return self::create((array)$array);
703
  }
704
705
  /**
706
   * Replace the keys in an array with another set.
707
   *
708
   * @param array $keys An array of keys matching the array's size
709
   *
710
   * @return self
711
   */
712 1
  public function replaceKeys(array $keys)
713
  {
714 1
    $values = array_values($this->array);
715
716 1
    return self::create(array_combine($keys, $values));
717
  }
718
719
  /**
720
   * Iterate over an array and modify the array's value.
721
   *
722
   * @param \Closure $closure
723
   *
724
   * @return array
725
   */
726 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...
727
  {
728 21
    $array = $this->array;
729
730 21
    foreach ($array as $key => &$value) {
731 17
      $value = $closure($value, $key);
732 21
    }
733
734 21
    return $array;
735
  }
736
737
  /**
738
   * Shuffle an array.
739
   *
740
   * @return self
741
   */
742 1
  public function shuffle()
743
  {
744 1
    $array = $this->array;
745
746 1
    shuffle($array);
747
748 1
    return self::create($array);
749
  }
750
751
  /**
752
   * Sort an array by key.
753
   *
754
   * @param string $direction
755
   *
756
   * @return self
757
   */
758 8
  public function sortKeys($direction = 'ASC')
759
  {
760 8
    $array = $this->array;
761 8
    $direction = strtolower($direction);
762
763 8
    if ($direction === 'desc') {
764 1
      $directionType = SORT_DESC;
765 1
    } else {
766 7
      $directionType = SORT_ASC;
767
    }
768
769 8
    if ($directionType === SORT_ASC) {
770 7
      ksort($array);
771 7
    } else {
772 1
      krsort($array);
773
    }
774
775 8
    return self::create($array);
776
  }
777
778
  /**
779
   * Implodes an array.
780
   *
781
   * @param string $with What to implode it with
782
   *
783
   * @return string
784
   */
785 22
  public function implode($with = '')
786
  {
787 22
    return implode($with, $this->array);
788
  }
789
790
  /**
791
   * Find all items in an array that pass the truth test.
792
   *
793
   * @param \Closure $closure
794
   *
795
   * @return self
796
   */
797 8
  public function filter($closure = null)
798
  {
799 8
    if (!$closure) {
800
      return $this->clean();
801
    }
802
803 8
    $array = array_filter($this->array, $closure);
804
805 8
    return self::create($array);
806
  }
807
808
  /**
809
   * Invoke a function on all of an array's values.
810
   *
811
   * @param mixed $callable
812
   * @param array $arguments
813
   *
814
   * @return self
815
   */
816 1
  public function invoke($callable, $arguments = array())
817
  {
818
    // If one argument given for each iteration, create an array for it.
819 1
    if (!is_array($arguments)) {
820 1
      $arguments = StaticArrayy::repeat($arguments, count($this->array))->getArray();
821 1
    }
822
823
    // If the callable has arguments, pass them.
824 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...
825 1
      $array = array_map($callable, $this->array, $arguments);
826 1
    } else {
827 1
      $array = array_map($callable, $this->array);
828
    }
829
830 1
    return self::create($array);
831
  }
832
833
  /**
834
   * Return all items that fail the truth test.
835
   *
836
   * @param \Closure $closure
837
   *
838
   * @return self
839
   */
840 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...
841
  {
842 1
    $filtered = array();
843
844 1
    foreach ($this->array as $key => $value) {
845 1
      if (!$closure($value, $key)) {
846 1
        $filtered[$key] = $value;
847 1
      }
848 1
    }
849
850 1
    return self::create($filtered);
851
  }
852
853
  /**
854
   * Remove the first value from an array.
855
   *
856
   * @return self
857
   */
858 8
  public function removeFirst()
859
  {
860 8
    array_shift($this->array);
861
862 8
    return self::create($this->array);
863
  }
864
865
  /**
866
   * Remove the last value from an array.
867
   *
868
   * @return self
869
   */
870 7
  public function removeLast()
871
  {
872 7
    array_pop($this->array);
873
874 7
    return self::create($this->array);
875
  }
876
877
  /**
878
   * Removes a particular value from an array (numeric or associative).
879
   *
880
   * @param mixed $value
881
   *
882
   * @return self
883
   */
884 7
  public function removeValue($value)
885
  {
886 7
    $isNumericArray = true;
887 7
    foreach ($this->array as $key => $item) {
888 6
      if ($item === $value) {
889 6
        if (!is_int($key)) {
890
          $isNumericArray = false;
891
        }
892 6
        unset($this->array[$key]);
893 6
      }
894 7
    }
895
896 7
    if ($isNumericArray) {
897 7
      $this->array = array_values($this->array);
898 7
    }
899
900 7
    return self::create($this->array);
901
  }
902
903
  /**
904
   * Prepend a value to an array.
905
   *
906
   * @param mixed $value
907
   *
908
   * @return self
909
   */
910 7
  public function prepend($value)
911
  {
912 7
    array_unshift($this->array, $value);
913
914 7
    return self::create($this->array);
915
  }
916
917
  /**
918
   * Append a value to an array.
919
   *
920
   * @param mixed $value
921
   *
922
   * @return self
923
   */
924 8
  public function append($value)
925
  {
926 8
    $this->array[] = $value;
927
928 8
    return self::create($this->array);
929
  }
930
931
  /**
932
   * Return the array in the reverse order.
933
   *
934
   * @return self
935
   */
936 7
  public function reverse()
937
  {
938 7
    $this->array = array_reverse($this->array);
939
940 7
    return self::create($this->array);
941
  }
942
943
  /**
944
   * duplicate free copy of an array
945
   *
946
   * @return self
947
   */
948 7
  public function unique()
949
  {
950 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...
951 7
        $this->array,
952 7
        function ($resultArray, $value) {
953 6
          if (in_array($value, $resultArray, true) === false) {
954 6
            $resultArray[] = $value;
955 6
          }
956
957 6
          return $resultArray;
958 7
        },
959 7
        array()
960 7
    );
961
962 7
    return self::create($this->array);
963
  }
964
}
965