Completed
Pull Request — master (#1)
by Rougin
02:23
created

ModelTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 76
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumns() 0 4 1
A getHiddenColumns() 0 4 1
A getPrimaryKey() 0 4 1
A getTableName() 0 8 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 = [];
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 = [ '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 columns of the model.
45
     *
46
     * @return array
47
     */
48 12
    public function getColumns()
49
    {
50 12
        return $this->columns;
51
    }
52
53
    /**
54
     * Returns the specified hidden columns of the model.
55
     *
56
     * @return array
57
     */
58 12
    public function getHiddenColumns()
59
    {
60 12
        return $this->hidden;
61
    }
62
63
    /**
64
     * Gets the specified primary key of the model.
65
     *
66
     * @return string
67
     */
68 3
    public function getPrimaryKey()
69
    {
70 3
        return $this->primary_key;
71
    }
72
73
    /**
74
     * Gets the specified table name of the model.
75
     *
76
     * @return string
77
     */
78 15
    public function getTableName()
79
    {
80 15
        if (! $this->table) {
81 15
            return plural(strtolower(get_class($this)));
82
        }
83
84
        return $this->table;
85
    }
86
}
87