Passed
Push — master ( a56982...6b40da )
by Raza
01:26
created

Products::product_archive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Srmklive\Chargify\Traits\ChargifyAPI;
4
5
trait Products
6
{
7
    /**
8
     * Create a new product.
9
     *
10
     * @param string $product_family_id
11
     * @param array  $data
12
     *
13
     * @return array
14
     */
15
    public function product_create(string $product_family_id, array $data): array
16
    {
17
        $this->apiEndPoint = "/product_families/{$product_family_id}/products.json";
18
19
        $this->verb = 'post';
20
21
        $this->options['json'] = [
0 ignored issues
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...
22
            'product' => $data,
23
        ];
24
25
        return $this->doChargifyRequest();
0 ignored issues
show
Bug introduced by
It seems like doChargifyRequest() 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

25
        return $this->/** @scrutinizer ignore-call */ doChargifyRequest();
Loading history...
26
    }
27
28
    /**
29
     * Get product details.
30
     *
31
     * @param string $product_id
32
     *
33
     * @return array
34
     */
35
    public function product_details(string $product_id): array
36
    {
37
        $this->apiEndPoint = "/products/{$product_id}.json";
38
39
        $this->verb = 'get';
40
41
        return $this->doChargifyRequest();
42
    }
43
44
    /**
45
     * Get product details via API Handle.
46
     *
47
     * @param string $handle
48
     *
49
     * @return array
50
     */
51
    public function product_details_by_handle(string $handle): array
52
    {
53
        $this->apiEndPoint = "/products/handle/{$handle}.json";
54
55
        $this->verb = 'get';
56
57
        return $this->doChargifyRequest();
58
    }
59
60
    /**
61
     * Update product details.
62
     *
63
     * @param string $product_id
64
     * @param array  $data
65
     *
66
     * @return array
67
     */
68
    public function product_update(string $product_id, array $data): array
69
    {
70
        $this->apiEndPoint = "/products/{$product_id}.json";
71
72
        $this->verb = 'put';
73
74
        $this->options['json'] = [
0 ignored issues
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...
75
            'product' => $data,
76
        ];
77
78
        return $this->doChargifyRequest();
79
    }
80
81
    /**
82
     * Archive a product.
83
     *
84
     * @param string $product_id
85
     *
86
     * @return array
87
     */
88
    public function product_archive(string $product_id): array
89
    {
90
        $this->apiEndPoint = "/products/{$product_id}.json";
91
92
        $this->verb = 'delete';
93
94
        return $this->doChargifyRequest();
95
    }
96
}
97