Test Failed
Push — 135-map-multiple-wordpress-obj... ( 3634c2...bb35fb )
by Jonathan
12:00
created

SforcePartnerClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) 2007, salesforce.com, inc.
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
7
 * that the following conditions are met:
8
 *
9
 *    Redistributions of source code must retain the above copyright notice, this list of conditions and the
10
 *    following disclaimer.
11
 *
12
 *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13
 *    the following disclaimer in the documentation and/or other materials provided with the distribution.
14
 *
15
 *    Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
16
 *    promote products derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
 * POSSIBILITY OF SUCH DAMAGE.
26
 */
27
require_once ('SforceBaseClient.php');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
28
//require_once ('SforceEmail.php');
29
30
31
/**
32
 * This file contains two classes.
33
 * @package SalesforceSoapClient
34
 */
35
/**
36
 * SforceSoapClient class.
37
 *
38
 * @package SalesforceSoapClient
39
 */
40
 // When parsing partner WSDL, when PHP SOAP sees NewValue and OldValue, since
41
 // the element has a xsi:type attribute with value 'string', it drops the
42
 // string content into the parsed output and loses the tag name. Removing the
43
 // xsi:type forces PHP SOAP to just leave the tags intact
44
 class SforceSoapClient extends SoapClient {
45
   function __doRequest($request, $location, $action, $version, $one_way=0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "SforceSoapClient::__doRequest" is invalid; only PHP magic methods should be prefixed with a double underscore
Loading history...
introduced by
Expected 1 space between argument "$one_way" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$one_way";
Loading history...
46
     $response = parent::__doRequest($request, $location, $action, $version, $one_way);
47
48
     // Quick check to only parse the XML here if we think we need to
49
     if (strpos($response, '<sf:OldValue') === false && strpos($response, '<sf:NewValue') === false) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
50
       return $response;
51
     }
52
53
     $dom = new DOMDocument();
54
     $dom->loadXML($response);
55
56
     $nodeList = $dom->getElementsByTagName('NewValue');
57
     foreach ($nodeList as $node) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
58
       $node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type');
59
     }
60
     $nodeList = $dom->getElementsByTagName('OldValue');
61
     foreach ($nodeList as $node) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
62
       $node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type');
63
     }
64
65
     return $dom->saveXML();      
66
   }
67
 }
68
69
/**
70
 * SforcePartnerClient class.
71
 *
72
 * @package SalesforceSoapClient
73
 */
74
class SforcePartnerClient extends SforceBaseClient {
75
  const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com';
76
	
77
  public function __construct() {
78
    $this->namespace = self::PARTNER_NAMESPACE;
79
  }
80
  
81
  protected function getSoapClient($wsdl, $options) {
0 ignored issues
show
Coding Style introduced by
The function name getSoapClient is in camel caps, but expected get_soap_client instead as per the coding standard.
Loading history...
82
    // Workaround an issue in parsing OldValue and NewValue in histories
83
		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...
84
  }
85
86
  /**
87
   * Adds one or more new individual objects to your organization's data.
88
   * @param array $sObjects Array of one or more sObjects (up to 200) to create.
89
   * @return SaveResult
90
   */
91 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...
92
    $arg = new stdClass;
93
    foreach ($sObjects as $sObject) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
94
      if (isset ($sObject->fields)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
95
        $sObject->any = $this->_convertToAny($sObject->fields);
96
      }
97
    }
98
    $arg->sObjects = $sObjects;
99
    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...
100
  }
101
102
  /**
103
   * Merge records
104
   *
105
   * @param stdclass $mergeRequest
106
   * @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...
107
   * @return mixed
108
   */
109
  public function merge($mergeRequest) {
110
    if (isset($mergeRequest->masterRecord)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
111
      if (isset($mergeRequest->masterRecord->fields)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
112
        $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields);
113
      }
114
      //return parent::merge($mergeRequest, $type);
115
      $arg->request = $mergeRequest;
116
      return $this->_merge($arg);
117
    }
118
  }
119
120
  /**
121
   * 
122
   * @param array $request
123
   */
124 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...
Coding Style introduced by
The function name sendSingleEmail is in camel caps, but expected send_single_email instead as per the coding standard.
Loading history...
125
    if (is_array($request)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
126
      $messages = array();
127
      foreach ($request as $r) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
128
        $email = new SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace);
129
        array_push($messages, $email);
130
      }
131
      $arg->messages = $messages;
132
      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...
133
    } else {
134
      $backtrace = debug_backtrace();
135
      die('Please pass in array to this function:  '.$backtrace[0]['function']);
136
    }
137
  }
138
139
  /**
140
   *
141
   * @param array $request
142
   */
143 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...
Coding Style introduced by
The function name sendMassEmail is in camel caps, but expected send_mass_email instead as per the coding standard.
Loading history...
144
    if (is_array($request)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
145
      $messages = array();
146
      foreach ($request as $r) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
147
        $email = new SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace);
148
        array_push($messages, $email);
149
      }
150
      $arg->messages = $messages;
151
      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...
152
    } else {
153
      $backtrace = debug_backtrace();
154
      die('Please pass in array to this function:  '.$backtrace[0]['function']);
155
    }
156
  }
157
158
  /**
159
   * Updates one or more new individual objects to your organization's data.
160
   * @param array sObjects    Array of sObjects
161
   * @return UpdateResult
162
   */
163 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...
164
    $arg = new stdClass;
165
    foreach ($sObjects as $sObject) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
166
      if (isset($sObject->fields)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
167
        $sObject->any = $this->_convertToAny($sObject->fields);
168
      }
169
    }
170
    $arg->sObjects = $sObjects;
171
    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...
172
  }
173
174
  /**
175
   * Creates new objects and updates existing objects; uses a custom field to
176
   * determine the presence of existing objects. In most cases, we recommend
177
   * that you use upsert instead of create because upsert is idempotent.
178
   * Available in the API version 7.0 and later.
179
   *
180
   * @param string $ext_Id        External Id
181
   * @param array  $sObjects  Array of sObjects
182
   * @return UpsertResult
183
   */
184
  public function upsert($ext_Id, $sObjects) {
185
    //		$this->_setSessionHeader();
186
    $arg = new stdClass;
187
    $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
188
    foreach ($sObjects as $sObject) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
189
      if (isset ($sObject->fields)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
190
        $sObject->any = $this->_convertToAny($sObject->fields);
191
      }
192
    }
193
    $arg->sObjects = $sObjects;
194
    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...
195
  }
196
  
197
  /**
198
   * @param string $fieldList
199
   * @param string $sObjectType
200
   * @param array $ids
201
   * @return string
202
   */
203
  public function retrieve($fieldList, $sObjectType, $ids) {
204
  	return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids));
205
  }  
206
207
  /**
208
   *
209
   * @param mixed $response
210
   * @return array
211
   */
212
  private function _retrieveResult($response) {
0 ignored issues
show
Coding Style introduced by
The function name _retrieveResult is in camel caps, but expected _retrieve_result instead as per the coding standard.
Loading history...
213
  	$arr = array();
214
  	if(is_array($response)) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
215
  		foreach($response as $r) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
216
  			$sobject = new SObject($r);
217
  			array_push($arr,$sobject);
218
  		};
219
  	}else {
220
  		$sobject = new SObject($response);
221
        array_push($arr, $sobject);
222
  	}
223
  	return $arr;
224
  }
225
  
226
}
227