Skip to content

Commit

Permalink
refactor: added missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Apr 9, 2022
1 parent 0dc37b5 commit 933a8ce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
22 changes: 10 additions & 12 deletions phpmyfaq/src/phpMyFAQ/Instance/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Database
/**
* Instance.
*
* @var Driver
* @var Driver|null
*/
private static $instance = null;
private static ?Driver $instance = null;

/**
* Database type.
Expand All @@ -44,13 +44,13 @@ class Database
/**
* @var Configuration
*/
protected $config;
protected Configuration $config;
/**
* DROP TABLE statements.
*
* @var array
*/
private $dropTableStmts = [
private array $dropTableStmts = [
'DROP TABLE %sfaqadminlog',
'DROP TABLE %sfaqattachment',
'DROP TABLE %sfaqattachment_file',
Expand Down Expand Up @@ -102,12 +102,11 @@ private function __construct(Configuration $config)
* Database factory.
*
* @param Configuration $config phpMyFAQ configuration container
* @param string $type Database management system type
*
* @return Driver
* @param string $type Database management system type
* @return Driver|null
* @throws Exception
*/
public static function factory(Configuration $config, $type)
public static function factory(Configuration $config, string $type): ?Driver
{
self::$dbType = $type;

Expand All @@ -125,9 +124,9 @@ public static function factory(Configuration $config, $type)
/**
* Returns the single instance.
*
* @return Driver
* @return Driver|null
*/
public static function getInstance()
public static function getInstance(): ?Driver
{
if (null === self::$instance) {
$className = __CLASS__;
Expand All @@ -141,10 +140,9 @@ public static function getInstance()
* Executes all DROP TABLE statements.
*
* @param string $prefix
*
* @return bool
*/
public function dropTables($prefix = '')
public function dropTables(string $prefix = ''): bool
{
foreach ($this->dropTableStmts as $stmt) {
$result = $this->config->getDb()->query(sprintf($stmt, $prefix));
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Instance/Database/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ interface Driver
*
* @return bool
*/
public function createTables(string $prefix = '');
public function createTables(string $prefix = ''): bool;
}
4 changes: 2 additions & 2 deletions phpmyfaq/src/phpMyFAQ/Instance/Database/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Mysqli extends Database implements Driver
/**
* @var array
*/
private $createTableStatements = [
private array $createTableStatements = [
'faqadminlog' => 'CREATE TABLE %sfaqadminlog (
id INT(11) NOT NULL,
time INT(11) NOT NULL,
Expand All @@ -52,7 +52,7 @@ class Mysqli extends Database implements Driver
mime_type VARCHAR(255) NULL,
PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci',

'faqattachment file' => 'CREATE TABLE %sfaqattachment_file (
'faqattachment_file' => 'CREATE TABLE %sfaqattachment_file (
virtual_hash CHAR(32) NOT NULL,
contents BLOB NOT NULL,
PRIMARY KEY (virtual_hash)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci',
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Instance/Database/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Pgsql extends Database implements Driver
mime_type VARCHAR(255) NULL,
PRIMARY KEY (id))',

'faqattachment file' => 'CREATE TABLE %sfaqattachment_file (
'faqattachment_file' => 'CREATE TABLE %sfaqattachment_file (
virtual_hash CHAR(32) NOT NULL,
contents BYTEA,
PRIMARY KEY (virtual_hash))',
Expand Down
6 changes: 3 additions & 3 deletions phpmyfaq/src/phpMyFAQ/Instance/Database/Sqlite3.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Sqlite3 extends Database implements Driver
/**
* @var array
*/
private $createTableStatements = [
private array $createTableStatements = [
'faqadminlog' => 'CREATE TABLE %sfaqadminlog (
id INTEGER NOT NULL,
time INTEGER NOT NULL,
Expand All @@ -52,7 +52,7 @@ class Sqlite3 extends Database implements Driver
mime_type VARCHAR(255) NULL,
PRIMARY KEY (id))',

'faqattachment file' => 'CREATE TABLE %sfaqattachment_file (
'faqattachment_file' => 'CREATE TABLE %sfaqattachment_file (
virtual_hash CHAR(32) NOT NULL,
contents TEXT NOT NULL,
PRIMARY KEY (virtual_hash))',
Expand Down Expand Up @@ -395,7 +395,7 @@ public function __construct(Configuration $config)
*
* @return bool
*/
public function createTables(string $prefix = '')
public function createTables(string $prefix = ''): bool
{
foreach ($this->createTableStatements as $stmt) {
$result = $this->config->getDb()->query(sprintf($stmt, $prefix));
Expand Down
6 changes: 3 additions & 3 deletions phpmyfaq/src/phpMyFAQ/Instance/Database/Sqlsrv.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* The phpMyFAQ instances database class with CREATE TABLE statements for MS SQL.
* The phpMyFAQ instances database class with CREATE TABLE statements for MS SQL Server.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
Expand Down Expand Up @@ -30,7 +30,7 @@ class Sqlsrv extends Database implements Driver
/**
* @var array
*/
private $createTableStatements = [
private array $createTableStatements = [
'faqadminlog' => 'CREATE TABLE %sfaqadminlog (
id INTEGER NOT NULL,
time INTEGER NOT NULL,
Expand All @@ -52,7 +52,7 @@ class Sqlsrv extends Database implements Driver
mime_type VARCHAR(255) NULL,
PRIMARY KEY (id))',

'faqattachment file' => 'CREATE TABLE %sfaqattachment_file (
'faqattachment_file' => 'CREATE TABLE %sfaqattachment_file (
virtual_hash CHAR(32) NOT NULL,
contents VARCHAR(MAX) NOT NULL,
PRIMARY KEY (virtual_hash))',
Expand Down

0 comments on commit 933a8ce

Please sign in to comment.