summaryrefslogtreecommitdiffstats
path: root/inc/paginate.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /inc/paginate.inc.php
parentUpdate phpstorm config (diff)
downloadslx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'inc/paginate.inc.php')
-rw-r--r--inc/paginate.inc.php25
1 files changed, 13 insertions, 12 deletions
diff --git a/inc/paginate.inc.php b/inc/paginate.inc.php
index 3187261c..b9a1ed78 100644
--- a/inc/paginate.inc.php
+++ b/inc/paginate.inc.php
@@ -9,15 +9,14 @@ class Paginate
private $totalRows = false;
/**
- * @query - The query that will return lines to show
- * @currentPage - 0based index of currently viewed page
- * @perPage - Number of items to show per page
- * @url - URL of current wegpage
+ * @param string $query - The query that will return lines to show
+ * @param int $perPage - Number of items to show per page
+ * @param ?string $url - URL of current wegpage
*/
- public function __construct($query, $perPage, $url = false)
+ public function __construct(string $query, int $perPage, string $url = null)
{
$this->currentPage = (isset($_GET['page']) ? (int)$_GET['page'] : 0);
- $this->perPage = (int)$perPage;
+ $this->perPage = $perPage;
if ($this->currentPage < 0) {
ErrorHandler::traceError('Current page < 0');
}
@@ -25,17 +24,17 @@ class Paginate
ErrorHandler::traceError('Per page < 1');
}
// Query
- if (!preg_match('/\s*SELECT\s/is', $query)) {
+ if (!preg_match('/\s*SELECT\s/i', $query)) {
ErrorHandler::traceError('Query has to start with SELECT!');
}
// XXX: MySQL only
- if (preg_match('/^mysql/i', CONFIG_SQL_DSN)) {
+ if (preg_match('/^(mysql|mariadb)/i', CONFIG_SQL_DSN)) {
// Sanity: Check for LIMIT specification at the end
if (preg_match('/LIMIT\s+(\d+|\:\w+|\?)\s*,\s*(\d+|\:\w+|\?)(\s|;)*(\-\-.*)?$/is', $query)) {
ErrorHandler::traceError("You cannot pass a query containing a LIMIT to the Paginator class!");
}
// Sanity: no comment or semi-colon at end (sloppy, might lead to false negatives)
- if (preg_match('/(\-\-|;)(\s|[^\'"`])*$/is', $query)) {
+ if (preg_match('/(\-\-|;)(\s|[^\'"`])*$/i', $query)) {
ErrorHandler::traceError("Your query must not end in a comment or semi-colon!");
}
// Don't use SQL_CALC_FOUND_ROWS as it leads to filesort frequently thus being slower than two queries
@@ -45,7 +44,9 @@ class Paginate
ErrorHandler::traceError('Unsupported database engine');
}
// Mangle URL
- if ($url === false) $url = $_SERVER['REQUEST_URI'];
+ if ($url === null) {
+ $url = $_SERVER['REQUEST_URI'];
+ }
if (strpos($url, '?') === false) {
$url .= '?';
} else {
@@ -60,7 +61,7 @@ class Paginate
/**
* Execute the query, returning the PDO query object
*/
- public function exec($args = array())
+ public function exec(array $args = [])
{
$countQuery = preg_replace('/ORDER\s+BY\s.*?(\sASC|\sDESC|$)/is', '', $this->query);
$countQuery = preg_replace('/SELECT\s.*?\sFROM\s/is', 'SELECT Count(*) AS rowcount FROM ', $countQuery);
@@ -71,7 +72,7 @@ class Paginate
return $retval;
}
- public function render($template, $data)
+ public function render(string $template, array $data): void
{
if ($this->totalRows == 0) {
// Shortcut for no content