MockAdapter::getNbResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Apie\MockPlugin\Pagers;
4
5
use Apie\Core\SearchFilters\SearchFilterHelper;
6
use Apie\Core\SearchFilters\SearchFilterRequest;
7
use Apie\MockPlugin\DataLayers\MockApiResourceDataLayer;
8
use Apie\ObjectAccessNormalizer\ObjectAccess\ObjectAccessInterface;
9
use Pagerfanta\Adapter\AdapterInterface;
10
11
class MockAdapter implements AdapterInterface
12
{
13
    /**
14
     * @var MockApiResourceDataLayer
15
     */
16
    private $dataLayer;
17
18
    /**
19
     * @var (int|string)[]
20
     */
21
    private $idList;
22
23
    /**
24
     * @var array
25
     */
26
    private $searches;
27
28
    /**
29
     * @var string
30
     */
31
    private $resourceClass;
32
33
    /**
34
     * @var array
35
     */
36
    private $context;
37
38
    /**
39
     * @var ObjectAccessInterface
40
     */
41
    private $propertyAccessor;
42
43
    public function __construct(
44
        MockApiResourceDataLayer $dataLayer,
45
        array $idList,
46
        array $searches,
47
        string $resourceClass,
48
        array $context,
49
        ObjectAccessInterface $propertyAccessor
50
    ) {
51
        $this->dataLayer = $dataLayer;
52
        $this->idList = $idList;
53
        $this->searches = $searches;
54
        $this->resourceClass = $resourceClass;
55
        $this->context = $context;
56
        $this->propertyAccessor = $propertyAccessor;
57
    }
58
59
    public function getNbResults()
60
    {
61
        return count($this->idList);
62
    }
63
64
    public function getSlice($offset, $length)
65
    {
66
        $searchFilterRequest = new SearchFilterRequest(
67
            $offset,
68
            $length,
69
            $this->searches
70
        );
71
72
        return array_map(
73
            function ($id) {
74
                return $this->dataLayer->retrieve($this->resourceClass, $id, $this->context);
75
            },
76
            SearchFilterHelper::applySearchFilter($this->idList, $searchFilterRequest, $this->propertyAccessor)
77
        );
78
    }
79
}
80