Passed
Push — master ( c40630...f0da52 )
by Nicolaas
08:09 queued 05:18
created

SalesForceTest::showRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
4
use SForce\Client\Partner;
5
6
use SForce\SObject;
7
8
use SForce\Wsdl\create;
9
10
class SalesForceTest extends BuildTask
11
{
12
    protected $title = 'Test Sales Force API';
13
14
    protected $description = 'Test Sales Cloud';
15
16
    public function run($request)
17
    {
18
        $this->findContact();
19
    }
20
21
    protected function findContact()
22
    {
23
        print '<h2>Request</h2>';
24
        print "<pre>MySalesForcePartnerAPI::retrieve_contact('[email protected]')</pre>";
25
        $contact = MySalesForcePartnerAPI::retrieve_contact('[email protected]');
0 ignored issues
show
Bug introduced by
'[email protected]' of type string is incompatible with the type array expected by parameter $fieldsArray of MySalesForcePartnerAPI::retrieve_contact(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $contact = MySalesForcePartnerAPI::retrieve_contact(/** @scrutinizer ignore-type */ '[email protected]');
Loading history...
26
27
        print '<h2>Result</h2>';
28
        print '<pre>';
29
        print htmlentities(print_r($contact, true));
30
        print '</pre>';
31
    }
32
33
    protected function createContact()
34
    {
35
        $response = MySalesForcePartnerAPI::create_contact(
36
            [
37
                'FirstName' => 'John',
38
                'LastName' => 'Smith',
39
                'Phone' => '(510) 555-5555',
40
                'BirthDate' => '1957-01-25',
41
                'Email' => '[email protected]',
42
            ]
43
        );
44
45
        $this->showResults($response);
46
    }
47
48
    protected function updateContact()
49
    {
50
        $response = MySalesForcePartnerAPI::update_contact(
51
            [
52
                'FirstName' => 'Joan',
53
                'LastName' => 'Smith',
54
                'Phone' => '(510) 555-5555',
55
                'BirthDate' => '1957-01-25',
56
                'Email' => '[email protected]',
57
            ]
58
        );
59
60
        $this->showResults($response);
61
    }
62
63
    protected function showResults($response)
64
    {
65
        $this->showRequest();
66
        $this->showResponse($response);
67
    }
68
69
    protected function showRequest()
70
    {
71
        $connection = MySalesForcePartnerAPIConnectionOnly::singleton();
72
        $this->output('
73
            <h2>Request</h2>
74
            <pre>
75
        ');
76
        $this->output($connection->debug(), true);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $connection->debug() targeting MySalesForcePartnerAPI::debug() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
77
        $this->output('
78
            </pre>
79
        ');
80
    }
81
82
    protected function showResponse($response)
83
    {
84
        $this->output('
85
            <h2>Response</h2>
86
            <pre>
87
        ');
88
        $this->output($response);
89
        $this->output('
90
            </pre>
91
        ');
92
    }
93
94
    protected function output($html, $escape = false)
95
    {
96
        if (! is_string($html)) {
97
            $html = print_r($html, 1);
98
        }
99
        if ($this->isCli()) {
100
            echo "\n";
101
        } elseif ($escape) {
102
            $html = htmlentities($html);
103
        }
104
105
        echo $html;
106
    }
107
108
    protected function isCli()
109
    {
110
        return PHP_SAPI === 'cli';
111
    }
112
}
113