Completed
Pull Request — master (#7)
by Rougin
02:16
created

ModelTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 0
dl 0
loc 71
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

3 Methods

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