Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
GetResourceListPaginationFolder
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getChild
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getChildren
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\ApieFileSystem\Virtual;
3
4use Apie\ApieFileSystem\Lists\VirtualFileMap;
5use Apie\Core\Context\ApieContext;
6use Apie\Core\Datalayers\Lists\EntityListInterface;
7use Apie\Core\Datalayers\Search\QuerySearch;
8use Apie\Serializer\Serializer;
9
10class GetResourceListPaginationFolder implements VirtualFolderInterface
11{
12    public const ITEMS_PER_PAGE = 100;
13
14    private ?VirtualFileMap $children = null;
15
16    public function __construct(
17        private readonly EntityListInterface $list,
18        private readonly int $page,
19        private readonly Serializer $serializer,
20        private readonly ApieContext $context,
21    ) {
22    }
23
24    public function getName(): string
25    {
26        return (string) $this->page;
27    }
28
29    public function getChild(string $name): VirtualFileInterface|VirtualFolderInterface|null
30    {
31        return $this->getChildren()[$name] ?? null;
32    }
33
34    public function getChildren(): VirtualFileMap
35    {
36        if ($this->children === null) {
37            $this->children = new VirtualFileMap();
38            $list = $this->list->toPaginatedResult(new QuerySearch($this->page, self::ITEMS_PER_PAGE));
39            foreach ($list as $item) {
40                $this->children[$item->getId()->toNative() . '.json'] = new GetSingleResourceFile(
41                    $item,
42                    $this->serializer,
43                    $this->context
44                );
45            }
46        }
47        return $this->children;
48    }
49}