WithRestFullRead   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 42
ccs 15
cts 15
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A callPagination() 0 5 1
A list() 0 10 1
A get() 0 9 3
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
It seems like httpClient() 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 ignore-call  annotation

16
        $response = $this->/** @scrutinizer ignore-call */ httpClient()->get($link);
Loading history...
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
Bug introduced by
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 ignore-call  annotation

31
        $response = $this->httpClient()->get($this->/** @scrutinizer ignore-call */ baseUrl(), $query);
Loading history...
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