Completed
Push — master ( 74263e...a27851 )
by Jonas
02:34
created

HasTableAlias   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 21
ccs 6
cts 7
cp 0.8571
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A qualifyColumn() 0 13 3
1
<?php
2
3
namespace Znck\Eloquent\Traits;
4
5
use Illuminate\Support\Str;
6
7
trait HasTableAlias
8
{
9
    /**
10
     * Qualify the given column name by the model's table.
11
     *
12
     * @param string $column
13
     * @return string
14
     */
15 7
    public function qualifyColumn($column)
16
    {
17 7
        if (Str::contains($column, '.')) {
18
            return $column;
19
        }
20
21 7
        $table = $this->getTable();
0 ignored issues
show
Bug introduced by
It seems like getTable() 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

21
        /** @scrutinizer ignore-call */ 
22
        $table = $this->getTable();
Loading history...
22
23 7
        if (Str::contains($table, ' as ')) {
24 1
            $table = explode(' as ', $table)[1];
25
        }
26
27 7
        return $table.'.'.$column;
28
    }
29
}
30