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

pixelpeter / laravel5-woocommerce-api-client / 14205496924

01 Apr 2025 08:35PM UTC coverage: 100.0%. Remained the same
14205496924

Pull #47

github

web-flow
Merge eafc4bcc2 into b19fe811d
Pull Request #47: Update automattic/woocommerce requirement from 1.3.* to 3.0.*

43 of 43 relevant lines covered (100.0%)

20.51 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
    public function __construct(Client $client)
102✔
18
    {
19
        $this->client = $client;
102✔
20
    }
102✔
21

22
    /**
23
     * POST method.
24
     *
25
     * @param  string  $endpoint  API endpoint.
26
     * @param  array  $data  Request data.
27
     * @return array
28
     */
29
    public function post($endpoint, $data)
6✔
30
    {
31
        return $this->client->post($endpoint, $data);
6✔
32
    }
33

34
    /**
35
     * PUT method.
36
     *
37
     * @param  string  $endpoint  API endpoint.
38
     * @param  array  $data  Request data.
39
     * @return array
40
     */
41
    public function put($endpoint, $data)
6✔
42
    {
43
        return $this->client->put($endpoint, $data);
6✔
44
    }
45

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

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

70
    /**
71
     * Get the http request header from the last request
72
     *
73
     * @return \Automattic\WooCommerce\HttpClient\Request
74
     */
75
    public function getRequest()
42✔
76
    {
77
        return $this->client->http->getRequest();
42✔
78
    }
79

80
    /**
81
     * Get the http response headers from the last request
82
     *
83
     * @return \Automattic\WooCommerce\HttpClient\Response
84
     */
85
    public function getResponse()
36✔
86
    {
87
        return $this->client->http->getResponse();
36✔
88
    }
89

90
    /**
91
     * Return the first page number of the result
92
     *
93
     * @return int
94
     */
95
    public function firstPage()
6✔
96
    {
97
        return 1;
6✔
98
    }
99

100
    /**
101
     * Return the last page number of the result
102
     *
103
     * @return int
104
     */
105
    public function lastPage()
12✔
106
    {
107
        return $this->totalPages();
12✔
108
    }
109

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

120
    /**
121
     * Return the total number of results
122
     *
123
     * @return int
124
     */
125
    public function totalResults()
6✔
126
    {
127
        return (int) $this->getResponse()->getHeaders()['X-WP-Total'];
6✔
128
    }
129

130
    /**
131
     * Return the total number of pages for this result
132
     *
133
     * @return mixed
134
     */
135
    public function totalPages()
24✔
136
    {
137
        return (int) $this->getResponse()->getHeaders()['X-WP-TotalPages'];
24✔
138
    }
139

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

153
        return $previous_page;
12✔
154
    }
155

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

169
        return $next_page;
12✔
170
    }
171

172
    /**
173
     * Returns true if there's a next page
174
     *
175
     * @return bool
176
     */
177
    public function hasNextPage()
12✔
178
    {
179
        return (bool) $this->nextPage();
12✔
180
    }
181

182
    /**
183
     * Returns true if there's a previous page
184
     *
185
     * @return bool
186
     */
187
    public function hasPreviousPage()
12✔
188
    {
189
        return (bool) $this->previousPage();
12✔
190
    }
191

192
    /**
193
     * Returns true if there's no next page
194
     *
195
     * @return bool
196
     */
197
    public function hasNotNextPage()
12✔
198
    {
199
        return (bool) ! $this->nextPage();
12✔
200
    }
201

202
    /**
203
     * Returns true if there's no previous page
204
     *
205
     * @return bool
206
     */
207
    public function hasNotPreviousPage()
12✔
208
    {
209
        return (bool) ! $this->previousPage();
12✔
210
    }
211
}
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