AccessTokenGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 100
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromJson() 0 36 1
A createFromSalesforceResponse() 0 35 1
A getKeyIfSet() 0 7 2
1
<?php namespace DarkGold\Salesforce;
2
3
use Carbon\Carbon;
4
5
class AccessTokenGenerator {
6
7
    /**
8
     * Create an access token from stored json data
9
     *
10
     * @param string $text
11
     * @return AccessToken
12
     */
13
    public function createFromJson($text)
14
    {
15
        $savedToken = json_decode($text, true);
16
17
        $id = $savedToken['id'];
18
19
        $dateIssued = Carbon::parse($savedToken['dateIssued']);
20
21
        $dateExpires = Carbon::parse($savedToken['dateExpires']);
22
23
        $scope = $savedToken['scope'];
24
25
        $tokenType = $savedToken['tokenType'];
26
27
        $refreshToken = $savedToken['refreshToken'];
28
29
        $signature = $savedToken['signature'];
30
31
        $accessToken = $savedToken['accessToken'];
32
33
        $apiUrl = $savedToken['apiUrl'];
34
35
        $token = new AccessToken(
36
            $id,
37
            $dateIssued,
38
            $dateExpires,
39
            $scope,
40
            $tokenType,
41
            $refreshToken,
42
            $signature,
43
            $accessToken,
44
            $apiUrl
45
        );
46
47
        return $token;
48
    }
49
50
    /**
51
     * Create an access token object from the salesforce response data
52
     *
53
     * @param array $salesforceToken
54
     * @return AccessToken
55
     */
56
    public function createFromSalesforceResponse(array $salesforceToken)
57
    {
58
59
        $dateIssued = Carbon::createFromTimestamp((int)($salesforceToken['issued_at'] / 1000));
60
61
        $dateExpires = $dateIssued->copy()->addHour()->subMinutes(5);
62
63
        $id = $this->getKeyIfSet($salesforceToken, 'id');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $id is correct as $this->getKeyIfSet($salesforceToken, 'id') (which targets DarkGold\Salesforce\Acce...enerator::getKeyIfSet()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64
65
        $scope = explode(' ', $this->getKeyIfSet($salesforceToken, 'scope'));
66
67
        $refreshToken = $this->getKeyIfSet($salesforceToken, 'refresh_token');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $refreshToken is correct as $this->getKeyIfSet($sale...Token, 'refresh_token') (which targets DarkGold\Salesforce\Acce...enerator::getKeyIfSet()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
69
        $signature = $this->getKeyIfSet($salesforceToken, 'signature');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $signature is correct as $this->getKeyIfSet($salesforceToken, 'signature') (which targets DarkGold\Salesforce\Acce...enerator::getKeyIfSet()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
71
        $tokenType = $this->getKeyIfSet($salesforceToken, 'token_type');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tokenType is correct as $this->getKeyIfSet($sale...rceToken, 'token_type') (which targets DarkGold\Salesforce\Acce...enerator::getKeyIfSet()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
72
73
        $accessToken = $salesforceToken['access_token'];
74
75
        $apiUrl = $salesforceToken['instance_url'];
76
77
        $token = new AccessToken(
78
            $id,
79
            $dateIssued,
80
            $dateExpires,
81
            $scope,
82
            $tokenType,
83
            $refreshToken,
84
            $signature,
85
            $accessToken,
86
            $apiUrl
87
        );
88
89
        return $token;
90
    }
91
92
    /**
93
     * @param array $array
94
     * @param string $key
95
     * @return null
96
     */
97
    private function getKeyIfSet($array, $key)
98
    {
99
        if (isset($array[$key])) {
100
            return $array[$key];
101
        }
102
        return null;
103
    }
104
}