for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Arcanedev\Support;
use Illuminate\Support\Collection as IlluminateCollection;
/**
* Class Collection
*
* @package Arcanedev\Support
* @author ARCANEDEV <[email protected]>
*/
class Collection extends IlluminateCollection
{
/* ------------------------------------------------------------------------------------------------
| Custom Functions
| ------------------------------------------------------------------------------------------------
* Return only unique items from the collection array.
* @param string|callable|null $key
* @param bool $strict
* @return static
public function unique($key = null, $strict = false)
if (is_null($key))
return new static(array_unique($this->items, SORT_REGULAR));
$key = $this->valueRetriever($key);
$key
callable
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
$exists = [];
return $this->reject(function ($item) use ($key, $strict, &$exists) {
if (in_array($id = $key($item), $exists, $strict)) {
return true;
}
$exists[] = $id;
});
* Return only unique items from the collection array using strict comparison.
public function uniqueStrict($key = null)
return $this->unique($key, true);
* Reset the collection.
public function reset()
$this->items = [];
return $this;
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: