17
17
18
18
namespace phpMyFAQ ;
19
19
20
+ use phpMyFAQ \Core \Exception ;
20
21
use phpMyFAQ \Database \DatabaseDriver ;
21
22
use phpMyFAQ \Database \Mysqli ;
22
23
use phpMyFAQ \Database \Pgsql ;
@@ -33,23 +34,23 @@ class Database
33
34
/**
34
35
* Instance.
35
36
*
36
- * @var DatabaseDriver
37
+ * @var DatabaseDriver|null
37
38
*/
38
- private static $ instance = null ;
39
+ private static ? DatabaseDriver $ instance = null ;
39
40
40
41
/**
41
42
* Database type.
42
43
*
43
- * @var string
44
+ * @var string|null
44
45
*/
45
- private static $ dbType = null ;
46
+ private static ? string $ dbType = null ;
46
47
47
48
/**
48
49
* Table prefix.
49
50
*
50
- * @var string
51
+ * @var string|null
51
52
*/
52
- private static $ tablePrefix = null ;
53
+ private static ? string $ tablePrefix = null ;
53
54
54
55
/**
55
56
* Constructor.
@@ -62,15 +63,14 @@ private function __construct()
62
63
* Database factory.
63
64
*
64
65
* @param string $type Database management system type
65
- *
66
- * @return Mysqli|Pgsql|Sqlite3|Sqlsrv
66
+ * @return Pgsql|Sqlsrv|Mysqli|Sqlite3|DatabaseDriver|null
67
67
* @throws Exception
68
68
*/
69
- public static function factory ($ type )
69
+ public static function factory (string $ type ): Pgsql | Sqlsrv | Mysqli | Sqlite3 | DatabaseDriver | null
70
70
{
71
71
self ::$ dbType = $ type ;
72
72
73
- if (0 === strpos ($ type , 'pdo_ ' )) {
73
+ if (str_starts_with ($ type , 'pdo_ ' )) {
74
74
$ class = 'phpMyFAQ\Database\Pdo_ ' . ucfirst (substr ($ type , 4 ));
75
75
} else {
76
76
$ class = 'phpMyFAQ\Database \\' . ucfirst ($ type );
@@ -88,9 +88,9 @@ public static function factory($type)
88
88
/**
89
89
* Returns the single instance.
90
90
*
91
- * @return DatabaseDriver
91
+ * @return DatabaseDriver|null
92
92
*/
93
- public static function getInstance ()
93
+ public static function getInstance (): ? DatabaseDriver
94
94
{
95
95
if (null == self ::$ instance ) {
96
96
$ className = __CLASS__ ;
@@ -110,9 +110,9 @@ private function __clone()
110
110
/**
111
111
* Returns the database type.
112
112
*
113
- * @return string
113
+ * @return string|null
114
114
*/
115
- public static function getType ()
115
+ public static function getType (): ? string
116
116
{
117
117
return self ::$ dbType ;
118
118
}
@@ -121,10 +121,9 @@ public static function getType()
121
121
* Check if a table is filled with data.
122
122
*
123
123
* @param string $tableName Table name
124
- *
125
124
* @return bool true, if table is empty, otherwise false
126
125
*/
127
- public static function checkOnEmptyTable ($ tableName )
126
+ public static function checkOnEmptyTable (string $ tableName ): bool
128
127
{
129
128
if (
130
129
self ::$ instance ->numRows (
@@ -139,18 +138,16 @@ public static function checkOnEmptyTable($tableName)
139
138
140
139
/**
141
140
* Error page, if the database connection is not possible.
141
+ *
142
142
* @param string $method
143
143
*/
144
- public static function errorPage ($ method )
144
+ public static function errorPage (string $ method )
145
145
{
146
146
echo '<!DOCTYPE html>
147
147
<html lang="en" class="no-js">
148
148
<head>
149
149
<meta charset="utf-8">
150
150
<title>Fatal phpMyFAQ Error</title>
151
- <style type="text/css">
152
- @import url("assets/themes/default/css/style.min.css");
153
- </style>
154
151
</head>
155
152
<body>
156
153
<div class="container">
@@ -166,17 +163,17 @@ public static function errorPage($method)
166
163
*
167
164
* @param string $tablePrefix
168
165
*/
169
- public static function setTablePrefix ($ tablePrefix )
166
+ public static function setTablePrefix (string $ tablePrefix )
170
167
{
171
168
self ::$ tablePrefix = $ tablePrefix ;
172
169
}
173
170
174
171
/**
175
172
* Returns the table prefix.
176
173
*
177
- * @return string
174
+ * @return string|null
178
175
*/
179
- public static function getTablePrefix ()
176
+ public static function getTablePrefix (): ? string
180
177
{
181
178
return self ::$ tablePrefix ;
182
179
}
0 commit comments