Completed
Push — master ( dd4dc5...d1e582 )
by ARCANEDEV
04:29
created

Paginatable   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A paginate() 0 13 1
1
<?php namespace Arcanedev\Support\Traits;
2
3
use Illuminate\Http\Request;
4
use Illuminate\Pagination\LengthAwarePaginator;
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Trait     Paginatable
9
 *
10
 * @package  Arcanedev\Support\Traits
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
trait Paginatable
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Main Functions
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Paginate the collection.
21
     *
22
     * @param  \Illuminate\Support\Collection  $data
23
     * @param  \Illuminate\Http\Request        $request
24
     * @param  int                             $perPage
25
     *
26
     * @return \Illuminate\Pagination\LengthAwarePaginator
27
     */
28
    protected function paginate(Collection $data, Request $request, $perPage)
29
    {
30
        $page = $request->get('page', 1);
31
        $path = $request->url();
32
33
        return new LengthAwarePaginator(
34
            $data->forPage($page, $perPage),
35
            $data->count(),
36
            $perPage,
37
            $page,
38
            compact('path')
39
        );
40
    }
41
}
42