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

InvoicesSearch::searchInvoices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 5
dl 0
loc 16
rs 9.9666
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait InvoicesSearch
6
{
7
    /**
8
     * Search and return existing invoices.
9
     *
10
     * @param array $filters
11
     * @param int $page
12
     * @param int $size
13
     * @param bool $totals
14
     * @param array $fields
15
     *
16
     * @throws \Throwable
17
     *
18
     * @return array|\Psr\Http\Message\StreamInterface|string
19
     *
20
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list
21
     */
22
    public function searchInvoices($filters, $page=1, $size=20, $totals=true, array $fields=[])
23
    {
24
        $fields_list = collect($fields);
25
26
        $fields = "";
27
        if ($fields_list->count() > 0)
28
            $fields = "&fields={$fields_list->implode(",")}";
29
30
        $this->apiEndPoint = "v2/invoicing/search-invoices?page={$page}&page_size={$size}&total_required={$totals}{$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...
31
        $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...
32
33
        $this->options['json'] = $filters;
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...
34
35
        $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...
36
37
        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

37
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
38
    }
39
}
40