Completed
Pull Request — master (#35)
by
unknown
01:49
created

UniqueMultiDim::uniqueMultiDim()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 9.584
c 0
b 0
f 0
cc 4
nc 2
nop 1
crap 4
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
use Cocur\Chain\Chain;
6
7
/**
8
 * Unique Multidimensional.
9
 *
10
 * @author    Paulo Félix
11
 */
12
trait UniqueMultiDim
13
{
14
    /**
15
     * @return Chain
16
     */
17
18 2
    public function uniqueMultiDim($key=null)
19
    {
20 2
        if (isset($key)){
21 1
            $tempArray = array(); 
22 1
            $keyArray = array(); 
23 1
            $i = 0; 
24
            
25 1
            foreach($this->array as $val) { 
0 ignored issues
show
Bug introduced by
The property array does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26 1
                if (!in_array($val[$key], $keyArray)) { 
27 1
                    $keyArray[$i] = $val[$key]; 
28 1
                    $tempArray[$i] = $val; 
29
                } 
30 1
                $i++; 
31
            } 
32
    
33 1
            $this->array = $tempArray;
34
        }else{
35 1
            $this->array = array_values(array_map("unserialize", array_unique(array_map("serialize", $this->array))));
36
        }
37 2
        return $this;
38
    }
39
}
40