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

pixelpeter / laravel5-woocommerce-api-client / 14970602232

12 May 2025 11:05AM UTC coverage: 100.0%. Remained the same
14970602232

Pull #65

github

web-flow
Merge 6732dd7d9 into 13c31535f
Pull Request #65: Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0

51 of 51 relevant lines covered (100.0%)

19.76 hits per line

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

100.0
/src/WoocommerceClient.php
1
<?php
2

3
namespace Pixelpeter\Woocommerce;
4

5
use Automattic\WooCommerce\Client;
6

7
/**
8
 * @property mixed $config
9
 */
10
class WoocommerceClient
11
{
12
    /**
13
     * @var \Automattic\WooCommerce\Client
14
     */
15
    protected $client;
16

17
    /**
18
     * @var bool
19
     */
20
    protected $usingLowerCaseHeaders = false;
21

22
    public function __construct(Client $client)
108✔
23
    {
24
        $this->client = $client;
108✔
25
    }
108✔
26

27
    /**
28
     * POST method.
29
     *
30
     * @param  string  $endpoint  API endpoint.
31
     * @param  array  $data  Request data.
32
     * @return array
33
     */
34
    public function post($endpoint, $data)
6✔
35
    {
36
        return $this->client->post($endpoint, $data);
6✔
37
    }
38

39
    /**
40
     * PUT method.
41
     *
42
     * @param  string  $endpoint  API endpoint.
43
     * @param  array  $data  Request data.
44
     * @return array
45
     */
46
    public function put($endpoint, $data)
6✔
47
    {
48
        return $this->client->put($endpoint, $data);
6✔
49
    }
50

51
    /**
52
     * GET method.
53
     *
54
     * @param  string  $endpoint  API endpoint.
55
     * @param  array  $parameters  Request parameters.
56
     * @return array
57
     */
58
    public function get($endpoint, $parameters = [])
6✔
59
    {
60
        return $this->client->get($endpoint, $parameters);
6✔
61
    }
62

63
    /**
64
     * DELETE method.
65
     *
66
     * @param  string  $endpoint  API endpoint.
67
     * @param  array  $parameters  Request parameters.
68
     * @return array
69
     */
70
    public function delete($endpoint, $parameters = [])
6✔
71
    {
72
        return $this->client->delete($endpoint, $parameters);
6✔
73
    }
74

75
    /**
76
     * Get the http request header from the last request
77
     *
78
     * @return \Automattic\WooCommerce\HttpClient\Request
79
     */
80
    public function getRequest()
42✔
81
    {
82
        return $this->client->http->getRequest();
42✔
83
    }
84

85
    /**
86
     * Get the http response headers from the last request
87
     *
88
     * @return \Automattic\WooCommerce\HttpClient\Response
89
     */
90
    public function getResponse()
36✔
91
    {
92
        return $this->client->http->getResponse();
36✔
93
    }
94

95
    /**
96
     * Return the first page number of the result
97
     *
98
     * @return int
99
     */
100
    public function firstPage()
6✔
101
    {
102
        return 1;
6✔
103
    }
104

105
    /**
106
     * Return the last page number of the result
107
     *
108
     * @return int
109
     */
110
    public function lastPage()
12✔
111
    {
112
        return $this->totalPages();
12✔
113
    }
114

115
    /**
116
     * Return the current page number of the result
117
     *
118
     * @return int
119
     */
120
    public function currentPage()
36✔
121
    {
122
        return ! empty($this->getRequest()->getParameters()['page']) ? $this->getRequest()->getParameters()['page'] : 1;
36✔
123
    }
124

125
    /**
126
     * Return the total number of results
127
     *
128
     * @return int
129
     */
130
    public function totalResults()
6✔
131
    {
132
        return (int) $this->getResponse()->getHeaders()[$this->getHeaderWithCase('X-WP-Total')];
6✔
133
    }
134

135
    /**
136
     * Return the total number of pages for this result
137
     *
138
     * @return mixed
139
     */
140
    public function totalPages()
24✔
141
    {
142
        return (int) $this->getResponse()->getHeaders()[$this->getHeaderWithCase('X-WP-TotalPages')];
24✔
143
    }
144

145
    /**
146
     * Return the previous page number for the current page
147
     * Will be null if there's no previous page
148
     *
149
     * @return int|null
150
     */
151
    public function previousPage()
12✔
152
    {
153
        $previous_page = $this->currentPage() - 1;
12✔
154
        if ($previous_page < 1) {
12✔
155
            $previous_page = null;
6✔
156
        }
157

158
        return $previous_page;
12✔
159
    }
160

161
    /**
162
     * Return the next page number for the current page
163
     * Will be null if there's no next page
164
     *
165
     * @return int|null
166
     */
167
    public function nextPage()
12✔
168
    {
169
        $next_page = $this->currentPage() + 1;
12✔
170
        if ($next_page > $this->totalPages()) {
12✔
171
            $next_page = null;
6✔
172
        }
173

174
        return $next_page;
12✔
175
    }
176

177
    /**
178
     * Returns true if there's a next page
179
     *
180
     * @return bool
181
     */
182
    public function hasNextPage()
12✔
183
    {
184
        return (bool) $this->nextPage();
12✔
185
    }
186

187
    /**
188
     * Returns true if there's a previous page
189
     *
190
     * @return bool
191
     */
192
    public function hasPreviousPage()
12✔
193
    {
194
        return (bool) $this->previousPage();
12✔
195
    }
196

197
    /**
198
     * Returns true if there's no next page
199
     *
200
     * @return bool
201
     */
202
    public function hasNotNextPage()
12✔
203
    {
204
        return (bool) ! $this->nextPage();
12✔
205
    }
206

207
    /**
208
     * Returns true if there's no previous page
209
     *
210
     * @return bool
211
     */
212
    public function hasNotPreviousPage()
12✔
213
    {
214
        return (bool) ! $this->previousPage();
12✔
215
    }
216

217
    /**
218
     * Set if headers should be indexed using lower case
219
     */
220
    public function useLowerCaseHeaders()
6✔
221
    {
222
        $this->usingLowerCaseHeaders = true;
6✔
223
    }
6✔
224

225
    /**
226
     * Set if headers should be case sensitive
227
     */
228
    public function useCaseSensitiveHeaders()
6✔
229
    {
230
        $this->usingLowerCaseHeaders = false;
6✔
231
    }
6✔
232

233
    /**
234
     * Convert header to correct case
235
     *
236
     *
237
     * @return string
238
     */
239
    public function getHeaderWithCase($header)
36✔
240
    {
241
        return $this->usingLowerCaseHeaders ? strtolower($header) : $header;
36✔
242
    }
243
}
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