Completed
Push — master ( 9d8165...e9b726 )
by Cesar
28s queued 13s
created

VaultService::getDataClientToken()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 14
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 21
rs 9.7998
1
<?php
2
3
namespace App\Service\Paypal;
4
5
use Exception;
6
use PayPal\Api\OpenIdUserinfo;
7
8
/**
9
 * Class VaultService.php
10
 * @package App\Service\Paypal
11
 */
12
class VaultService extends IdentityService
13
{
14
    /**
15
     * @param string $clientId
16
     * @return string | null
17
     */
18
    public function getDataClientToken(string $clientId)
19
    {
20
        try {
21
            $accessToken = $this->getAccessToken();
22
            $response = $this->paypalApiCall(
23
                $accessToken,
0 ignored issues
show
Bug introduced by
It seems like $accessToken can also be of type null; however, parameter $accessToken of App\Service\Paypal\Abstr...ervice::paypalApiCall() 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

23
                /** @scrutinizer ignore-type */ $accessToken,
Loading history...
24
                json_encode(["customer_id" => $clientId]),
25
                "https://api-m.sandbox.paypal.com/v1/identity/generate-token",
26
                [],
27
                'POST'
28
            );
29
        } catch (Exception $e) {
30
            $this->logger->error('Error on PayPal::getDataClientToken = ' . $e->getMessage());
31
            return null;
32
        }
33
        $result = json_decode($response['result'], true);
34
35
        if (array_key_exists('client_token', $result)) {
36
            return $result['client_token'];
37
        }
38
        return null;
39
    }
40
}
41