From 261eb9540079b0d1924d17ed899e2a95a192e08a Mon Sep 17 00:00:00 2001 From: tbreuss Date: Wed, 28 Dec 2022 11:28:30 +0100 Subject: [PATCH] refactor: Remove unused methods Signed-off-by: tbreuss --- system/PageList.php | 100 +------------------------------------------- 1 file changed, 1 insertion(+), 99 deletions(-) diff --git a/system/PageList.php b/system/PageList.php index 208a821b..6debf1a6 100644 --- a/system/PageList.php +++ b/system/PageList.php @@ -39,39 +39,16 @@ public function addItem(Page $item): void $this->items[$route] = $item; } - public function getItems(): array - { - return $this->items; - } - public function getIterator(): ArrayIterator { return new ArrayIterator($this->items); } - public function getRandom(): Page - { - $routes = array_keys($this->items); - $index = mt_rand(0, $this->count() - 1); - $route = $routes[$index]; - return $this->items[$route]; - } - public function count(): int { return count($this->items); } - public function find(string $value, string $key): ?Page - { - foreach ($this->items as $item) { - if ($item->$key === $value) { - return $item; - } - } - return null; - } - public function query(): QueryBuilder { return (new QueryBuilder())->from($this); @@ -111,11 +88,6 @@ public function shuffle(): PageList return new self($items); } - public function flatten(): array - { - return $this->items; - } - /** * @param callable|string|null $mixed */ @@ -188,23 +160,6 @@ public function getCategories(?string $type = null): array return $categories; } - public function getRecent(int $limit, ?string $type = null): array - { - $items = []; - $i = 0; - foreach ($this->items as $page) { - if ($type && ($page->getType() !== $type)) { - continue; - } - if ($i >= $limit) { - break; - } - $items[] = $page; - $i++; - } - return $items; - } - public function getTags(?string $type = null): array { $type = $type === null ? '__all__' : $type; @@ -272,59 +227,6 @@ public function getMonths(?string $type = null): array return $months; } - public function filterItems(string $type, string $parentRoute, array $params): PageList - { - $items = []; - - foreach ($this->items as $item) { - if ($item->getType() !== $type) { - continue; - } - if ($item->getParentRoute() !== $parentRoute) { - continue; - } - if (empty($params)) { - $items[] = $item; - continue; - } - if (isset($params['category']) && $item->hasCategory($params['category'])) { - $items[] = $item; - continue; - } - if (isset($params['tag']) && $item->hasTag($params['tag'])) { - $items[] = $item; - continue; - } - if (isset($params['author']) && $item->hasAuthor($params['author'])) { - $items[] = $item; - continue; - } - if (isset($params['year'], $params['month'], $params['day'])) { - $date = sprintf('%s-%s-%s', $params['year'], $params['month'], $params['day']); - if ($item->getDate() === $date) { - $items[] = $item; - } - continue; - } - if (isset($params['year'], $params['month'])) { - $date = substr($item->getDate(), 0, 7); - $month = sprintf('%s-%s', $params['year'], $params['month']); - if ($date === $month) { - $items[] = $item; - } - continue; - } - if (isset($params['year'])) { - if (substr($item->getDate(), 0, 4) === $params['year']) { - $items[] = $item; - } - continue; - } - } - - return new self($items); - } - public function getPageTree(): PageTree { if ($this->pageTree === null) { @@ -361,6 +263,6 @@ public function getPageTrail(string $requestRoute): PageTrail public function getItem(string $route): ?Page { - return isset($this->items[$route]) ? $this->items[$route] : null; + return $this->items[$route] ?? null; } }