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

HasTableAlias::qualifyColumn()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
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