Passed
Push — master ( 6ce97f...1fe2f9 )
by huang
05:13
created

DemoModel::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Model;
4
5
use FastD\Model\Model;
6
7
class DemoModel extends Model
8
{
9
    const TABLE = 'hello';
10
    const LIMIT = '15';
11
12
    public function select($page = 1)
13
    {
14
        $offset = ($page - 1) * static::LIMIT;
15
16
        return $this->db->select(static::TABLE, '*', [
17
            'LIMIT' => [$offset, static::LIMIT],
18
        ]);
19
    }
20
21
    public function find($id)
22
    {
23
        return $this->db->get(static::TABLE, '*', [
24
            'OR' => [
25
                'id' => $id,
26
            ],
27
        ]);
28
    }
29
30
    public function patch($id, array $data)
31
    {
32
        $affected = $this->db->update(static::TABLE, $data, [
0 ignored issues
show
Unused Code introduced by
$affected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
            'OR' => [
34
                'id' => $id,
35
            ],
36
        ]);
37
38
        return $this->find($id);
39
    }
40
41
    public function create(array $data)
42
    {
43
        $id = $this->db->insert(static::TABLE, $data);
44
45
        return $this->find($id);
46
    }
47
48
    public function deleteUser($id)
49
    {
50
        return $this->db->delete(static::TABLE, [
51
            'id' => $id,
52
        ]);
53
    }
54
}
55