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