Sécurité et qualité : headers HTTP, permissions .env, lint PHPStan + PHP-CS-Fixer, réorganisation dossiers, scripts de déploiement
This commit is contained in:
+11
-9
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class PostManager
|
||||
{
|
||||
private PDO $db;
|
||||
@@ -11,13 +13,13 @@ class PostManager
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
$stmt = $this->db->query("SELECT * FROM posts ORDER BY created_at DESC");
|
||||
$stmt = $this->db->query('SELECT * FROM posts ORDER BY created_at DESC');
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public function get(int $id): ?array
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM posts WHERE id = :id");
|
||||
$stmt = $this->db->prepare('SELECT * FROM posts WHERE id = :id');
|
||||
$stmt->execute(['id' => $id]);
|
||||
$post = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $post ?: null;
|
||||
@@ -25,10 +27,10 @@ class PostManager
|
||||
|
||||
public function create(string $title, string $content, string $published_at): int
|
||||
{
|
||||
$stmt = $this->db->prepare("
|
||||
$stmt = $this->db->prepare('
|
||||
INSERT INTO posts (title, content, created_at, is_published)
|
||||
VALUES (:title, :content, :published_at, true)
|
||||
");
|
||||
');
|
||||
$stmt->execute([
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
@@ -36,11 +38,11 @@ class PostManager
|
||||
]);
|
||||
return (int)$this->db->lastInsertId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function update(int $id, string $title, string $content, string $published_at, bool $published): bool
|
||||
{
|
||||
$stmt = $this->db->prepare("
|
||||
$stmt = $this->db->prepare('
|
||||
UPDATE posts
|
||||
SET title = :title,
|
||||
content = :content,
|
||||
@@ -48,7 +50,7 @@ class PostManager
|
||||
is_published = :published,
|
||||
updated_at = NOW()
|
||||
WHERE id = :id
|
||||
");
|
||||
');
|
||||
return $stmt->execute([
|
||||
'id' => $id,
|
||||
'title' => $title,
|
||||
@@ -57,11 +59,11 @@ class PostManager
|
||||
'published' => $published,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
$stmt = $this->db->prepare("DELETE FROM posts WHERE id = :id");
|
||||
$stmt = $this->db->prepare('DELETE FROM posts WHERE id = :id');
|
||||
return $stmt->execute(['id' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user