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

pixelpeter / laravel5-woocommerce-api-client / 14205374897

01 Apr 2025 08:28PM UTC coverage: 100.0%. Remained the same
14205374897

Pull #63

github

web-flow
Merge b66d04f64 into d89e5c510
Pull Request #63: ADD: github actions

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 namespace Pixelpeter\Woocommerce;
2

3
use Automattic\WooCommerce\Client;
4

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

15
    /**
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
     *
28
     * @return array
29
     */
30
    public function post($endpoint, $data)
6✔
31
    {
32
        return $this->client->post($endpoint, $data);
6✔
33
    }
34

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

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

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

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

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

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

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

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

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

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

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

157
        return $previous_page;
12✔
158
    }
159

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

173
        return $next_page;
12✔
174
    }
175

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

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

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

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