Passed
Push — v2.0 ( d916ef...282229 )
by Raza
02:10
created

CatalogProducts::showProductDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
6
trait CatalogProducts
7
{
8
    /**
9
     * Create a product.
10
     *
11
     * @param array $data
12
     * @param string $request_id
13
     *
14
     * @throws \Throwable
15
     *
16
     * @return array|\Psr\Http\Message\StreamInterface|string
17
     *
18
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
19
     */
20
    public function createProduct(array $data, $request_id)
21
    {
22
        $this->apiEndPoint = "v1/catalogs/products";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
25
        $this->options['headers']['PayPal-Request-Id'] = $request_id;
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->options['json'] = $data;
27
28
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
30
        return $this->doPayPalRequest();
1 ignored issue
show
Bug introduced by
It seems like doPayPalRequest() 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

30
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
31
    }
32
33
    /**
34
     * List products.
35
     *
36
     * @throws \Throwable
37
     *
38
     * @return array|\Psr\Http\Message\StreamInterface|string
39
     *
40
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list
41
     */
42
    public function listProducts()
43
    {
44
        $this->apiEndPoint = "v1/catalogs/products";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
46
47
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
49
        return $this->doPayPalRequest();
50
    }
51
52
    /**
53
     * Update a product.
54
     *
55
     * @param array $data
56
     * @param string $product_id
57
     *
58
     * @throws \Throwable
59
     *
60
     * @return array|\Psr\Http\Message\StreamInterface|string
61
     *
62
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch
63
     */
64
    public function updateProduct(array $data, $product_id)
65
    {
66
        $this->apiEndPoint = "v1/catalogs/products/{$product_id}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
67
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
68
69
        $this->options['json'] = $data;
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
70
71
        $this->verb = 'patch';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72
73
        return $this->doPayPalRequest();
74
    }
75
76
    /**
77
     * Get product details.
78
     *
79
     * @param string $product_id
80
     *
81
     * @throws \Throwable
82
     *
83
     * @return array|\Psr\Http\Message\StreamInterface|string
84
     *
85
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get
86
     */
87
    public function showProductDetails($product_id)
88
    {
89
        $this->apiEndPoint = "v1/catalogs/products/{$product_id}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
90
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
91
92
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
93
94
        return $this->doPayPalRequest();
95
    }
96
}
97