Passed
Push — master ( 1fe2f9...d2939f )
by huang
05:07
created

DemoModel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
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, [
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