Completed
Push — master ( 502914...9bc236 )
by ARCANEDEV
12:21
created

Model::setPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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