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:26 +01:00
parent 518c4ae90d
commit 707415e9c5

View File

@ -1,7 +1,8 @@
<?php
<?php declare(strict_types=1);
namespace App\Controller;
error_reporting(error_level: E_ALL);
use PDO;
use PDOException;
@ -20,12 +21,13 @@ class NameserverController
*/
public function findAll(): bool|array
{
$statement = "
$sql = "
SELECT id, name, a, aaaa, apikey
FROM " . DatabaseConnection::TABLE_NAMESERVERS;
try {
$statement = $this->databaseConnection->getConnection()->query($statement);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->execute();
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
@ -46,10 +48,10 @@ class NameserverController
WHERE name = :name";
try {
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
return $statement->fetch(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
}
@ -69,10 +71,10 @@ class NameserverController
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param:':id', var: $id);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
return $statement->fetch(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
}
@ -85,16 +87,16 @@ class NameserverController
* @param String $aaaa
* @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 = "
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey)
VALUES (:name, :a, :aaaa, :apikey)";
try {
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name);
$statement->bindParam(param: ':a', var: $a);
$statement->bindParam(param: ':aaaa', var: $aaaa);
@ -119,7 +121,7 @@ class NameserverController
*/
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)) {
$name = $current['name'] ?? '';
@ -143,7 +145,7 @@ class NameserverController
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare($sql);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id);
$statement->bindParam(param: 'name', var: $name);
$statement->bindParam(param: 'a', var: $a);
@ -165,12 +167,12 @@ class NameserverController
*/
public function delete($id): int
{
$statement = "
$sql = "
DELETE FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare($statement);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id);
$statement->execute();
return $statement->rowCount();
@ -186,11 +188,11 @@ class NameserverController
*/
public function getLongestEntry(String $field): int
{
$statement = "
$sql = "
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_NAMESERVERS;
try {
$statement = $this->databaseConnection->getConnection()->prepare($statement);
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
return $result['length'];