Completed
Push — master ( 784e72...c87e8f )
by Jonas
02:18
created

HasTableAlias   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A qualifyColumn() 0 13 3
A setAlias() 0 3 1
1
<?php
2
3
namespace Staudenmeir\EloquentHasManyDeep;
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 26
    public function qualifyColumn($column)
16
    {
17 26
        if (Str::contains($column, '.')) {
18 4
            return $column;
19
        }
20
21 23
        $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 23
        if (Str::contains($table, ' as ')) {
24 3
            $table = explode(' as ', $table)[1];
25
        }
26
27 23
        return $table.'.'.$column;
28
    }
29
30
    /**
31
     * Set an alias for the model's table.
32
     *
33
     * @param string $alias
34
     * @return $this
35
     */
36 1
    public function setAlias($alias)
37
    {
38 1
        return $this->setTable($this->getTable().' as '.$alias);
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

38
        return $this->/** @scrutinizer ignore-call */ setTable($this->getTable().' as '.$alias);
Loading history...
39
    }
40
}
41