Completed
Pull Request — master (#15)
by
unknown
03:16
created

Salesforce   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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\LaravelSalesforce;
2
3
use Davispeixoto\ForceDotComToolkitForPhp\SforceEnterpriseClient as Client;
4
use Exception;
5
6
/**
7
 * Class Salesforce
8
 *
9
 * Provides an easy binding to Salesforce
10
 * on Laravel 4 applications through SOAP
11
 * Data Integration.
12
 *
13
 * @package Davispeixoto\LaravelSalesforce
14
 */
15
class Salesforce
16
{
17
    /**
18
     * @var Client $sfh The Salesforce Handler
19
     */
20
    public $sfh;
21
22
    /**
23
     * Salesforce constructor.
24
     *
25
     * @param Client $sfh
26
     * @throws SalesforceException
27
     */
28
    public function __construct(Client $sfh)
29
    {
30
        $this->sfh = $sfh;
31
    }
32
33
    /**
34
     * @param $method
35
     * @param $args
36
     * @return mixed
37
     */
38
    public function __call($method, $args)
39
    {
40
        return call_user_func_array(array($this->sfh, $method), $args);
41
    }
42
43
    /**
44
     * Authenticates into Salesforce according to
45
     * the provided credentials and WSDL file
46
     *
47
     * @param $configExternal
48
     * @throws SalesforceException
49
     */
50
    public function connect($configExternal)
51
    {
52
        $wsdl = $configExternal->get('salesforce.wsdl');
53
54
        if (empty($wsdl)) {
55
            $wsdl = __DIR__ . '/Wsdl/enterprise.wsdl.xml';
56
        }
57
58
        $user = $configExternal->get('salesforce.username');
59
        $pass = $configExternal->get('salesforce.password');
60
        $token = $configExternal->get('salesforce.token');
61
62
        try {
63
            $this->sfh->createConnection($wsdl);
64
            $this->sfh->login($user, $pass . $token);
65
        } catch (Exception $e) {
66
            throw new SalesforceException('Exception at Constructor' . $e->getMessage() . "\n\n" . $e->getTraceAsString());
67
        }
68
    }
69
70
    /*
71
     * Debugging functions
72
     */
73
74
    /**
75
     * @return mixed
76
     */
77
    public function dump()
78
    {
79
        return print_r($this, true);
80
    }
81
}
82