added missing named parameters, added strict_types

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-26 19:36:43 +01:00
parent 707415e9c5
commit 1c1305af89
1 changed files with 16 additions and 13 deletions

View File

@ -1,7 +1,9 @@
<?php <?php declare(strict_types=1);
namespace App\Controller; namespace App\Controller;
error_reporting(error_level: E_ALL);
use PDO; use PDO;
use PDOException; use PDOException;
@ -26,7 +28,8 @@ class PanelController
FROM " . DatabaseConnection::TABLE_PANELS; FROM " . DatabaseConnection::TABLE_PANELS;
try { try {
$statement = $this->databaseConnection->getConnection()->query($statement); $statement = $this->databaseConnection->getConnection()->prepare(query: $statement);
$statement->execute();
return $statement->fetchAll(mode: PDO::FETCH_ASSOC); return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
exit($e->getMessage()); exit($e->getMessage());
@ -47,10 +50,10 @@ class PanelController
WHERE name = :name"; WHERE name = :name";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name); $statement->bindParam(param: ':name', var: $name);
$statement->execute(); $statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC); return $statement->fetch(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
exit($e->getMessage()); exit($e->getMessage());
} }
@ -70,7 +73,7 @@ class PanelController
WHERE id = :id"; WHERE id = :id";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param:':id', var: $id); $statement->bindParam(param:':id', var: $id);
$statement->execute(); $statement->execute();
return $statement->fetch(mode: PDO::FETCH_ASSOC); return $statement->fetch(mode: PDO::FETCH_ASSOC);
@ -86,16 +89,16 @@ class PanelController
* @param String $aaaa * @param String $aaaa
* @param String $apikey * @param String $apikey
* *
* @return int * @return string|false
*/ */
public function insert(String $name, String $a, String $aaaa, String $apikey): int public function insert(String $name, String $a, String $aaaa, String $apikey): bool|string
{ {
$sql = " $sql = "
INSERT INTO " . DatabaseConnection::TABLE_PANELS . " (name, a, aaaa, apikey) INSERT INTO " . DatabaseConnection::TABLE_PANELS . " (name, a, aaaa, apikey)
VALUES (:name, :a, :aaaa, :apikey)"; VALUES (:name, :a, :aaaa, :apikey)";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name); $statement->bindParam(param: ':name', var: $name);
$statement->bindParam(param: ':a', var: $a); $statement->bindParam(param: ':a', var: $a);
$statement->bindParam(param: ':aaaa', var: $aaaa); $statement->bindParam(param: ':aaaa', var: $aaaa);
@ -120,7 +123,7 @@ class PanelController
*/ */
public function update(Int $id, String $name, String $a, String $aaaa, String $apikey): bool|int public function update(Int $id, String $name, String $a, String $aaaa, String $apikey): bool|int
{ {
$current = $this->findByID($id); $current = $this->findByID(id: $id);
if (empty($name)) { if (empty($name)) {
$name = $current['name']; $name = $current['name'];
@ -144,7 +147,7 @@ class PanelController
WHERE id = :id"; WHERE id = :id";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id); $statement->bindParam(param: 'id', var: $id);
$statement->bindParam(param: 'name', var: $name); $statement->bindParam(param: 'name', var: $name);
$statement->bindParam(param: 'a', var: $a); $statement->bindParam(param: 'a', var: $a);
@ -172,7 +175,7 @@ class PanelController
WHERE id = :id"; WHERE id = :id";
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($statement); $statement = $this->databaseConnection->getConnection()->prepare(query: $statement);
$statement->bindParam(param: 'id', var: $id); $statement->bindParam(param: 'id', var: $id);
$statement->execute(); $statement->execute();
return $statement->rowCount(); return $statement->rowCount();
@ -193,7 +196,7 @@ class PanelController
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_PANELS; SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_PANELS;
try { try {
$statement = $this->databaseConnection->getConnection()->prepare($statement); $statement = $this->databaseConnection->getConnection()->prepare(query: $statement);
$statement->execute(); $statement->execute();
$result = $statement->fetch(); $result = $statement->fetch();
return $result['length']; return $result['length'];