Passed
Push — refactor/split-apis ( 704388 )
by Darío
03:14
created

CatalogProductsApi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getProduct() 0 6 1
A getProducts() 0 6 1
A createProduct() 0 6 1
A updateProduct() 0 6 1
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Api;
4
5
use PaymentGateway\PayPalSdk\Contracts\PayPalResponse;
6
use PaymentGateway\PayPalSdk\PayPalApi;
7
use PaymentGateway\PayPalSdk\Products\Requests\StoreProductRequest;
8
use PaymentGateway\PayPalSdk\Products\Requests\UpdateProductRequest;
9
use PaymentGateway\PayPalSdk\Responses\GetResponse;
10
use PaymentGateway\PayPalSdk\Responses\PatchResponse;
11
use PaymentGateway\PayPalSdk\Responses\PostResponse;
12
13
class CatalogProductsApi extends PayPalApi
14
{
15 1
    public function getProduct(string $id): PayPalResponse
16
    {
17 1
        $this->client->prepareRequest('GET', $this->baseUri . '/v1/catalogs/products/' . $id);
18 1
        $this->setAuthentication();
19
20 1
        return new GetResponse($this->client->execute());
21
    }
22
23 1
    public function getProducts(): PayPalResponse
24
    {
25 1
        $this->client->prepareRequest('GET', $this->baseUri . '/v1/catalogs/products');
26 1
        $this->setAuthentication();
27
28 1
        return new GetResponse($this->client->execute());
29
    }
30
31 2
    public function createProduct(StoreProductRequest $product): PayPalResponse
32
    {
33 2
        $this->client->prepareRequest('POST', $this->baseUri . '/v1/catalogs/products');
34 2
        $this->setAuthentication()->setJson($product->toArray());
35
36 2
        return new PostResponse($this->client->execute());
37
    }
38
39 2
    public function updateProduct(UpdateProductRequest $productRequest): PayPalResponse
40
    {
41 2
        $this->client->prepareRequest('PATCH', $this->baseUri . '/v1/catalogs/products/' . $productRequest->getId());
42 2
        $this->setAuthentication()->setJson($productRequest->toArray());
43
44 2
        return new PatchResponse($this->client->execute());
45
    }
46
}
47