Reporting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A listTransactions() 0 12 2
A listBalances() 0 10 3
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
use Carbon\Carbon;
6
7
trait Reporting
8
{
9
    /**
10
     * List all transactions.
11
     *
12
     * @param array  $filters
13
     * @param string $fields
14
     *
15
     * @throws \Throwable
16
     *
17
     * @return array|\Psr\Http\Message\StreamInterface|string
18
     *
19
     * @see https://developer.paypal.com/docs/api/transaction-search/v1/#transactions_get
20
     */
21
    public function listTransactions(array $filters, string $fields = 'all')
22
    {
23
        $filters_list = collect($filters)->isEmpty() ? '' :
0 ignored issues
show
Bug introduced by
$filters of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $filters_list = collect(/** @scrutinizer ignore-type */ $filters)->isEmpty() ? '' :
Loading history...
24
            collect($filters)->map(function ($value, $key) {
25
                return "{$key}={$value}&";
26
            })->implode('');
27
28
        $this->apiEndPoint = "v1/reporting/transactions?{$filters_list}fields={$fields}&page={$this->current_page}&page_size={$this->page_size}";
29
30
        $this->verb = 'get';
31
32
        return $this->doPayPalRequest();
33
    }
34
35
    /**
36
     * List available balance.
37
     *
38
     * @param string $date
39
     * @param string $balance_currency
40
     *
41
     * @throws \Throwable
42
     *
43
     * @return array|\Psr\Http\Message\StreamInterface|string
44
     *
45
     * @see https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get
46
     */
47
    public function listBalances(string $date = '', string $balance_currency = '')
48
    {
49
        $date = empty($date) ? Carbon::now()->toIso8601ZuluString() : Carbon::parse($date)->toIso8601ZuluString();
50
        $currency = empty($balance_currency) ? $this->getCurrency() : $balance_currency;
0 ignored issues
show
Bug introduced by
It seems like getCurrency() 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

50
        $currency = empty($balance_currency) ? $this->/** @scrutinizer ignore-call */ getCurrency() : $balance_currency;
Loading history...
51
52
        $this->apiEndPoint = "v1/reporting/balances?currency_code={$currency}&as_of_time={$date}";
53
54
        $this->verb = 'get';
55
56
        return $this->doPayPalRequest();
57
    }
58
}
59