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

SforceMetadataClient   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 144
Duplicated Lines 4.17 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 6
loc 144
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 43 2
A _setLoginHeader() 6 6 1
A setEndpoint() 0 4 1
A setSessionHeader() 0 12 1
A getObjtype() 0 8 2
A create() 0 6 1
A update() 0 7 1
A delete() 0 6 1
A checkStatus() 0 3 1
A getLastRequest() 0 3 1
A getLastRequestHeaders() 0 3 1
A getLastResponse() 0 3 1
A getLastResponseHeaders() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 ('SforceMetaObject.php');
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
28
29
class SforceMetadataClient {
30
  public $sforce;
31
  protected $sessionId;
32
  protected $location;
33
  protected $version = '27.0';
34
35
  protected $namespace = 'http://soap.sforce.com/2006/04/metadata';
36
37
  public function __construct($wsdl, $loginResult, $sforceConn) {
0 ignored issues
show
Unused Code introduced by
The parameter $sforceConn is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
39
    $soapClientArray = null;
0 ignored issues
show
Unused Code introduced by
$soapClientArray is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
    
41
	  $phpversion = substr(phpversion(), 0, strpos(phpversion(), '-'));
42
//		if (phpversion() > '5.1.2') {
43
	  if ($phpversion > '5.1.2') {
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...
44
      $soapClientArray = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
45
      'user_agent' => 'salesforce-toolkit-php/'.$this->version,
46
      'encoding' => 'utf-8',
47
      'trace' => 1,
48
      'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
49
      'sessionId' => $loginResult->sessionId
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
50
      );
51
    } else {
52
      $soapClientArray = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
53
	  'user_agent' => 'salesforce-toolkit-php/'.$this->version,
54
      'encoding' => 'utf-8',
55
      'trace' => 1,
56
      'sessionId' => $loginResult->sessionId
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
57
      );
58
    }
59
    $this->sforce = new SoapClient($wsdl,$soapClientArray);
60
    //$this->sforce->__setSoapHeaders($header_array);
61
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
62
63
    $sessionVar = array(
64
      'sessionId' => new SoapVar($loginResult->sessionId, XSD_STRING)
65
    );
66
67
    $headerBody = new SoapVar($sessionVar, SOAP_ENC_OBJECT);
68
69
    $session_header = new SoapHeader($this->namespace, 'SessionHeader', $headerBody, false);
70
71
    $header_array = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
72
    $session_header
73
    );
74
75
    $this->sforce->__setSoapHeaders($header_array);
76
77
    $this->sforce->__setLocation($loginResult->metadataServerUrl);
78
    return $this->sforce;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
79
  }
80
81
  /**
82
   * Specifies the session ID returned from the login server after a successful
83
   * login.
84
   */
85 View Code Duplication
  protected function _setLoginHeader($loginResult) {
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 _setLoginHeader is in camel caps, but expected _set_login_header instead as per the coding standard.
Loading history...
86
    $this->sessionId = $loginResult->sessionId;
87
    $this->setSessionHeader($this->sessionId);
88
    $serverURL = $loginResult->serverUrl;
89
    $this->setEndPoint($serverURL);
90
  }
91
92
  /**
93
   * Set the endpoint.
94
   *
95
   * @param string $location   Location
96
   */
97
  public function setEndpoint($location) {
0 ignored issues
show
Coding Style introduced by
The function name setEndpoint is in camel caps, but expected set_endpoint instead as per the coding standard.
Loading history...
98
    $this->location = $location;
99
    $this->sforce->__setLocation($location);
100
  }
101
102
  /**
103
   * Set the Session ID
104
   *
105
   * @param string $sessionId   Session ID
106
   */
107
  public function setSessionHeader($sessionId) {
0 ignored issues
show
Coding Style introduced by
The function name setSessionHeader is in camel caps, but expected set_session_header instead as per the coding standard.
Loading history...
108
    $this->sforce->__setSoapHeaders(NULL);
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
109
    $session_header = new SoapHeader($this->namespace, 'SessionHeader', array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
110
    'sessionId' => $sessionId
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 4.
Loading history...
introduced by
Each line in an array declaration must end in a comma
Loading history...
111
    ));
112
    $this->sessionId = $sessionId;
113
    $header_array = array (
0 ignored issues
show
introduced by
There must be no space between the Array keyword and the opening parenthesis
Loading history...
114
    $session_header
115
    );
116
    $this->_setClientId($header_array);
0 ignored issues
show
Bug introduced by
The method _setClientId() does not seem to exist on object<SforceMetadataClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
    $this->sforce->__setSoapHeaders($header_array);
118
  }
119
  
120
  private function getObjtype($obj) {
0 ignored issues
show
Coding Style introduced by
The function name getObjtype is in camel caps, but expected get_objtype instead as per the coding standard.
Loading history...
121
    $classArray = explode('\\', get_class($obj));
122
    $objtype = array_pop($classArray);
123
    if (strpos($objtype, 'Sforce', 0) === 0) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Found "=== 0". Use Yoda Condition checks, you must
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
124
      $objtype = substr($objtype, 6);
125
    }
126
    return $objtype;
127
  }
128
129
  public function create($obj) {
130
    $encodedObj = new stdClass();
131
    $encodedObj->metadata = new SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace);
132
     
133
    return $this->sforce->create($encodedObj);
134
  }
135
  
136
  public function update($obj) {    
137
    $encodedObj = new stdClass();
138
    $encodedObj->UpdateMetadata = $obj;
139
    $encodedObj->UpdateMetadata->metadata = new SoapVar($obj->metadata, SOAP_ENC_OBJECT, $this->getObjtype($obj->metadata), $this->namespace);
140
    
141
    return $this->sforce->update($encodedObj);
142
  }
143
  
144
  public function delete($obj) {
145
    $encodedObj = new stdClass();
146
    $encodedObj->metadata = new SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace);
147
     
148
    return $this->sforce->delete($encodedObj);
149
  }  
150
  
151
  public function checkStatus($ids) {
0 ignored issues
show
Coding Style introduced by
The function name checkStatus is in camel caps, but expected check_status instead as per the coding standard.
Loading history...
152
    return $this->sforce->checkStatus($ids);
153
  }  
154
155
  public function getLastRequest() {
0 ignored issues
show
Coding Style introduced by
The function name getLastRequest is in camel caps, but expected get_last_request instead as per the coding standard.
Loading history...
156
    return $this->sforce->__getLastRequest();
157
  }
158
159
  public function getLastRequestHeaders() {
0 ignored issues
show
Coding Style introduced by
The function name getLastRequestHeaders is in camel caps, but expected get_last_request_headers instead as per the coding standard.
Loading history...
160
    return $this->sforce->__getLastRequestHeaders();
161
  }
162
163
  public function getLastResponse() {
0 ignored issues
show
Coding Style introduced by
The function name getLastResponse is in camel caps, but expected get_last_response instead as per the coding standard.
Loading history...
164
    return $this->sforce->__getLastResponse();
165
  }
166
167
  public function getLastResponseHeaders() {
0 ignored issues
show
Coding Style introduced by
The function name getLastResponseHeaders is in camel caps, but expected get_last_response_headers instead as per the coding standard.
Loading history...
168
    return $this->sforce->__getLastResponseHeaders();
169
  }
170
171
172
}
173
174
175
?>
176