HasTableWithSuffix   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 11 3
A makeUsingSuffix() 0 9 2
1
<?php
2
3
namespace LaraGeoData\Models;
4
5
trait HasTableWithSuffix
6
{
7
    /**
8
     * Get base table name (root name, without suffix).
9
     *
10
     * @return string
11
     */
12
    abstract public function getTableNameRoot(): string;
13
14
    /**
15
     * @inheritDoc
16
     */
17 4
    public function getTable(): string
18
    {
19 4
        if ($this->table) {
20 4
            return $this->table;
21
        }
22 2
        $tableName = $this->getTableNameRoot();
23 2
        if ($suffix = config('geonames.database.default_suffix')) {
24 2
            $tableName = "{$tableName}_{$suffix}";
25
        }
26
27 2
        return $tableName;
28
    }
29
30
    /**
31
     * Initialise model with suffixed table name.
32
     *
33
     * @param string|null $suffix
34
     * @return static
35
     */
36 4
    public static function makeUsingSuffix(?string $suffix = null): static
37
    {
38 4
        $instance  = new static();
39 4
        $tableName = $instance->getTableNameRoot();
40 4
        if ($suffix) {
41 4
            $tableName = "{$tableName}_{$suffix}";
42
        }
43
44 4
        return $instance->setTable($tableName);
0 ignored issues
show
Bug introduced by
It seems like setTable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        return $instance->/** @scrutinizer ignore-call */ setTable($tableName);
Loading history...
45
    }
46
}
47