Completed
Pull Request — master (#3)
by Rougin
02:51
created

DatabaseTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDatabase() 0 18 2
A setQuery() 0 6 1
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
 * @property string $table
14
 */
15
trait DatabaseTrait
16
{
17
    /**
18
     * @var \CI_DB
19
     */
20
    protected $db;
21
22
    /**
23
     * @var \CI_DB_result
24
     */
25
    protected $query;
26
27
    /**
28
     * Sets the database class.
29
     *
30
     * @param  \CI_DB|null $database
31
     * @return self
32
     */
33 39
    public function setDatabase($database = null)
34
    {
35 39
        $ci = Instance::create();
36
37 39
        $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...
38
39 39
        if (empty($database)) {
40 3
            $ci->load->database();
41
42 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...
43
44 3
            return $this;
45
        }
46
47 39
        $this->db = $database;
48
49 39
        return $this;
50
    }
51
52
    /**
53
     * Sets the query result.
54
     *
55
     * @param  \CI_DB_result $query
56
     * @return self
57
     */
58 3
    public function setQuery($query)
59
    {
60 3
        $this->query = $query;
61
62 3
        return $this;
63
    }
64
}
65