HasTableAlias   A
last analyzed

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 setAlias() 0 3 1
A qualifyColumn() 0 13 3
1
<?php
2
3
namespace Staudenmeir\EloquentHasManyDeep;
4
5
trait HasTableAlias
6
{
7
    /**
8
     * Qualify the given column name by the model's table.
9
     *
10
     * @param string $column
11
     * @return string
12
     */
13 114
    public function qualifyColumn($column)
14
    {
15 114
        if (str_contains($column, '.')) {
16 2
            return $column;
17
        }
18
19 114
        $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

19
        /** @scrutinizer ignore-call */ 
20
        $table = $this->getTable();
Loading history...
20
21 114
        if (str_contains($table, ' as ')) {
22 17
            $table = explode(' as ', $table)[1];
23
        }
24
25 114
        return $table.'.'.$column;
26
    }
27
28
    /**
29
     * Set an alias for the model's table.
30
     *
31
     * @param string $alias
32
     * @return $this
33
     */
34 2
    public function setAlias($alias)
35
    {
36 2
        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

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