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

ModelTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 59
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumns() 0 4 1
A getHiddenColumns() 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
     * The table associated with the model.
31
     *
32
     * @var string
33
     */
34
    protected $table = '';
35
36
    /**
37
     * Returns the specified columns of the model.
38
     *
39
     * @return array
40
     */
41 9
    public function getColumns()
42
    {
43 9
        return $this->columns;
44
    }
45
46
    /**
47
     * Returns the specified hidden columns of the model.
48
     *
49
     * @return array
50
     */
51
    public function getHiddenColumns()
52
    {
53
        return $this->hidden;
54
    }
55
56
    /**
57
     * Gets the specified table name of the model.
58
     *
59
     * @return string
60
     */
61 9
    public function getTableName()
62
    {
63 9
        if (! $this->table) {
64 9
            return plural(strtolower(get_class($this)));
65
        }
66
67
        return $this->table;
68
    }
69
}
70