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

Salesforce   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 4 1
A connect() 0 19 3
A dump() 0 4 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