added missing named parameters, added strict_types

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-26 19:35:57 +01:00
parent ec156db4aa
commit 30180e6d71

View File

@ -1,7 +1,9 @@
<?php
<?php declare(strict_types=1);
namespace App\Controller;
error_reporting(error_level: E_ALL);
use PDO;
use PDOException;
@ -20,7 +22,7 @@ class DatabaseConnection
public function __construct(private array $config)
{
extract($this->config);
extract(array: $this->config);
try {
$this->dbConnection = new PDO(
@ -29,13 +31,13 @@ class DatabaseConnection
password: $dbPassword
);
$sql = "SHOW TABLES";
$statement = $this->dbConnection->prepare($sql);
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
if (empty($result)) {
// ALTER TABLE `domains` ADD `panel_id` INT NULL AFTER `id`;
echo 'Error: Cannot find tables.' . PHP_EOL;
if (confirm('Should I try to create them?')) {
if (confirm(message: 'Should I try to create them?')) {
$sql = "
CREATE TABLE `apikeys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
@ -44,7 +46,7 @@ class DatabaseConnection
`api_token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$statement = $this->dbConnection->prepare($sql);
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
@ -56,7 +58,7 @@ class DatabaseConnection
`aaaa` varbinary(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$statement = $this->dbConnection->prepare($sql);
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
@ -68,7 +70,7 @@ class DatabaseConnection
`apikey` varbinary(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$statement = $this->dbConnection->prepare($sql);
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
@ -80,7 +82,7 @@ class DatabaseConnection
`apikey` varbinary(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$statement = $this->dbConnection->prepare($sql);
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
echo 'Tables have been created.' . PHP_EOL;