Completed
Pull Request — master (#4)
by ARCANEDEV
05:54
created

Model::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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 16
    public function getTable()
34
    {
35 16
        return $this->getPrefix() . parent::getTable();
36
    }
37
38
    /**
39
     * Get the prefix table associated with the model.
40
     *
41
     * @return null|string
42
     */
43 16
    public function getPrefix()
44
    {
45 16
        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 8
    public function setPrefix($prefix)
56
    {
57 8
        $this->prefix = $prefix;
58
59 8
        return $this;
60
    }
61
62
    /* ------------------------------------------------------------------------------------------------
63
     |  Check Functions
64
     | ------------------------------------------------------------------------------------------------
65
     */
66
    /**
67
     * Check if table is prefixed.
68
     *
69
     * @return bool
70
     */
71 16
    public function isPrefixed()
72
    {
73 16
        return ! is_null($this->prefix);
74
    }
75
}
76