Passed
Push — master ( 6ce97f...1fe2f9 )
by huang
05:13
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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 8 1
A find() 0 8 1
A patch() 0 10 1
A create() 0 6 1
A deleteUser() 0 6 1
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