Mark data classes and functions with types
This commit is contained in:
@@ -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])];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user