Completed
Pull Request — master (#35)
by
unknown
02:47
created

UniqueMultiDim   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A uniqueMultiDim() 0 17 3
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
 * @copyright 2019 Paulo Félix
12
 */
13
trait UniqueMultiDim
14
{
15
    public function uniqueMultiDim($key)
16
    {
17
        $tempArray = array(); 
18
        $i = 0; 
19
        $keyArray = array(); 
20
        
21
        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...
22
            if (!in_array($val[$key], $keyArray)) { 
23
                $keyArray[$i] = $val[$key]; 
24
                $tempArray[$i] = $val; 
25
            } 
26
            $i++; 
27
        } 
28
29
        $this->array = $tempArray;
30
        return $this;
31
    }
32
}
33