1 | <?php |
||||
2 | |||||
3 | namespace LaravelWorkcast\Endpoints; |
||||
4 | |||||
5 | use Illuminate\Http\Client\Response; |
||||
6 | use LaravelWorkcast\WorkcastException; |
||||
7 | use LaravelWorkcast\WorkcastPagination; |
||||
8 | |||||
9 | trait WithRestFullRead |
||||
10 | { |
||||
11 | /** |
||||
12 | * @inheritDoc |
||||
13 | */ |
||||
14 | 1 | public function callPagination(string $link): WorkcastPagination |
|||
15 | { |
||||
16 | 1 | $response = $this->httpClient()->get($link); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
17 | |||||
18 | 1 | return new WorkcastPagination($response, $this->key()); |
|||
19 | } |
||||
20 | |||||
21 | /** |
||||
22 | * @inheritDoc |
||||
23 | */ |
||||
24 | 1 | public function list(array $query = []): WorkcastPagination |
|||
25 | { |
||||
26 | 1 | $query = array_merge([ |
|||
27 | 1 | 'limit' => 100, |
|||
28 | 1 | 'skip' => 0, |
|||
29 | 1 | ], $query); |
|||
30 | |||||
31 | 1 | $response = $this->httpClient()->get($this->baseUrl(), $query); |
|||
0 ignored issues
–
show
It seems like
baseUrl() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
32 | |||||
33 | 1 | return new WorkcastPagination($response, $this->key()); |
|||
34 | } |
||||
35 | |||||
36 | /** |
||||
37 | * @inheritDoc |
||||
38 | */ |
||||
39 | 2 | public function get($id): Response |
|||
40 | { |
||||
41 | 2 | $response = $this->httpClient()->get($this->baseUrl() . "/{$id}"); |
|||
42 | |||||
43 | 2 | if (!$response->ok() || $response->json('responseCode') != 200) { |
|||
44 | 1 | throw new WorkcastException('Request error', $response->status()); |
|||
45 | } |
||||
46 | |||||
47 | 1 | return $response; |
|||
48 | } |
||||
49 | |||||
50 | abstract public function key():string; |
||||
51 | } |
||||
52 |