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

TableStructureRecordsTrait::getTableStructure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
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