Passed
Push — master ( a36f81...fe8dc6 )
by Nicolaas
02:07
created

SalesforceTest::createSubscriber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 5
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 8
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
    protected $emailStub = '@test.best.co.com.org.net';
17
18
    protected $email = '';
19
20
    public function run($request)
21
    {
22
        MySalesforceContactApi::set_debug(true);
23
        $this->setEmail();
24
        $this->findContact();
25
        $this->createContact();
26
        $this->findContact();
27
        $this->updateContact();
28
        $this->createSubscriber();
29
        $this->findContact();
30
        $this->updateSubscriber();
31
        $this->setEmail();
32
        $this->createBadContact();
33
    }
34
35
    protected function createContact()
36
    {
37
        MySalesforceContactApi::create_contact(
38
            [
39
                'FirstName' => 'John',
40
                'LastName' => 'Smith',
41
                'Phone' => '(510) 555-5555',
42
                'Email' => $this->email,
43
            ]
44
        );
45
    }
46
47
    protected function updateContact()
48
    {
49
        MySalesforceContactApi::update_contact(
50
            [
51
                'FirstName' => 'Joan',
52
                'LastName' => 'Smith',
53
                'Phone' => '(510) 555-5555',
54
                'Email' => $this->email,
55
            ]
56
        );
57
    }
58
59
    protected function findContact()
60
    {
61
        $contact = MySalesforceContactApi::is_email_registered($this->email);
0 ignored issues
show
Unused Code introduced by
The assignment to $contact is dead and can be removed.
Loading history...
62
    }
63
64
65
    protected function createSubscriber()
66
    {
67
        MySalesforceContactApi::create_contact(
68
            $this->email,
0 ignored issues
show
Bug introduced by
$this->email of type string is incompatible with the type array expected by parameter $fieldsArray of MySalesforceContactApi::create_contact(). ( Ignorable by Annotation )

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

68
            /** @scrutinizer ignore-type */ $this->email,
Loading history...
69
            '(510) 555-5555',
0 ignored issues
show
Bug introduced by
'(510) 555-5555' of type string is incompatible with the type array expected by parameter $extraFilterArray of MySalesforceContactApi::create_contact(). ( Ignorable by Annotation )

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

69
            /** @scrutinizer ignore-type */ '(510) 555-5555',
Loading history...
70
            'John',
0 ignored issues
show
Unused Code introduced by
The call to MySalesforceContactApi::create_contact() has too many arguments starting with 'John'. ( Ignorable by Annotation )

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

70
        MySalesforceContactApi::/** @scrutinizer ignore-call */ 
71
                                create_contact(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
71
            'Smith',
72
            [
73
            ]
74
        );
75
    }
76
77
    protected function updateSubscriber()
78
    {
79
        MySalesforceContactApi::update_email_subscriber(
80
            $this->email,
81
            [
82
                'Phone' => '(511) 555-1111',
83
            ]
84
        );
85
    }
86
87
88
    protected function createBadContact()
89
    {
90
        MySalesforceContactApi::create_contact(
91
            [
92
                'FirstName' => 'John',
93
                'LastName' => 'Smith',
94
                'NON_EXISTING_FIELD' => 'RUBBISH',
95
                'Email' => $this->email,
96
            ]
97
        );
98
    }
99
100
101
    protected function setEmail()
102
    {
103
        $this->email = 'test'.rand(0,99999).$this->emailStub;
104
105
    }
106
107
}
108