HasLimit   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 28
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A limit() 0 9 2
A take() 0 3 1
1
<?php
2
3
namespace Staudenmeir\EloquentEagerLimit\Relations;
4
5
trait HasLimit
6
{
7
    /**
8
     * Alias to set the "limit" value of the query.
9
     *
10
     * @param int $value
11
     * @return $this
12
     */
13 20
    public function take($value)
14
    {
15 20
        return $this->limit($value);
16
    }
17
18
    /**
19
     * Set the "limit" value of the query.
20
     *
21
     * @param int $value
22
     * @return $this
23
     */
24 64
    public function limit($value)
25
    {
26 64
        if ($this->parent->exists) {
27 24
            $this->query->limit($value);
28
        } else {
29 48
            $this->query->groupLimit($value, $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

29
            $this->query->groupLimit($value, $this->/** @scrutinizer ignore-call */ getExistenceCompareKey());
Loading history...
30
        }
31
32 64
        return $this;
33
    }
34
}
35