Completed
Push — master ( 28e149...cc2c18 )
by Davis
03:19
created

SforcePartnerClient::merge()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php namespace Davispeixoto\ForceDotComToolkitForPhp;
2
3
    /*
4
     * Copyright (c) 2007, salesforce.com, inc.
5
     * All rights reserved.
6
     *
7
     * Redistribution and use in source and binary forms, with or without modification, are permitted provided
8
     * that the following conditions are met:
9
     *
10
     *    Redistributions of source code must retain the above copyright notice, this list of conditions and the
11
     *    following disclaimer.
12
     *
13
     *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
14
     *    the following disclaimer in the documentation and/or other materials provided with the distribution.
15
     *
16
     *    Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
17
     *    promote products derived from this software without specific prior written permission.
18
     *
19
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20
     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21
     * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
     * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23
     * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
     * POSSIBILITY OF SUCH DAMAGE.
27
     */
28
use stdClass;
29
30
/**
31
 * SforcePartnerClient class.
32
 *
33
 * @package SalesforceSoapClient
34
 */
35
class SforcePartnerClient extends SforceBaseClient
36
{
37
    const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com';
38
39
    public function __construct()
40
    {
41
        $this->namespace = self::PARTNER_NAMESPACE;
42
    }
43
44
    protected function getSoapClient($wsdl, $options)
45
    {
46
        return new SforceSoapClient($wsdl, $options);
0 ignored issues
show
Unused Code introduced by
The call to SforceSoapClient::__construct() has too many arguments starting with $wsdl.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
47
    }
48
49
    /**
50
     * Adds one or more new individual objects to your organization's data.
51
     * @param array $sObjects Array of one or more sObjects (up to 200) to create.
52
     * @return SaveResult
53
     */
54 View Code Duplication
    public function create($sObjects)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $arg = new stdClass;
57
        foreach ($sObjects as $sObject) {
58
            if (isset ($sObject->fields)) {
59
                $sObject->any = $this->_convertToAny($sObject->fields);
60
            }
61
        }
62
        $arg->sObjects = $sObjects;
63
64
        return parent::_create($arg);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_create() instead of create()). Are you sure this is correct? If so, you might want to change this to $this->_create().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
65
    }
66
67
    /**
68
     * Merge records
69
     *
70
     * @param stdclass $mergeRequest
71
     * @param String $type
0 ignored issues
show
Bug introduced by
There is no parameter named $type. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
72
     * @return mixed
73
     */
74
    public function merge($mergeRequest)
75
    {
76
        if (isset($mergeRequest->masterRecord)) {
77
            if (isset($mergeRequest->masterRecord->fields)) {
78
                $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields);
79
            }
80
            $arg = new stdClass();
81
            $arg->request = $mergeRequest;
82
83
            return $this->_merge($arg);
84
        }
85
    }
86
87
    /**
88
     *
89
     * @param array $request
90
     */
91 View Code Duplication
    public function sendSingleEmail($request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        if (is_array($request)) {
94
            $messages = array();
95
            foreach ($request as $r) {
96
                $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace);
97
                array_push($messages, $email);
98
            }
99
            $arg->messages = $messages;
0 ignored issues
show
Bug introduced by
The variable $arg does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
100
101
            return parent::_sendEmail($arg);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_sendEmail() instead of sendSingleEmail()). Are you sure this is correct? If so, you might want to change this to $this->_sendEmail().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
102
        } else {
103
            $backtrace = debug_backtrace();
104
            error_log('Please pass in array to this function:  ' . $backtrace[0]['function']);
105
            return false;
106
        }
107
    }
108
109
    /**
110
     *
111
     * @param array $request
112
     */
113 View Code Duplication
    public function sendMassEmail($request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        $arg = new stdClass();
116
        if (is_array($request)) {
117
            $messages = array();
118
            foreach ($request as $r) {
119
                $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace);
120
                array_push($messages, $email);
121
            }
122
            $arg->messages = $messages;
123
124
            return parent::_sendEmail($arg);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_sendEmail() instead of sendMassEmail()). Are you sure this is correct? If so, you might want to change this to $this->_sendEmail().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
125
        } else {
126
            $backtrace = debug_backtrace();
127
            error_log('Please pass in array to this function:  ' . $backtrace[0]['function']);
128
            return false;
129
        }
130
    }
131
132
    /**
133
     * Updates one or more new individual objects to your organization's data.
134
     * @param array sObjects    Array of sObjects
135
     * @return UpdateResult
136
     */
137 View Code Duplication
    public function update($sObjects)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
    {
139
        $arg = new stdClass;
140
        foreach ($sObjects as $sObject) {
141
            if (isset($sObject->fields)) {
142
                $sObject->any = $this->_convertToAny($sObject->fields);
143
            }
144
        }
145
        $arg->sObjects = $sObjects;
146
147
        return parent::_update($arg);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_update() instead of update()). Are you sure this is correct? If so, you might want to change this to $this->_update().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
148
    }
149
150
    /**
151
     * Creates new objects and updates existing objects; uses a custom field to
152
     * determine the presence of existing objects. In most cases, we recommend
153
     * that you use upsert instead of create because upsert is idempotent.
154
     * Available in the API version 7.0 and later.
155
     *
156
     * @param string $ext_Id External Id
157
     * @param array $sObjects Array of sObjects
158
     * @return UpsertResult
159
     */
160
    public function upsert($ext_Id, $sObjects)
161
    {
162
        $arg = new stdClass;
163
        $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
164
        foreach ($sObjects as $sObject) {
165
            if (isset ($sObject->fields)) {
166
                $sObject->any = $this->_convertToAny($sObject->fields);
167
            }
168
        }
169
        $arg->sObjects = $sObjects;
170
171
        return parent::_upsert($arg);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_upsert() instead of upsert()). Are you sure this is correct? If so, you might want to change this to $this->_upsert().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
172
    }
173
174
    /**
175
     * @param string $fieldList
176
     * @param string $sObjectType
177
     * @param array $ids
178
     * @return string
179
     */
180
    public function retrieve($fieldList, $sObjectType, $ids)
181
    {
182
        return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids));
183
    }
184
185
    /**
186
     *
187
     * @param mixed $response
188
     * @return array
189
     */
190
    private function _retrieveResult($response)
191
    {
192
        $arr = array();
193
        if (is_array($response)) {
194
            foreach ($response as $r) {
195
                $sobject = new SObject($r);
196
                array_push($arr, $sobject);
197
            }
198
        } else {
199
            $sobject = new SObject($response);
200
            array_push($arr, $sobject);
201
        }
202
203
        return $arr;
204
    }
205
206
}
207