GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Pagination::previousPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * Pagination Class
5
 *
6
 * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
7
 * @author     Omar El Gabry <[email protected]>
8
 */
9
10
class Pagination {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
12
    /**
13
     * @access public
14
     * @var integer Current Page
15
     */
16
    public $currentPage;
17
18
    /**
19
     * @access public
20
     * @var integer Number of items(newsfeed, posts, ..etc.) to be displayed per page
21
     */
22
    public $perPage;
23
24
    /**
25
     * @access public
26
     * @var integer Total count of items(newsfeed, posts, ..etc.)
27
     */
28
    public $totalCount;
29
30
    /**
31
     * This is the constructor for Pagination Object.
32
     *
33
     * @access  public
34
     * @param   integer  $currentPage
35
     * @param   integer  $totalCount
36
     * @param   integer  $perPage Number of items per page
37
     */
38
    public function __construct($currentPage = 1, $totalCount = 0, $perPage = 0){
39
        $this->currentPage = (empty($currentPage))? 1: (int)$currentPage;
40
        $this->totalCount = (empty($totalCount))? 0: (int)$totalCount;
41
        $this->perPage = (empty($perPage))? Config::get('PAGINATION_DEFAULT_LIMIT'): (int)$perPage;
0 ignored issues
show
Documentation Bug introduced by
It seems like empty($perPage) ? \Confi...IMIT') : (int) $perPage can also be of type string. However, the property $perPage is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
42
    }
43
44
    /**
45
     * get pagination object by executing COUNT(*) query.
46
     *
47
     * @access public
48
     * @param  string  $table
49
     * @param  string  $options
50
     * @param  array   $values  array of data
51
     * @param  integer $pageNum
52
     * @param  integer $extraOffset check comment class
53
     * @return Pagination
54
     */
55
    public static function pagination($table, $options, $values, $pageNum, $extraOffset = 0){
56
57
        $database = Database::openConnection();
58
        $query  = "SELECT COUNT(*) AS count FROM {$table}  ";
59
        $query .= $options;
60
61
        $database->prepare($query);
62
        $database->execute($values);
63
        $totalCount = $database->fetchAssociative()["count"];
64
        $extraOffset = ((int)$extraOffset > $totalCount)? 0: (int)$extraOffset;
65
66
        return new Pagination((int)$pageNum, $totalCount - $extraOffset);
67
    }
68
69
    /**
70
     * Get the offset.
71
     *
72
     * @access public
73
     * @return integer
74
     */
75
    public function getOffset() {
76
        return ($this->currentPage - 1) * $this->perPage;
77
    }
78
79
    /**
80
     * Get number of total pages.
81
     *
82
     * @access public
83
     * @return integer
84
     */
85
    public function totalPages() {
86
        return ceil($this->totalCount/$this->perPage);
87
    }
88
89
    /**
90
     * Get the number of the previous page.
91
     *
92
     * @access public
93
     * @return integer  Number of previous page
94
     */
95
    public function previousPage() {
96
        return $this->currentPage - 1;
97
    }
98
99
    /**
100
     * Get the number of the next page.
101
     *
102
     * @access public
103
     * @return integer  Number of next page
104
     */
105
    public function nextPage() {
106
        return $this->currentPage + 1;
107
    }
108
109
    /**
110
     * checks if there is a previous page or not
111
     *
112
     * @access public
113
     * @return boolean
114
     */
115
    public function hasPreviousPage() {
116
        return $this->previousPage() >= 1 ? true : false;
117
    }
118
119
    /**
120
     * checks if there is a next page or not
121
     *
122
     * @access public
123
     * @return boolean
124
     */
125
    public function hasNextPage() {
126
        return $this->totalPages() >= $this->nextPage()? true : false;
127
    }
128
129
}
130