Completed
Push — master ( 03af29...6d12c1 )
by Vincenzo
02:16
created

Pagination   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getPaginationParams() 0 21 4
1
<?php
2
3
namespace App\Lib\Slime\RestAction\Traits;
4
5
use App\Lib\Helpers\Config;
6
7
trait Pagination
8
{
9
    protected $pageParam = 'p';
10
    protected $limitParam = 'l';
11
12
    public function getPaginationParams($request)
13
    {
14
        $page = $request->getParam(
15
            $this->pageParam,
16
            1
17
        );
18
19
        $limit = $request->getParam(
20
            $this->limitParam,
21
            Config::get('pagination.defaultLimit')
22
        );
23
24
        $page = $page > 0 ? $page : 1;
25
        $limit = $limit >= Config::get('pagination.minLimit') && $limit <= Config::get('pagination.maxLimit')
26
            ? $limit : Config::get('pagination.defaultLimit');
27
28
        return [
29
            'page' => $page,
30
            'limit' => $limit
31
        ];
32
    }
33
34
}