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

CodeigniterModel::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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->findBy([]);
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 findBy(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
    /**
87
     * Calls methods from this class in underscore case.
88
     *
89
     * @param  string $method
90
     * @param  mixed  $parameters
91
     * @return mixed
92
     */
93 View Code Duplication
    public function __call($method, $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $method = camelize($method);
96
        $result = $this;
97
98
        if (method_exists($this, $method)) {
99
            $class = [ $this, $method ];
100
101
            $result = call_user_func_array($class, $parameters);
102
        }
103
104
        return $result;
105
    }
106
}
107