LoginResponseDto::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 7

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 2
b 0
f 0
nc 7
nop 1
dl 0
loc 16
rs 9.9
1
<?php
2
3
namespace SalesforceBulkApi\dto;
4
5
use BaseHelpers\hydrators\ConstructFromArrayOrJson;
6
use SalesforceBulkApi\exceptions\SFClientException;
7
8
class LoginResponseDto extends ConstructFromArrayOrJson
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $serverUrl;
14
15
    /**
16
     * @var string
17
     */
18
    protected $sessionId;
19
20
    /**
21
     * @var string
22
     */
23
    protected $userId;
24
25
    /**
26
     * @var string
27
     */
28
    protected $instance;
29
30
    /**
31
     * LoginResponseDto constructor.
32
     *
33
     * @param null $params
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $params is correct as it would always require null to be passed?
Loading history...
34
     *
35
     * @throws SFClientException
36
     */
37
    public function __construct($params = null)
38
    {
39
        if (!$params instanceof \DOMDocument) {
40
            parent::__construct($params);
41
            return;
42
        }
43
        try {
44
            $this->serverUrl = $params->getElementsByTagName('serverUrl')[0]->nodeValue;
45
            $this->sessionId = $params->getElementsByTagName('sessionId')[0]->nodeValue;
46
            $this->userId    = $params->getElementsByTagName('userId')[0]->nodeValue;
47
48
            //  extract the instance portion of the URL.
49
            preg_match('/https:\/\/(.*)\.salesforce\.com/', $this->serverUrl, $matches);
50
            $this->instance  = $matches[1];
51
        } catch (\Exception $e) {
52
            throw new SFClientException('SF Api waiting behavior changed. Parse response error: ' . $e->getMessage());
53
        }
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getSessionId()
60
    {
61
        return $this->sessionId;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getInstance()
68
    {
69
        return $this->instance;
70
    }
71
}
72