ReviewsioApi   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
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 38
ccs 16
cts 16
cp 1
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A pendingRequest() 0 15 5
A productReviewBySku() 0 7 3
A simpleRequest() 0 3 1
1
<?php
2
3
namespace Reviewsio;
4
5
use Illuminate\Http\Client\PendingRequest;
6
use Illuminate\Support\Facades\Http;
7
use Reviewsio\Endpoints\ProductReviewBySku;
8
use Reviewsio\Endpoints\SimpleRequest;
9
10
class ReviewsioApi
11
{
12
    protected array $config;
13
14 3
    public function __construct(array $config = [])
15
    {
16 3
        $this->config = $config;
17
    }
18
19 3
    public function pendingRequest(array $additionalOptions = []): PendingRequest
20
    {
21 3
        $config = array_merge_recursive($this->config, $additionalOptions);
22
23 3
        $client = Http::baseUrl($config['base_url'] ?? 'https://api.reviews.io');
24
25 3
        if (isset($config['guzzle']) && is_array($config['guzzle'])) {
26 1
            $client->withOptions($config['guzzle']);
27
        }
28
29 3
        if (isset($config['headers']) && is_array($config['headers'])) {
30 1
            $client->withHeaders($config['headers']);
31
        }
32
33 3
        return $client;
34
    }
35
36 1
    public function simpleRequest(): SimpleRequest
37
    {
38 1
        return (new SimpleRequest($this));
39
    }
40
41 2
    public function productReviewBySku(array $query = []): ProductReviewBySku\Request
42
    {
43 2
        if (!isset($query['store']) && isset($this->config['store'])) {
44 2
            $query['store'] = $this->config['store'];
45
        }
46
47 2
        return (new ProductReviewBySku\Request($this))->withQuery($query);
48
    }
49
}
50