Completed
Push — master ( ed61e9...497a60 )
by Rougin
04:46
created

ModelTrait::table()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
/**
6
 * Model Trait
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
trait ModelTrait
12
{
13
    /**
14
     * Columns that will be displayed.
15
     * If not set, it will get the columns from the database table.
16
     *
17
     * @var array
18
     */
19
    protected $columns = array();
20
21
    /**
22
     * Columns that will be hidden in the display.
23
     * If not set, it will hide a "password" column if it exists.
24
     *
25
     * @var array
26
     */
27
    protected $hidden = array('password');
28
29
    /**
30
     * Model's default primary key or unique identifier.
31
     *
32
     * @var string
33
     */
34
    protected $primary_key = 'id';
35
36
    /**
37
     * The table associated with the model.
38
     *
39
     * @var string
40
     */
41
    protected $table = '';
42
43
    /**
44
     * Returns the specified primary key of the model.
45
     * NOTE: To be removed in v1.0.0. Use $this->primary instead.
46
     *
47
     * @return string
48
     */
49
    public function getPrimaryKey()
50
    {
51
        return $this->primary();
52
    }
53
54
    /**
55
     * Returns the specified primary key of the model.
56
     *
57
     * @return string
58
     */
59 6
    public function primary()
60
    {
61 6
        return $this->primary_key;
62
    }
63
64
    /**
65
     * Returns the values from the model's properties.
66
     * NOTE: To be removed in v1.0.0. Use $this->properties instead.
67
     *
68
     * @return array
69
     */
70
    public function getProperties()
71
    {
72
        return $this->properties();
73
    }
74
75
    /**
76
     * Returns the values from the model's properties.
77
     *
78
     * @return array
79
     */
80 36
    public function properties()
81
    {
82 36
        $properties = array();
83
84 36
        $properties['columns'] = $this->columns;
85
86 36
        $properties['hidden']  = $this->hidden;
87
88 36
        return $properties;
89
    }
90
91
    /**
92
     * Returns the specified table name of the model.
93
     * NOTE: To be removed in v1.0.0. Use $this->table instead.
94
     *
95
     * @return string
96
     */
97
    public function getTableName()
98
    {
99
        return $this->table();
100
    }
101
102
    /**
103
     * Returns the specified table name of the model.
104
     *
105
     * @return string
106
     */
107 42
    public function table()
108
    {
109 42
        $table = plural(strtolower(get_class($this)));
110
111 42
        return $this->table ? $this->table : $table;
112
    }
113
}
114