Model   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 5 Features 2
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 74
c 5
b 5
f 2
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __set() 0 4 1
A save() 0 10 1
A update() 0 8 1
A remove() 0 10 2
A find() 0 15 2
A findAll() 0 8 1
1
<?php
2
3
namespace Vundi\Potato;
4
5
use Vundi\Potato\Exceptions\IDShouldBeNumber;
6
7
class Model
8
{
9
    private static $db;
10
    protected static $entity_table;
11
    protected static $entity_class;
12
    protected $db_fields = [];
13
    public static $ID;
14
15
    public function __construct()
16
    {
17
        self::$db = new Database();
18
    }
19
20
    public function __set($key, $value)
21
    {
22
        $this->db_fields[$key] = $value;
23
    }
24
25
    public function save()
26
    {
27
        //var_dump($this->db_fields);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
28
        $s = new static();
29
        // foreach ($s::$db_fields as $key) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
30
        //     $data[$key] = $this->$key;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
31
        // }
32
33
        return self::$db->insert($s::$entity_table, $this->db_fields);
34
    }
35
36
    public function update()
37
    {
38
        $s = new static();
39
40
        $where = "id = {$s::$ID}";
41
42
        self::$db->update($s::$entity_table, $this->db_fields, $where);
43
    }
44
45
    public static function remove($id)
46
    {
47
        if (is_int($id)) {
48
            $where = "id = {$id}";
49
            $s = new static();
50
            self::$db->delete($s::$entity_table, $where);
51
        } else {
52
            throw new IDShouldBeNumber('Pass in an ID as the parameter, ID has to be a number', 1);
53
        }
54
    }
55
56
    public static function find($id)
57
    {
58
        if (is_int($id)) {
59
            $s = new static();
60
            //comment
61
            $s::$ID = $id;
62
63
            $where = "id = {$id}";
64
            self::$db->select($s::$entity_table, $where);
65
66
            return self::$db->singleObject($s::$entity_class);
67
        } else {
68
            throw new IDShouldBeNumber('Find only takes a number as a parameter', 1);
69
        }
70
    }
71
72
    public static function findAll()
73
    {
74
        $s = new static();
75
76
        self::$db->select($s::$entity_table);
77
78
        return self::$db->objectSet();
79
    }
80
}
81