Skip to content

Commit

Permalink
refactor: Remove unused methods
Browse files Browse the repository at this point in the history
Signed-off-by: tbreuss <[email protected]>
  • Loading branch information
tbreuss committed Dec 28, 2022
1 parent d3b36f0 commit 261eb95
Showing 1 changed file with 1 addition and 99 deletions.
100 changes: 1 addition & 99 deletions system/PageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -111,11 +88,6 @@ public function shuffle(): PageList
return new self($items);
}

public function flatten(): array
{
return $this->items;
}

/**
* @param callable|string|null $mixed
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 261eb95

Please sign in to comment.