Completed
Push — master ( d34ae1...d2cd4a )
by kill
10:24
created

Model::page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
4
namespace puck;
5
6
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
7
 * this->where()
8
 *
9
 *
10
 * */
11
class Model
12
{
13
    protected $db;
14
    protected $field;
15
    protected $table;
16
    protected $dbConn;
17
    protected $limitCount=null;
18
    public function __construct()
19
    {
20
        if(!$this->dbConn){
21
            $this->dbConn='main';
22
        }
23
        $this->db = mysql::getDb($this->dbConn);
24
    }
25
    public function __call($method,$arg){
26
        $ret=$this;
27
        if(method_exists ($this->db, $method)){
28
            $ret=call_user_func_array(array($this->db,$method),$arg);
29
        }
30
        return $ret==$this->db? $this: $ret;
31
    }
32
    public function __get($name){
33
        if(property_exists($this->db, $name)){
34
            return $this->db->$name;
35
        }
36
        throw new MemberAccessException('model Property ' . $name . ' not exists');
37
    }
38
    public function limit($limit){
39
        $this->limitCount=$limit;
40
        return $this;
41
    }
42
    public function find(){
43
        return $this->db->getOne($this->table,$this->field);
44
    }
45
    public function select(){
46
        return $this->db->get($this->table,$this->limitCount?$this->limitCount:null,$this->field);
47
    }
48
    public function count(){
49
        return $this->db->count;
50
    }
51
    public function table($table){
52
        $this->table=$table;
53
        return $this;
54
    }
55
    public function add($data){
56
        return $this->db->insert($this->table,$data);
57
    }
58
    public function update($data){
59
        return $this->db->update($this->table,$data);
60
    }
61
    public function field($field){
62
        $this->field=$field;
63
        return $this;
64
    }
65
    public function delete(){
66
        return $this->db->delete($this->table);
67
    }
68
    public function page($page,$pageLimit='10'){
69
        $this->db->pageLimit=$pageLimit;
0 ignored issues
show
Documentation Bug introduced by
The property $pageLimit was declared of type integer, but $pageLimit is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
70
        $info= $this->db->paginate($this->table,$page);
71
        return $info;
72
    }
73
}