Completed
Push — master ( bd326e...3b0d07 )
by Paweł
12:10 queued 06:38
created

ContentApiSdk/Api/Pagerfanta/ResourceAdapter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file is part of the PHP SDK library for the Superdesk Content API.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace Superdesk\ContentApiSdk\Api\Pagerfanta;
16
17
use Pagerfanta\Adapter\AdapterInterface;
18
use Superdesk\ContentApiSdk\Api\Request\PaginationDecorator;
19
use Superdesk\ContentApiSdk\Api\Request\RequestInterface;
20
use Superdesk\ContentApiSdk\Client\ApiClientInterface;
21
22
/**
23
 * Base adapter for api resources.
24
 */
25
class ResourceAdapter implements AdapterInterface
26
{
27
    /**
28
     * HTTP Client.
29
     *
30
     * @var ApiClientInterface
31
     */
32
    protected $client;
33
34
    /**
35
     * API Request object.
36
     *
37
     * @var RequestInterface
38
     */
39
    protected $request;
40
41
    /**
42
     * Instantiate object.
43
     *
44
     * @param ApiClientInterface $client HTTP Client
45
     * @param RequestInterface $request API Request object
46
     */
47
    public function __construct(ApiClientInterface $client, RequestInterface $request)
48
    {
49
        $this->client = $client;
50
        $this->request = $request;
51
    }
52
53
    /**
54
     * Make HTTP call.
55
     *
56
     * @return \Superdesk\ContentApiSdk\Api\Response API Response object
57
     */
58
    private function doCall(RequestInterface $request)
59
    {
60
        return $this->client->makeApiCall($request);
61
    }
62
63
    /**
64
     * Returns the number of results.
65
     *
66
     * @return integer The number of results.
67
     */
68
    public function getNbResults()
69
    {
70
        $response = $this->doCall($this->request);
71
72
        return $response->getTotalResults();
73
    }
74
75
    /**
76
     * Returns an slice of the results.
77
     *
78
     * @param integer $offset The offset.
79
     * @param integer $length The length.
80
     *
81
     * @return array|stdClass|\Traversable The slice.
82
     *
83
     * @throws InvalidDataException
84
     */
85
    public function getSlice($offset, $length)
86
    {
87
        $paginationRequest = new PaginationDecorator($this->request);
88
        $paginationRequest->addPagination($offset, $length);
89
90
        $response = $this->doCall($paginationRequest);
91
92
        return $response->getResources();
0 ignored issues
show
Bug Compatibility introduced by
The expression $response->getResources(); of type array|stdClass adds the type stdClass to the return on line 92 which is incompatible with the return type declared by the interface Pagerfanta\Adapter\AdapterInterface::getSlice of type array|Traversable.
Loading history...
93
    }
94
}
95