Completed
Push — master ( 080cf5...aaebc2 )
by Davis
21s
created

Salesforce::connect()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 6
nop 1
1
<?php namespace Davispeixoto\Laravel5Salesforce;
2
3
use Davispeixoto\ForceDotComToolkitForPhp\SforceEnterpriseClient as Client;
4
use Exception;
5
6
/**
7
 * Class Salesforce
8
 * @package Davispeixoto\Laravel5Salesforce
9
 *
10
 * The Salesforce service accessor Constructor
11
 */
12
class Salesforce
13
{
14
    /**
15
     * @var Client
16
     */
17
    public $sfh;
18
19
    /**
20
     * Salesforce constructor.
21
     * @param Client $sfh
22
     */
23
    public function __construct(Client $sfh)
24
    {
25
        $this->sfh = $sfh;
26
    }
27
28
    /**
29
     * @param $method
30
     * @param $args
31
     * @return mixed
32
     */
33
    public function __call($method, $args)
34
    {
35
        return call_user_func_array([$this->sfh, $method], $args);
36
    }
37
38
    /**
39
     * Connect user into salesforce
40
     *
41
     * @param $configExternal
42
     * @throws SalesforceException
43
     */
44
    public function connect($configExternal)
45
    {
46
        $wsdl = $configExternal->get('salesforce.wsdl');
47
48
        if (empty($wsdl)) {
49
            $wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml';
50
        }
51
52
        $user = $configExternal->get('salesforce.username');
53
        $pass = $configExternal->get('salesforce.password');
54
        $token = $configExternal->get('salesforce.token');
55
56
        try {
57
            $this->sfh->createConnection($wsdl);
58
            $this->sfh->login($user, $pass . $token);
59
        } catch (Exception $e) {
60
            throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString());
61
        }
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function dump()
68
    {
69
        return print_r($this, true);
70
    }
71
}
72