Completed
Push — master ( f5dbf7...c3a999 )
by ARCANEDEV
12:57
created

SpammersController::paginate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 3
crap 2
1
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin;
2
3
use Arcanedev\SpamBlocker\Contracts\SpamBlocker;
4
use Illuminate\Http\Request;
5
use Illuminate\Pagination\LengthAwarePaginator;
6
use Illuminate\Support\Collection;
7
8
/**
9
 * Class     SpammersController
10
 *
11
 * @package  Arcanesoft\Seo\Http\Controllers\Admin
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class SpammersController extends Controller
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Properties
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * The spam blocker instance.
22
     *
23
     * @var \Arcanedev\SpamBlocker\Contracts\SpamBlocker
24
     */
25
    protected $blocker;
26
27
    /**
28
     * Number of items per page for pagination.
29
     *
30
     * @var int
31
     */
32
    protected $perPage = 50;
33
34
    /* ------------------------------------------------------------------------------------------------
35
     |  Constructor
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    /**
39
     * MetasController constructor.
40
     *
41
     * @param  \Arcanedev\SpamBlocker\Contracts\SpamBlocker  $blocker
42
     */
43
    public function __construct(SpamBlocker $blocker)
44
    {
45
        parent::__construct();
46
47
        $this->blocker = $blocker;
48
49
        $this->setCurrentPage('seo-spammers');
50
        $this->addBreadcrumbRoute('Spammers', 'admin::seo.spammers.index');
51
    }
52
53
    /* ------------------------------------------------------------------------------------------------
54
     |  Main Functions
55
     | ------------------------------------------------------------------------------------------------
56
     */
57
    /**
58
     * List all the spammers.
59
     *
60
     * @param  \Illuminate\Http\Request  $request
61
     *
62
     * @return \Illuminate\View\View
63
     */
64
    public function index(Request $request)
65
    {
66
        $this->setTitle($title = 'List of Spammers');
67
        $this->addBreadcrumb($title);
68
69
        $spammers = $this->paginate($this->blocker->all(), $request, $this->perPage);
70
71
        return $this->view('admin.spammers.index', compact('spammers'));
72
    }
73
74
    /* ------------------------------------------------------------------------------------------------
75
     |  Other Functions
76
     | ------------------------------------------------------------------------------------------------
77
     */
78
    /**
79
     * Paginate the collection.
80
     *
81
     * @param  \Illuminate\Support\Collection  $data
82
     * @param  \Illuminate\Http\Request        $request
83
     * @param  int                             $perPage
84
     *
85
     * @return \Illuminate\Pagination\LengthAwarePaginator
86
     */
87
    protected function paginate(Collection $data, Request $request, $perPage)
88
    {
89
        $page = $request->get('page', 1);
90
        $path = $request->url();
91
92
        return new LengthAwarePaginator(
93
            $data->forPage($page, $perPage),
94
            $data->count(),
95
            $perPage,
96
            $page,
97
            compact('path')
98
        );
99
    }
100
}
101