Completed
Push — master ( 449a48...6f6236 )
by Ashleigh
01:27
created

SalesforceAuth::isAuthenticated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Surge\LaravelSalesforce;
4
5
class SalesforceAuth
6
{
7
    /**
8
     * @var string
9
     */
10
    public $id;
11
12
    /**
13
     * @var string
14
     */
15
    public $accessToken;
16
17
    /**
18
     * @var string
19
     */
20
    public $instanceUrl;
21
22
    /**
23
     * @var string
24
     */
25
    public $url;
26
27
    /**
28
     * @var bool
29
     */
30
    private $authenticated = false;
31
32
    public function isAuthenticated(): bool
33
    {
34
        return $this->authenticated;
35
    }
36
37
    public function __construct($client)
38
    {
39
        $this->client = $client;
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
41
        $this->login();
42
    }
43
44
    /**
45
     * Login.
46
     */
47
    private function login()
48
    {
49
        $body = [
50
            'grant_type'    => 'password',
51
            'client_id'     => config('sf.client_id'),
52
            'client_secret' => config('sf.client_secret'),
53
            'username'      => config('sf.username'),
54
            'password'      => config('sf.password'),
55
        ];
56
57
        $response = $this->client->post('https://login.salesforce.com/services/oauth2/token', [
58
            'form_params' => $body,
59
        ])->getBody()->getContents();
60
61
        $responseObject = \GuzzleHttp\json_decode($response);
62
63
        $this->id = $responseObject->id;
64
        $this->accessToken = $responseObject->access_token;
65
        $this->instanceUrl = $responseObject->instance_url;
66
        $this->url = $responseObject->instance_url.$this->version['url'];
0 ignored issues
show
Bug introduced by
The property version does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
67
68
        if ($this->accessToken !== null) {
69
            $this->authenticated = true;
70
        }
71
    }
72
}
73