Completed
Pull Request — master (#1)
by Rougin
02:23
created

CodeigniterModel   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 73
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A all() 0 4 1
A delete() 0 6 1
A find() 0 4 1
A get() 0 4 1
A find_by() 0 6 1
1
<?php
2
3
namespace Rougin\Wildfire;
4
5
/**
6
 * Codeigniter Model
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 *
11
 * @property \CI_DB $db
12
 */
13
class CodeigniterModel extends \CI_Model
14
{
15
    use Traits\ModelTrait;
16
17
    /**
18
     * @var \Rougin\Wildfire\Wildfire
19
     */
20
    protected $wildfire;
21
22 15
    public function __construct()
23
    {
24 15
        parent::__construct();
25
26 15
        $this->wildfire = new Wildfire($this->db);
27 15
    }
28
29
    /**
30
     * Returns all of the models from the database.
31
     *
32
     * @return array
33
     */
34 3
    public function all()
35
    {
36 3
        return $this->find_by([]);
37
    }
38
39
    /**
40
     * Deletes the specified ID of the model from the database.
41
     *
42
     * @param  integer $id
43
     * @return void
44
     */
45 3
    public function delete($id)
46
    {
47 3
        $this->db->where($this->getPrimaryKey(), $id);
48
49 3
        return $this->db->delete($this->getTableName());
50
    }
51
52
    /**
53
     * Finds the specified model from the database.
54
     *
55
     * @param  integer $id
56
     * @return mixed
57
     */
58 9
    public function find($id)
59
    {
60 9
        return $this->wildfire->find($this->getTableName(), $id);
61
    }
62
63
    /**
64
     * Finds the specified model from the database by the given delimiters.
65
     *
66
     * @param  array $delimiters
67
     * @return mixed
68
     */
69 3
    public function find_by(array $delimiters)
70
    {
71 3
        $this->db->where($delimiters);
72
73 3
        return $this->get()->result();
74
    }
75
76
    /**
77
     * Returns all rows from the specified table.
78
     *
79
     * @return self
80
     */
81 3
    public function get()
82
    {
83 3
        return $this->wildfire->get($this->getTableName());
84
    }
85
}
86