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

InvoicesTemplates   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 112
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A showInvoiceTemplateDetails() 0 8 1
A deleteInvoiceTemplate() 0 8 1
A updateInvoiceTemplate() 0 10 1
A listInvoiceTemplates() 0 8 1
A createInvoiceTemplate() 0 10 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait InvoicesTemplates
6
{
7
    /**
8
     * Create a new invoice template.
9
     *
10
     * @param array $data
11
     *
12
     * @throws \Throwable
13
     *
14
     * @return array|\Psr\Http\Message\StreamInterface|string
15
     *
16
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_create
17
     */
18
    public function createInvoiceTemplate(array $data)
19
    {
20
        $this->apiEndPoint = "v2/invoicing/templates";
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...
21
        $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...
22
23
        $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...
24
25
        $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...
26
27
        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

27
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
28
    }
29
30
    /**
31
     * Get list of invoice templates.
32
     *
33
     * @param int $page
34
     * @param int $size
35
     * @param string $fields
36
     *
37
     * @throws \Throwable
38
     *
39
     * @return array|\Psr\Http\Message\StreamInterface|string
40
     *
41
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_list
42
     */
43
    public function listInvoiceTemplates($page=1, $size=20, $fields='all')
44
    {
45
        $this->apiEndPoint = "v2/invoicing/templates?page={$page}&page_size={$size}&fields={$fields}";
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...
46
        $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...
47
48
        $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...
49
50
        return $this->doPayPalRequest();
51
    }
52
53
    /**
54
     * Delete an invoice template.
55
     *
56
     * @param string $template_id
57
     *
58
     * @throws \Throwable
59
     *
60
     * @return array|\Psr\Http\Message\StreamInterface|string
61
     *
62
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_delete
63
     */
64
    public function deleteInvoiceTemplate($template_id)
65
    {
66
        $this->apiEndPoint = "v2/invoicing/templates/{$template_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->verb = 'delete';
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...
70
71
        return $this->doPayPalRequest();
72
    }
73
74
    /**
75
     * Update an existing invoice template.
76
     *
77
     * @param string $template_id
78
     * @param array $data
79
     *
80
     * @throws \Throwable
81
     *
82
     * @return array|\Psr\Http\Message\StreamInterface|string
83
     *
84
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_update
85
     */
86
    public function updateInvoiceTemplate($template_id, array $data)
87
    {
88
        $this->apiEndPoint = "v2/invoicing/templates/{$template_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...
89
        $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...
90
91
        $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...
92
93
        $this->verb = 'put';
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...
94
95
        return $this->doPayPalRequest();
96
    }
97
98
    /**
99
     * Show details for an existing invoice.
100
     *
101
     * @param string $template_id
102
     *
103
     * @throws \Throwable
104
     *
105
     * @return array|\Psr\Http\Message\StreamInterface|string
106
     *
107
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_get
108
     */
109
    public function showInvoiceTemplateDetails($template_id)
110
    {
111
        $this->apiEndPoint = "v2/invoicing/templates/{$template_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...
112
        $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...
113
114
        $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...
115
116
        return $this->doPayPalRequest();
117
    }
118
}
119