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

HasTableAlias::setAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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