Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

ColumnsProcess::fields()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 21
rs 9.6111
1
<?php
2
3
namespace Migratio\GrammarStructure\Mysql\Traits;
4
5
trait ColumnsProcess
6
{
7
    /**
8
     * @var $columns
0 ignored issues
show
Documentation Bug introduced by
The doc comment $columns at position 0 could not be parsed: Unknown type name '$columns' at position 0 in $columns.
Loading history...
9
     */
10
    private $columns;
11
12
    /**
13
     * @var string
14
     */
15
    private $fieldKey='Field';
16
17
    /**
18
     * @param $columns
19
     */
20
    public function columnsProcess($columns)
21
    {
22
        $this->columns=$columns;
23
    }
24
25
    /**
26
     * @return mixed
27
     */
28
    public function all()
29
    {
30
        return $this->columns;
31
    }
32
33
    /**
34
     * @param array $tables
35
     * @return array
36
     */
37
    public function fields($tables=array())
38
    {
39
        $list = [];
40
41
        foreach ($this->columns as $table=>$columns)
42
        {
43
            foreach ($columns as $columnData)
44
            {
45
                if(count($tables)){
46
47
                    if(in_array($table,$tables)){
48
                        $list[$table][] = $columnData[$this->fieldKey];
49
                    }
50
                }
51
                else{
52
                    $list[$table][] = $columnData[$this->fieldKey];
53
                }
54
            }
55
        }
56
57
        return $list;
58
    }
59
}
60
61