Run php-cs-fixer on src

This commit is contained in:
2025-12-17 04:25:47 +09:00
parent 0a77f46fe1
commit f782d20e56
19 changed files with 237 additions and 264 deletions
+18 -21
View File
@@ -4,9 +4,6 @@ declare(strict_types=1);
namespace pvv\side;
use DateTimeImmutable;
use PDO;
class Door {
private $pdo;
@@ -18,15 +15,15 @@ class Door {
* @return array{time: int, open: bool}[]
*/
public function getAll(): array {
$query = "SELECT time, open FROM door ORDER BY time DESC";
$query = 'SELECT time, open FROM door ORDER BY time DESC';
$statement = $this->pdo->prepare($query);
$statement->execute();
$doorEvents = [];
foreach ($statement->fetchAll() as $row) {
$doorEvents[] = [
"time" => (int) $row["time"],
"open" => (bool) $row["open"],
'time' => (int) $row['time'],
'open' => (bool) $row['open'],
];
}
@@ -36,18 +33,18 @@ class Door {
/**
* @return array{time: int, open: bool}[]
*/
public function getEntriesAfter(DateTimeImmutable $startTime): array {
$query =
"SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC";
public function getEntriesAfter(\DateTimeImmutable $startTime): array {
$query
= 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC';
$statement = $this->pdo->prepare($query);
$statement->bindParam(":startTime", $startTime, \PDO::PARAM_STR);
$statement->bindParam(':startTime', $startTime, \PDO::PARAM_STR);
$statement->execute();
$doorEvents = [];
foreach ($statement->fetchAll() as $row) {
$doorEvents[] = [
"time" => (int) $row["time"],
"open" => (bool) $row["open"],
'time' => (int) $row['time'],
'open' => (bool) $row['open'],
];
}
@@ -58,30 +55,30 @@ class Door {
* @return array{time: int, open: bool}
*/
public function getCurrent(): array {
$query = "SELECT time, open FROM door ORDER BY time DESC LIMIT 1";
$query = 'SELECT time, open FROM door ORDER BY time DESC LIMIT 1';
$statement = $this->pdo->prepare($query);
$statement->execute();
$row = $statement->fetch();
return [
"time" => (int) $row["time"],
"open" => (bool) $row["open"],
'time' => (int) $row['time'],
'open' => (bool) $row['open'],
];
}
private function removeOld(): void {
$firstValidTime = time() - 60 * 60 * 24 * 7; // One week before now
$query = "DELETE FROM door WHERE time < :firstValid";
$query = 'DELETE FROM door WHERE time < :firstValid';
$statement = $this->pdo->prepare($query);
$statement->bindParam(":firstValid", $firstValidTime, \PDO::PARAM_STR);
$statement->bindParam(':firstValid', $firstValidTime, \PDO::PARAM_STR);
$statement->execute();
}
public function createEvent(DateTimeImmutable $time, bool $open): void {
$query = "INSERT INTO door(time, open) VALUES (:time, :open)";
public function createEvent(\DateTimeImmutable $time, bool $open): void {
$query = 'INSERT INTO door(time, open) VALUES (:time, :open)';
$statement = $this->pdo->prepare($query);
$statement->bindParam(":time", $time, \PDO::PARAM_STR);
$statement->bindParam(":open", $open, \PDO::PARAM_STR);
$statement->bindParam(':time', $time, \PDO::PARAM_STR);
$statement->bindParam(':open', $open, \PDO::PARAM_STR);
$statement->execute();
$this->removeOld();