Completed
Push — master ( 9bc236...8662c2 )
by ARCANEDEV
07:20
created

PrefixedModel::getTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php namespace Arcanedev\Support\Traits;
2
3
/**
4
 * Trait     PrefixedModel
5
 *
6
 * @package  Arcanedev\Support\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
trait PrefixedModel
10
{
11
    /* ------------------------------------------------------------------------------------------------
12
     |  Properties
13
     | ------------------------------------------------------------------------------------------------
14
     */
15
    /**
16
     * The table prefix.
17
     *
18
     * @var string|null
19
     */
20
    protected $prefix;
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Getters & Setters
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * Get the table associated with the model.
28
     *
29
     * @return string
30
     */
31 16
    public function getTable()
32
    {
33 16
        return $this->getPrefix() . parent::getTable();
34
    }
35
36
    /**
37
     * Get the prefix table associated with the model.
38
     *
39
     * @return null|string
40
     */
41 16
    public function getPrefix()
42
    {
43 16
        return $this->isPrefixed() ? $this->prefix : '';
44
    }
45
46
    /**
47
     * Set the prefix table associated with the model.
48
     *
49
     * @param  string  $prefix
50
     *
51
     * @return self
52
     */
53 8
    public function setPrefix($prefix)
54
    {
55 8
        $this->prefix = $prefix;
56
57 8
        return $this;
58
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Check Functions
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Check if table is prefixed.
66
     *
67
     * @return bool
68
     */
69 16
    public function isPrefixed()
70
    {
71 16
        return ! is_null($this->prefix);
72
    }
73
}
74