Test Failed
Pull Request — master (#116)
by Zing
04:20
created

Pageable::enablePaginator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Concerns;
6
7
use Zing\QueryBuilder\Paginator;
8
9
trait Pageable
10
{
11
    /**
12
     * @param string|\Zing\QueryBuilder\Paginator $paginator
13
     *
14
     * @return $this
15
     */
16
    public function enablePaginator(?string $paginator = null)
17
    {
18
        $paginator = $paginator instanceof Paginator ? $paginator : Paginator::name($paginator);
19
        $perPage = $this->request->input($paginator->getName(), $paginator->getDefault());
20
        $this->builder->getModel()
21
            ->setPerPage($perPage);
22
23
        return $this;
24
    }
25
}
26