Completed
Pull Request — master (#7)
by Rougin
02:16
created

CodeigniterModel::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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|\CI_DB_driver $db
12
 */
13
class CodeigniterModel extends \CI_Model
14
{
15
    use Traits\ModelTrait, Traits\RelationshipTrait;
16
17
    /**
18
     * @var \Rougin\Wildfire\Wildfire
19
     */
20
    protected $wildfire;
21
22 24
    public function __construct()
23
    {
24 24
        parent::__construct();
25
26 24
        $this->wildfire = new Wildfire($this->db);
0 ignored issues
show
Bug introduced by
It seems like $this->db can also be of type object<CI_DB_driver>; however, Rougin\Wildfire\Wildfire::__construct() does only seem to accept object<CI_DB>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
27 21
    }
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
    public function delete($id)
46
    {
47
        $this->db->where($this->getPrimaryKey(), $id);
0 ignored issues
show
Bug introduced by
The method where does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48
49
        return $this->db->delete($this->getTableName());
0 ignored issues
show
Bug introduced by
The method delete does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50
    }
51
52
    /**
53
     * Finds the specified model from the database.
54
     *
55
     * @param  integer $id
56
     * @return mixed
57
     */
58
    public function find($id)
59
    {
60
        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);
0 ignored issues
show
Bug introduced by
The method where does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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);
84
    }
85
86
    /**
87
     * Inserts a new row into the table.
88
     *
89
     * @param  array $data
90
     * @return integer
91
     */
92
    public function insert(array $data)
93
    {
94
        $this->db->insert($this->getTableName(), $data);
0 ignored issues
show
Bug introduced by
The method insert does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
95
96
        return $this->db->insert_id();
97
    }
98
99
    /**
100
     * Updates the selected row from the table.
101
     *
102
     * @param  integer $id
103
     * @param  array   $data
104
     * @return boolean
105
     */
106
    public function update($id, array $data)
107
    {
108
        $this->db->where($this->getPrimaryKey(), $id);
0 ignored issues
show
Bug introduced by
The method where does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
109
        $this->db->set($data);
0 ignored issues
show
Bug introduced by
The method set does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
110
111
        return $this->db->update($this->getTableName());
0 ignored issues
show
Bug introduced by
The method update does only exist in CI_DB, but not in CI_DB_driver.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
    }
113
}
114