Acme   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 2
A find() 0 3 1
A __get() 0 5 1
A get() 0 3 1
A __construct() 0 3 1
A create() 0 3 1
1
<?php
2
3
require __DIR__ . '/../vendor/autoload.php';
4
5
use Suitcase\Builder\SDK;
6
7
class Acme
8
{
9
    protected $client;
10
11
    protected $resource = '';
12
13
    private function __construct(string $authToken)
14
    {
15
        $this->client = SDK::make('https://api.acme.com')->withAuthHeaders($authToken);
16
    }
17
18
    public static function create(string $authToken): self
19
    {
20
        return new self($authToken);
21
    }
22
23
    public function load(...$resources): self
24
    {
25
        foreach ($resources as $resource) {
26
            $this->client->add($resource);
27
        }
28
29
        return $this;
30
    }
31
32
    public function __get(string $resource): self
33
    {
34
        $this->resource = $resource;
35
36
        return $this;
37
    }
38
39
    public function get(): array
40
    {
41
        return json_decode($this->client->use($this->resource)->get()->getBody()->getContents());
42
    }
43
44
    public function find($identifier)
45
    {
46
        return json_decode($this->client->use($this->resource)->find($identifier)->getBody()->getContents());
47
    }
48
}
49
50
// Create your SDK
51
$acme = Acme::create('1234-api-token-1234')->load('users', 'posts'. 'categories', 'likes');
52
53
// Access the Users resource and get all records from your API
54
$acme->users->get();
0 ignored issues
show
Bug Best Practice introduced by
The property users does not exist on Acme. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
56
// Access the Users resource and find a specific resource using an identifier from your API
57
$acme->users->find(1);
58
59
60
61
62
63
64
65
66
67