Failed Conditions
Push — master ( 11c8ec...b620eb )
by Bas
05:48 queued 10s
created

IsAranguentModel::newBaseQueryBuilder()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Eloquent\Concerns;
4
5
use Illuminate\Support\Str;
6
use LaravelFreelancerNL\Aranguent\Eloquent\Builder;
7
use LaravelFreelancerNL\Aranguent\Query\Builder as QueryBuilder;
8
9
trait IsAranguentModel
10
{
11
    /**
12
     * @override
13
     * Create a new Eloquent query builder for the model.
14
     *
15
     * @param QueryBuilder $query
16
     *
17
     * @return Builder
18
     */
19 57
    public function newEloquentBuilder($query)
20
    {
21 57
        return new Builder($query);
22
    }
23
24
    /**
25
     * Get a new query builder instance for the connection.
26
     *
27
     * @return \Illuminate\Database\Query\Builder
28
     */
29 57
    protected function newBaseQueryBuilder()
30
    {
31 57
        return $this->getConnection()->query();
0 ignored issues
show
Bug introduced by
It seems like getConnection() 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

31
        return $this->/** @scrutinizer ignore-call */ getConnection()->query();
Loading history...
32
    }
33
34
    /**
35
     * Qualify the given column name by the model's table.
36
     *
37
     * @param string $column
38
     *
39
     * @return string
40
     */
41 33
    public function qualifyColumn($column)
42
    {
43 33
        $tableReferer = Str::singular($this->getTable()) . 'Doc';
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

43
        $tableReferer = Str::singular($this->/** @scrutinizer ignore-call */ getTable()) . 'Doc';
Loading history...
44
45 33
        if (Str::startsWith($column, $tableReferer . '.')) {
46
            return $column;
47
        }
48
49 33
        return $tableReferer . '.' . $column;
50
    }
51
52
    /**
53
     * Get the default foreign key name for the model.
54
     *
55
     * @return string
56
     */
57 7
    public function getForeignKey()
58
    {
59 7
        $keyName = $this->getKeyName();
0 ignored issues
show
Bug introduced by
It seems like getKeyName() 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

59
        /** @scrutinizer ignore-call */ 
60
        $keyName = $this->getKeyName();
Loading history...
60
61 7
        if ($keyName[0] != '_') {
62
            $keyName = '_' . $keyName;
63
        }
64
65 7
        return Str::snake(class_basename($this)) . $keyName;
66
    }
67
}
68