Mark data classes and functions with types

This commit is contained in:
2025-12-17 03:41:40 +09:00
parent da1113341a
commit f8acc4b815
20 changed files with 496 additions and 343 deletions

View File

@@ -4,44 +4,53 @@ declare(strict_types=1);
namespace pvv\side;
use PDO;
class MOTD {
private $pdo;
public function __construct($pdo) {
public function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
public function setMOTD($title, $content): void {
public function setMOTD(string $title, string $content): void {
if (\is_array($content)) {
$content = implode('_', $content);
$content = implode("_", $content);
}
$query = 'INSERT INTO motd(title, content) VALUES (:title, :content);';
$query = "INSERT INTO motd(title, content) VALUES (:title, :content);";
$statement = $this->pdo->prepare($query);
$statement->bindParam(':title', $title, \PDO::PARAM_STR);
$statement->bindParam(':content', $content, \PDO::PARAM_STR);
$statement->bindParam(":title", $title, \PDO::PARAM_STR);
$statement->bindParam(":content", $content, \PDO::PARAM_STR);
$statement->execute();
}
public function getMOTD() {
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1';
/**
* @return array{title: string, content: string[]}
*/
public function getMOTD(): array {
$query =
"SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT 1";
$statement = $this->pdo->prepare($query);
$statement->execute();
$data = $statement->fetch();
return ['title' => $data[0], 'content' => explode("\n", $data[1])];
return ["title" => $data[0], "content" => explode("\n", $data[1])];
}
public function getMOTD_history($limit = 5) {
$query = 'SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit';
/**
* @return array{title: string, content: string[]}
*/
public function getMOTD_history(int $limit = 5): array {
$query =
"SELECT motd.title, motd.content FROM motd ORDER BY motd.id DESC LIMIT :limit";
$statement = $this->pdo->prepare($query);
$statement->bindParam(':limit', $limit, \PDO::PARAM_STR);
$statement->bindParam(":limit", $limit, \PDO::PARAM_STR);
$statement->execute();
$data = $statement->fetch();
return ['title' => $data[0], 'content' => explode("\n", $data[1])];
return ["title" => $data[0], "content" => explode("\n", $data[1])];
}
}