SpammersController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 91
ccs 0
cts 26
cp 0
rs 10
c 3
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A index() 0 9 1
A paginate() 0 13 1
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
    /**
22
     * The spam blocker instance.
23
     *
24
     * @var \Arcanedev\SpamBlocker\Contracts\SpamBlocker
25
     */
26
    protected $blocker;
27
28
    /**
29
     * Number of items per page for pagination.
30
     *
31
     * @var int
32
     */
33
    protected $perPage = 50;
34
35
    /* -----------------------------------------------------------------
36
     |  Constructor
37
     | -----------------------------------------------------------------
38
     */
39
40
    /**
41
     * SpammersController constructor.
42
     *
43
     * @param  \Arcanedev\SpamBlocker\Contracts\SpamBlocker  $blocker
44
     */
45
    public function __construct(SpamBlocker $blocker)
46
    {
47
        parent::__construct();
48
49
        $this->blocker = $blocker;
50
51
        $this->setCurrentPage('seo-spammers');
52
        $this->addBreadcrumbRoute(trans('seo::spammers.titles.spammers'), 'admin::seo.spammers.index');
53
    }
54
55
    /* -----------------------------------------------------------------
56
     |  Main Methods
57
     | -----------------------------------------------------------------
58
     */
59
60
    /**
61
     * List all the spammers.
62
     *
63
     * @param  \Illuminate\Http\Request  $request
64
     *
65
     * @return \Illuminate\View\View
66
     */
67
    public function index(Request $request)
68
    {
69
        $spammers = $this->paginate($this->blocker->all(), $request, $this->perPage);
70
71
        $this->setTitle($title = trans('seo::spammers.titles.spammers-list'));
72
        $this->addBreadcrumb($title);
73
74
        return $this->view('admin.spammers.index', compact('spammers'));
75
    }
76
77
    /* -----------------------------------------------------------------
78
     |  Other Methods
79
     | -----------------------------------------------------------------
80
     */
81
82
    /**
83
     * Paginate the collection.
84
     *
85
     * @param  \Illuminate\Support\Collection  $data
86
     * @param  \Illuminate\Http\Request        $request
87
     * @param  int                             $perPage
88
     *
89
     * @return \Illuminate\Pagination\LengthAwarePaginator
90
     */
91
    protected function paginate(Collection $data, Request $request, $perPage)
92
    {
93
        $page = $request->get('page', 1);
94
        $path = $request->url();
95
96
        return new LengthAwarePaginator(
97
            $data->forPage($page, $perPage),
98
            $data->count(),
99
            $perPage,
100
            $page,
101
            compact('path')
102
        );
103
    }
104
}
105