HasPaginator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A paginate() 0 8 1
1
<?php
2
3
namespace Acacha\Users\Traits;
4
5
6
use Illuminate\Pagination\LengthAwarePaginator;
7
use Illuminate\Support\Collection;
8
9
/**
10
 * Class HasPaginator.
11
 * 
12
 * @package Acacha\Users\Traits
13
 */
14
trait HasPaginator
15
{
16
    /**
17
     * Create a length aware custom paginator instance.
18
     *
19
     * @param  Collection  $items
20
     * @param  int  $perPage
21
     * @return \Illuminate\Pagination\LengthAwarePaginator
22
     */
23
    protected function paginate($items, $perPage = 15)
24
    {
25
        $currentPage = LengthAwarePaginator::resolveCurrentPage();
26
27
        $currentPageItems = collect($items)->slice(($currentPage - 1) * $perPage, $perPage);
28
29
        return new LengthAwarePaginator($currentPageItems, count($items), $perPage);
30
    }
31
}