Passed
Push — master ( f90e65...c97d58 )
by Yaroslav
04:32
created

HasTableWithSuffix   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
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 26
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 11 3
A useSuffix() 0 9 2
1
<?php
2
3
namespace LaraGeoData\Models;
4
5
trait HasTableWithSuffix
6
{
7
    abstract public function getTableNameRoot(): string;
8
9 4
    public function getTable()
10
    {
11 4
        if ($this->table) {
12 4
            return $this->table;
13
        }
14 2
        $tableName = $this->getTableNameRoot();
15 2
        if ($suffix = config('geonames.database.default_suffix')) {
16 2
            $tableName = "{$tableName}_{$suffix}";
17
        }
18
19 2
        return $tableName;
20
    }
21
22 4
    public static function useSuffix(?string $suffix = null): static
23
    {
24 4
        $instance  = new static();
25 4
        $tableName = $instance->getTableNameRoot();
26 4
        if ($suffix) {
27 4
            $tableName = "{$tableName}_{$suffix}";
28
        }
29
30 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

30
        return $instance->/** @scrutinizer ignore-call */ setTable($tableName);
Loading history...
31
    }
32
}
33