• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

webeweb / pexels-library / 8308898083

16 Mar 2024 04:02PM UTC coverage: 97.216%. Remained the same
8308898083

push

github

webeweb
Update CHANGELOG

419 of 431 relevant lines covered (97.22%)

34.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/Provider/ApiProvider.php
1
<?php
2

3
declare(strict_types = 1);
4

5
/*
6
 * This file is part of the pexels-library package.
7
 *
8
 * (c) 2019 WEBEWEB
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace WBW\Library\Pexels\Provider;
15

16
use InvalidArgumentException;
17
use WBW\Library\Pexels\Api\PaginateResponseInterface;
18
use WBW\Library\Pexels\Request\AbstractRequest;
19
use WBW\Library\Pexels\Response\AbstractResponse;
20
use WBW\Library\Pexels\Response\PhotosResponse;
21
use WBW\Library\Pexels\Response\VideosResponse;
22
use WBW\Library\Provider\Exception\ApiException;
23

24
/**
25
 * API provider.
26
 *
27
 * @author webeweb <https://github.com/webeweb>
28
 * @package WBW\Library\Pexels\Provider
29
 */
30
class ApiProvider extends AbstractProvider {
31

32
    /**
33
     * Populate a response.
34
     *
35
     * @param AbstractResponse $response The response.
36
     * @return AbstractResponse Returns the response.
37
     */
38
    protected function populateResponse(AbstractResponse $response): AbstractResponse {
39

40
        $response->setLimit($this->getLimit());
8✔
41
        $response->setRemaining($this->getRemaining());
8✔
42
        $response->setReset($this->getReset());
8✔
43

44
        return $response;
8✔
45
    }
46

47
    /**
48
     * Request a next page.
49
     *
50
     * @param PaginateResponseInterface $response The response.
51
     * @return PhotosResponse|VideosResponse Returns the response.
52
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
53
     * @throws ApiException Throws an API exception if an error occurs.
54
     */
55
    public function requestNextPage(PaginateResponseInterface $response): AbstractResponse {
56

57
        $rawResponse = $this->callApiWithResponse($response);
×
58

59
        /** @var PhotosResponse|VideosResponse */
60
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
61
    }
62

63
    /**
64
     * Request a previous page.
65
     *
66
     * @param PaginateResponseInterface $response The response.
67
     * @return PhotosResponse|VideosResponse Returns the response.
68
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
69
     * @throws ApiException Throws an API exception if an error occurs.
70
     */
71
    public function requestPrevPage(PaginateResponseInterface $response): AbstractResponse {
72

73
        $rawResponse = $this->callApiWithResponse($response, false);
×
74

75
        /** @var PhotosResponse|VideosResponse */
76
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
77
    }
78

79
    /**
80
     * Send a request.
81
     *
82
     * @param AbstractRequest $request The request.
83
     * @return AbstractResponse Returns the response.
84
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
85
     * @throws ApiException Throws an API exception if an error occurs.
86
     */
87
    public function sendRequest(AbstractRequest $request): AbstractResponse {
88

89
        $queryData   = $request->serializeRequest();
112✔
90
        $rawResponse = $this->callApiWithRequest($request, $queryData);
112✔
91

92
        return $this->populateResponse($request->deserializeResponse($rawResponse));
×
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc