Completed
Push — master ( 289621...5c183f )
by Rougin
02:34
created

DatabaseTrait::getTableName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
use Rougin\SparkPlug\Instance;
6
7
/**
8
 * Database Trait
9
 * 
10
 * @package Wildfire
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
trait DatabaseTrait
14
{
15
    /**
16
     * @var \CI_DB
17
     */
18
    protected $db;
19
20
    /**
21
     * @var \CI_DB_result
22
     */
23
    protected $query;
24
25
    /**
26
     * Parses the table name from Describe class.
27
     * 
28
     * @param  string $table
29
     * @return string
30
     */
31 24
    protected function getTableName($table)
32
    {
33 24
        $table = ucfirst(singular($table));
34 24
        $array = explode('.', $table);
35
36 24
        return isset($array[1]) ? $array[1] : $table;
37
    }
38
39
    /**
40
     * Sets the database class.
41
     * 
42
     * @param  \CI_DB|null $database
43
     * @return self
44
     */
45 24
    public function setDatabase($database = null)
46
    {
47 24
        $ci = Instance::create();
48 24
        $ci->load->helper('inflector');
0 ignored issues
show
Bug introduced by
The property load does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
50 24
        if (empty($database)) {
51 3
            $ci->load->database();
52
53 3
            $this->db = $ci->db;
0 ignored issues
show
Bug introduced by
The property db does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
54
55 3
            return $this;
56
        }
57
58 24
        $this->db = $database;
59
60 24
        return $this;
61
    }
62
63
    /**
64
     * Sets the query result.
65
     * 
66
     * @param  \CI_DB_result $query
67
     * @return self
68
     */
69 3
    public function setQuery($query)
70
    {
71 3
        $this->query = $query;
72
73 3
        return $this;
74
    }
75
}
76