Table   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 59.51%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 90
ccs 25
cts 42
cp 0.5951
rs 10
c 0
b 0
f 0
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A getColumns() 0 3 1
A unsigned() 0 4 1
A notNull() 0 4 1
A integer() 0 5 1
A string() 0 5 1
A onUpdate() 0 4 1
A references() 0 5 1
A __call() 0 4 1
A onDelete() 0 4 1
A increments() 0 6 1
A timestamps() 0 4 1
A __set() 0 3 1
1
<?php
2
3
namespace Bonfim\ActiveRecord;
4
5
final class Table
6
{
7
    private $columns;
8
    private $last;
9
10
    private $pk;
11
    private $fk;
12
13
    private $references = "";
14
    private $onupdate = "";
15
    private $ondelete = "";
16
17 30
    public function __set($name, $value)
18
    {
19 30
        $this->columns[$name] = $value;
20 30
    }
21
22 30
    public function __get($name)
23
    {
24 30
        return $this->columns[$name];
25
    }
26
27 30
    public function __call($name, $arguments)
28
    {
29 30
        $name = strtolower(str_replace('get', '', $name));
30 30
        return $this->$name;
31
    }
32
33 30
    public function increments(string $name = 'id')
34
    {
35 30
        $this->last = $name;
36 30
        $this->$name = "INT AUTO_INCREMENT";
37 30
        $this->pk = $name;
38 30
        return $this;
39
    }
40
41 30
    public function timestamps(string $name = 'created_at')
42
    {
43 30
        $this->$name = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP";
44 30
        return $this;
45
    }
46
47 30
    public function string(string $name, int $len = 255)
48
    {
49 30
        $this->last = $name;
50 30
        $this->$name = "VARCHAR($len)";
51 30
        return $this;
52
    }
53
54
    public function integer($name)
55
    {
56
        $this->last = $name;
57
        $this->$name = "INT";
58
        return $this;
59
    }
60
61
    public function unsigned()
62
    {
63
        $this->{$this->last} .= " unsigned";
64
        return $this;
65
    }
66
67 30
    public function notNull()
68
    {
69 30
        $this->{$this->last} .= " NOT NULL";
70 30
        return $this;
71
    }
72
73
    public function references($table, $name)
74
    {
75
        $this->fk = "FOREIGN KEY ($this->last)";
76
        $this->references = "REFERENCES $table($name)";
77
        return $this;
78
    }
79
80
    public function onUpdate($method)
81
    {
82
        $this->onupdate = "ON UPDATE $method";
83
        return $this;
84
    }
85
86
    public function onDelete($method)
87
    {
88
        $this->ondelete = "ON DELETE $method";
89
        return $this;
90
    }
91
92 30
    public function getColumns()
93
    {
94 30
        return $this->columns;
95
    }
96
}
97