Paginator::createLinks()   D
last analyzed

Complexity

Conditions 11
Paths 385

Size

Total Lines 39
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 39
rs 4.1708
c 1
b 0
f 0
cc 11
nc 385
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Ballybran\Helpers\Event;
4
5
use Ballybran\Database\DBconnection;
6
use Ballybran\Database\RegistryDatabase;
7
8
class Paginator extends DBconnection
9
{
10
11
    private $conn;
0 ignored issues
show
introduced by
The private property $conn is not used, and could be removed.
Loading history...
12
    private $limit;
13
    private $page;
14
    private $query;
15
    private $total;
0 ignored issues
show
introduced by
The private property $total is not used, and could be removed.
Loading history...
16
    private $starringlimit;
17
    private $totalpage;
18
    private $table;
0 ignored issues
show
introduced by
The private property $table is not used, and could be removed.
Loading history...
19
    private $total_result;
20
21
22
    public function __construct($dbType, $query, $limit)
23
    {
24
        $reg = new RegistryDatabase();
25
        $this->stmt = $reg->get($dbType);
0 ignored issues
show
Bug Best Practice introduced by
The property stmt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->limit = $limit;
27
        $this->query = $query;
28
        $this->page = $this->stmt->selectManager($this->query);
29
        $this->total_result = count($this->page);
30
        $this->totalpage = ceil($this->total_result / $this->limit);
31
32
33
    }
34
35
    public function getColum()
36
    {
37
38
39
        $this->page = (isset($_GET['page'])) ? $_GET['page'] : 1;
40
41
        $this->starringlimit = ($this->page - 1) * $this->limit;
42
43
        return $this->stmt->selectManager(" $this->query LIMIT $this->starringlimit, $this->limit");
44
45
    }
46
47
    public function createLinks($list_class)
48
    {
49
        if ($this->limit == 'all') {
50
            return '';
51
        }
52
        $links = (isset($_GET['links'])) ? $_GET['links'] : $this->total_result;
53
54
        $last = $this->totalpage;
55
56
        $start = (($this->page - $links) > 0) ? $this : 1;
57
        $end = (($this->page + $links) < $last) ? $this->page + $links : $last;
58
59
        $html = '<ul class="' . $list_class . '">';
60
61
        $class = ($this->page == 1) ? "disabled" : "";
62
        $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . '&page=' . ($this->page - 1) . '">&laquo;</a></li>';
63
64
65
        if ($start > 1) {
66
            $html .= '<li><a href="?limit=' . $this->limit . '&page=1">1</a></li>';
67
            $html .= '<li class="disabled"><span>...</span></li>';
68
        }
69
70
        for ($i = $start; $i <= $end; $i++) {
71
            $class = ($this->page == $i) ? "active" : "";
72
            $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . "&page=$i" . '">' . $i . '</a></li>';
0 ignored issues
show
Bug introduced by
Are you sure $i of type Ballybran\Helpers\Event\Paginator|integer can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
            $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . "&page=$i" . '">' . /** @scrutinizer ignore-type */ $i . '</a></li>';
Loading history...
73
        }
74
75
        if ($end < $last) {
76
            $html .= '<li class="disabled"><span>...</span></li>';
77
            $html .= '<li><a class="page-link" href="?limit=' . $this->limit . '&page=' . $last . '">' . $last . '</a></li>';
78
        }
79
80
        $class = ($this->page == $last) ? "disabled" : "";
81
        $html .= '<li class="' . $class . '"><a class="page-link" href="?limit=' . $this->limit . '&page=' . ($this->page + 1) . '">&raquo;</a></li>';
82
83
        $html .= '</ul>';
84
85
        return $html;
86
    }
87
}
88