Passed
Push — master ( 371e3b...7e5a5d )
by Jonas
05:54
created

BelongsOrMorphToMany::limit()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.9666
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Staudenmeir\EloquentEagerLimit\Relations;
4
5
use Illuminate\Database\Query\Grammars\MySqlGrammar;
6
7
trait BelongsOrMorphToMany
8
{
9
    use HasLimit;
10
11
    /**
12
     * Set the "limit" value of the query.
13
     *
14
     * @param int $value
15
     * @return $this
16
     */
17 32
    public function limit($value)
18
    {
19 32
        if ($this->parent->exists) {
20 8
            $this->query->limit($value);
21
        } else {
22 24
            $column = $this->getExistenceCompareKey();
0 ignored issues
show
Bug introduced by
It seems like getExistenceCompareKey() 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

22
            /** @scrutinizer ignore-call */ 
23
            $column = $this->getExistenceCompareKey();
Loading history...
23
24 24
            $grammar = $this->query->getQuery()->getGrammar();
25
26 24
            if ($grammar instanceof MySqlGrammar && $grammar->useLegacyGroupLimit($this->query->getQuery())) {
27 6
                $column = 'pivot_'.last(explode('.', $column));
28
            }
29
30 24
            $this->query->groupLimit($value, $column);
31
        }
32
33 32
        return $this;
34
    }
35
}
36