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

UniqueMultiDim   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 28
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A uniqueMultiDim() 0 21 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