fix: address code review findings for bookmark feature (H1–L5)

Fix broken tests (H1), align interface signatures with implementations (H3),
remove dead code (H4), add missing input guard (M1), replace raw $_SESSION
access with SessionStoreInterface (M2), sync update script schema (M4),
use shared getAppBase utility (L2), document fragment stripping (L3),
and apply app- CSS class prefix convention (L5).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 22:58:07 +01:00
parent 9688848401
commit d9805c45d3
10 changed files with 195 additions and 91 deletions

View File

@@ -3,50 +3,31 @@
namespace MintyPHP\Repository\User;
use MintyPHP\DB;
use MintyPHP\Repository\Support\RepoQuery;
use MintyPHP\Repository\Support\RepositoryArrayHelper;
class BookmarkGroupRepository implements BookmarkGroupRepositoryInterface
{
private function unwrapList(mixed $rows): array
{
if (!is_array($rows)) {
return [];
}
$list = [];
foreach ($rows as $row) {
$data = $row['user_bookmark_groups'] ?? $row;
if (is_array($data)) {
$list[] = $data;
}
}
return $list;
return RepositoryArrayHelper::unwrapList($rows, 'user_bookmark_groups');
}
public function listByUser(int $userId): array
public function listByUser(int $userId, array $options = []): array
{
if ($userId <= 0) {
return [];
}
[$limit, $offset] = RepoQuery::sanitizeLimitOffset($options, 100, 1, 100);
$rows = DB::select(
'select id, user_id, name, icon, sort_order, created, modified from user_bookmark_groups where user_id = ? order by sort_order, id',
(string) $userId
'select id, user_id, name, icon, sort_order, created, modified from user_bookmark_groups where user_id = ? order by sort_order, id limit ? offset ?',
(string) $userId,
(string) $limit,
(string) $offset
);
return $this->unwrapList($rows);
}
public function nextGroupSortOrder(int $userId): int
{
if ($userId <= 0) {
return 1;
}
$max = DB::selectValue(
'select COALESCE(max(sort_order), 0) from user_bookmark_groups where user_id = ?',
(string) $userId
);
return max(1, ((int) $max) + 1);
}
public function countByUser(int $userId): int
{
if ($userId <= 0) {

View File

@@ -4,10 +4,11 @@ namespace MintyPHP\Repository\User;
interface BookmarkGroupRepositoryInterface
{
/** @return list<array<string, mixed>> */
public function listByUser(int $userId): array;
public function nextGroupSortOrder(int $userId): int;
/**
* @param array{limit?: int, offset?: int} $options
* @return list<array<string, mixed>>
*/
public function listByUser(int $userId, array $options = []): array;
public function countByUser(int $userId): int;

View File

@@ -4,8 +4,11 @@ namespace MintyPHP\Repository\User;
interface BookmarkRepositoryInterface
{
/** @return list<array<string, mixed>> */
public function listByUser(int $userId): array;
/**
* @param array{limit?: int, offset?: int} $options
* @return list<array<string, mixed>>
*/
public function listByUser(int $userId, array $options = []): array;
public function nextBookmarkSortOrder(int $userId, ?int $groupId): int;
@@ -26,5 +29,8 @@ interface BookmarkRepositoryInterface
/** @param list<array{id: int, sort_order: int}> $idOrderPairs */
public function updateSortOrders(int $userId, array $idOrderPairs): bool;
public function clearGroupId(int $groupId, int $userId): bool;
/** @return list<array<string, mixed>> */
public function listByGroup(int $userId, int $groupId): array;
public function unsetGroupId(int $bookmarkId, int $userId, int $sortOrder): bool;
}