Completed
Push — master ( 184560...9805df )
by ARCANEDEV
21s queued 18s
created

PrefixedModel::getTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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