Completed
Push — master ( 19d4fc...09bb07 )
by Gabriel
03:42
created

TableStructureRecordsTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 35.29%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 47
ccs 6
cts 17
cp 0.3529
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTableStructure() 0 7 2
A initTableStructure() 0 3 1
A initFields() 0 4 1
A setTableStructure() 0 3 1
A getFields() 0 7 2
1
<?php
2
3
namespace Nip\Records\Traits\TableStructure;
4
5
/**
6
 * Trait TableStructureRecordsTrait
7
 * @package Nip\Records\Traits\TableStructure
8
 */
9
trait TableStructureRecordsTrait
10
{
11
    protected $tableStructure = null;
12
13
    protected $fields = null;
14
15
    /**
16
     * @return null
17
     */
18
    public function getFields()
19
    {
20
        if ($this->fields === null) {
21
            $this->initFields();
22
        }
23
24
        return $this->fields;
25
    }
26
27
    public function initFields()
28
    {
29
        $structure = $this->getTableStructure();
30
        $this->fields = array_keys($structure['fields']);
31
    }
32
33
    /**
34
     * @return mixed
35
     */
36 2
    protected function getTableStructure()
37
    {
38 2
        if ($this->tableStructure == null) {
39
            $this->initTableStructure();
40
        }
41
42 2
        return $this->tableStructure;
43
    }
44
45
    /**
46
     * @param null $tableStructure
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $tableStructure is correct as it would always require null to be passed?
Loading history...
47
     */
48 3
    public function setTableStructure($tableStructure)
49
    {
50 3
        $this->tableStructure = $tableStructure;
51 3
    }
52
53
    protected function initTableStructure()
54
    {
55
        $this->setTableStructure($this->getDB()->getMetadata()->describeTable($this->getTable()));
0 ignored issues
show
Bug introduced by
The method getTable() does not exist on Nip\Records\Traits\Table...leStructureRecordsTrait. Did you maybe mean getTableStructure()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $this->setTableStructure($this->getDB()->getMetadata()->describeTable($this->/** @scrutinizer ignore-call */ getTable()));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
It seems like getDB() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $this->setTableStructure($this->/** @scrutinizer ignore-call */ getDB()->getMetadata()->describeTable($this->getTable()));
Loading history...
56
    }
57
}
58