removed constructor body

This commit is contained in:
tracer 2022-01-20 10:37:34 +01:00
parent 8aaf607ad4
commit 0cbaaec179
1 changed files with 10 additions and 13 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controller;
use Exception;
use PDO;
use PDOException;
@ -10,12 +11,9 @@ use PDOException;
*/
class ApiUsers
{
private PDO $dbConnection;
public function __construct(private PDO $dbConnection)
{}
public function __construct(PDO $dbConnection)
{
$this->dbConnection = $dbConnection;
}
/**
* @return array|false
@ -53,7 +51,7 @@ class ApiUsers
$statement->bindParam(':id', $id);
$statement->execute();
return $statement->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
} catch (PDOException $e) {
exit($e->getMessage());
}
}
@ -71,7 +69,7 @@ class ApiUsers
$statement->bindParam(':prefix', $prefix);
$statement->execute();
return $statement->fetch(PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
} catch (PDOException $e) {
exit($e->getMessage());
}
}
@ -86,13 +84,12 @@ class ApiUsers
try {
$key = bin2hex(random_bytes(24));
$result['key'] = $key;
} catch (\Exception $e) {
} catch (Exception $e) {
echo $e->getMessage() . PHP_EOL;
exit(1);
}
$token = password_hash($tokenPrefix . '.' . $key, PASSWORD_ARGON2ID);
//print()
$statement = "
INSERT INTO user (api_token_prefix, api_token)
VALUES (:token_prefix, :token)";
@ -104,7 +101,7 @@ class ApiUsers
$statement->execute();
$result['row'] = $this->dbConnection->lastInsertId();
return $result;
} catch (\PDOException $e) {
} catch (PDOException $e) {
exit($e->getMessage());
}
}
@ -113,9 +110,9 @@ class ApiUsers
/**
* @param $id
*
* @return void
* @return int
*/
public function delete($id)
public function delete($id): int
{
$statement = "
DELETE FROM user
@ -126,7 +123,7 @@ class ApiUsers
$statement->bindParam('id', $id);
$statement->execute();
return $statement->rowCount();
} catch (\PDOException $e) {
} catch (PDOException $e) {
exit($e->getMessage());
}
}