Completed
Pull Request — master (#8)
by Rougin
02:26
created

CodeigniterModel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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_query_builder $db
12
 */
13
class CodeigniterModel extends \CI_Model
14
{
15
    use Traits\ModelTrait, Traits\RelationshipTrait;
16
17
    /**
18
     * Returns all of the models from the database.
19
     *
20
     * @return array
21
     */
22 6
    public function all()
23
    {
24 6
        return $this->find_by([]);
25
    }
26
27
    /**
28
     * Deletes the specified ID of the model from the database.
29
     *
30
     * @param  integer $id
31
     * @return void
32
     */
33 3
    public function delete($id)
34
    {
35 3
        $this->db->where($this->getPrimaryKey(), $id);
36
37 3
        return $this->db->delete($this->getTableName());
38
    }
39
40
    /**
41
     * Finds the specified model from the database.
42
     *
43
     * @param  integer $id
44
     * @return mixed
45
     */
46 12
    public function find($id)
47
    {
48 12
        return Wildfire::create($this->db)->find($this->getTableName(), $id);
0 ignored issues
show
Documentation introduced by
$this->db is of type object<CI_DB_query_builder>, but the function expects a object<CI_DB>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
    }
50
51
    /**
52
     * Finds the specified model from the database by the given delimiters.
53
     *
54
     * @param  array $delimiters
55
     * @return mixed
56
     */
57 6
    public function find_by(array $delimiters)
58
    {
59 6
        $this->db->where($delimiters);
60
61 6
        return $this->get()->result();
62
    }
63
64
    /**
65
     * Returns all rows from the specified table.
66
     *
67
     * @return self
68
     */
69 6
    public function get()
70
    {
71 6
        return Wildfire::create($this->db)->get($this);
0 ignored issues
show
Documentation introduced by
$this->db is of type object<CI_DB_query_builder>, but the function expects a object<CI_DB>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
    }
73
74
    /**
75
     * Inserts a new row into the table.
76
     *
77
     * @param  array $data
78
     * @return integer
79
     */
80 3
    public function insert(array $data)
81
    {
82 3
        $this->db->insert($this->getTableName(), $data);
83
84 3
        return $this->db->insert_id();
0 ignored issues
show
Bug introduced by
The method insert_id() does not exist on CI_DB_query_builder. Did you maybe mean insert()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
85
    }
86
87
    /**
88
     * Updates the selected row from the table.
89
     *
90
     * @param  integer $id
91
     * @param  array   $data
92
     * @return boolean
93
     */
94 3
    public function update($id, array $data)
95
    {
96 3
        $this->db->where($this->getPrimaryKey(), $id);
97 3
        $this->db->set($data);
98
99 3
        return $this->db->update($this->getTableName());
100
    }
101
}
102