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

webeweb / pexels-library / 4820297686

pending completion
4820297686

push

github

webeweb
Improve metrics workflow

397 of 409 relevant lines covered (97.07%)

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

12
namespace WBW\Library\Pexels\Provider;
13

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

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

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

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

43
        return $response;
7✔
44
    }
45

46
    /**
47
     * Requests a next page.
48
     *
49
     * @param PaginateResponseInterface $response The response.
50
     * @return PhotosResponse|VideosResponse Returns the response.
51
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
52
     * @throws GuzzleException Throws a Guzzle exception if an error occurs.
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
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
60
    }
61

62
    /**
63
     * Request a previous page.
64
     *
65
     * @param PaginateResponseInterface $response The response.
66
     * @return PhotosResponse|VideosResponse Returns the response.
67
     * @throws InvalidArgumentException Throws an invalid argument exception if a parameter is missing.
68
     * @throws GuzzleException Throws a Guzzle exception if an error occurs.
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
        return $this->populateResponse($response->deserializeResponse($rawResponse));
×
76
    }
77

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

89
        $queryData   = $request->serializeRequest();
98✔
90
        $rawResponse = $this->callApiWithRequest($request, $queryData);
98✔
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