ReportingService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUserTransactionsFromRefreshToken() 0 24 2
1
<?php
2
3
namespace App\Service\Paypal;
4
5
use Exception;
6
7
/**
8
 * Class ReportingService
9
 * @package App\Service\Paypal
10
 */
11
class ReportingService extends IdentityService
12
{
13
    /**
14
     * @param string $refreshToken
15
     * @return bool|string|null
16
     */
17
    public function getUserTransactionsFromRefreshToken(string $refreshToken)
18
    {
19
        try {
20
            $tokenInfo = $this->refreshToken($refreshToken);
21
            $ch = curl_init();
22
            curl_setopt(
23
                $ch,
24
                CURLOPT_URL,
25
                "https://api.sandbox.paypal.com/v1/reporting/transactions?start_date=" .
26
                date('Y-m-d', strtotime('5 days ago')) . 'T00:00:00-0700' .
27
                "&end_date=" . date('Y-m-d', strtotime('now')) . 'T00:00:00-0700'
28
            );
29
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
30
            curl_setopt($ch, CURLOPT_HTTPHEADER, [
31
                'Content-Type: application/json',
32
                'Authorization: Bearer ' . $tokenInfo->getAccessToken(),
33
            ]);
34
            $userTransactions = curl_exec($ch);
35
            curl_close($ch);
36
        } catch (Exception $e) {
37
            $this->logger->error('Error on PayPal::getUserTransactionsFromRefreshToken = ' . $e->getMessage());
38
            return null;
39
        }
40
        return json_decode($userTransactions);
0 ignored issues
show
Bug introduced by
It seems like $userTransactions can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

40
        return json_decode(/** @scrutinizer ignore-type */ $userTransactions);
Loading history...
41
    }
42
}
43