GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CodendiSOAP::setMaxRetry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Portion of this file is inspired from the  GForge Command-line Interface
4
 * contained in GForge.
5
 * Copyright 2005 GForge, LLC
6
 * http://gforge.org/
7
 *
8
 *
9
 */
10
11
/**
12
 * CodendiSOAP - Wrapper function for SOAP class.
13
 *
14
 * This class will pass on each command common variables to the server, like the
15
 * session ID and the project name
16
 */
17
class CodendiSOAP extends SoapClient {
18
	var $sess_hash;
19
	var $wsdl_string;
20
	var $proxy_host;
21
	var $proxy_port;
22
	var $connected;
23
	var $session_string;
24
	var $session_file;		// Configuration file for this session
25
	var $session_group_id;	// Default group
26
	var $session_user;		// Logged user name
27
    var $session_user_id;	// Logged user ID
28
    protected $fileChunkSize;
29
    protected $maxRetry;  // Max number of soap call retry in case of failure
30
    protected $callDelay; // Time "spacer" between 2 failing soap calls
31
	/**
32
	 * constructor
33
	 */
34
	function __construct() {
35
		$this->wsdl_string = "";
36
		$this->proxy_host = "";
37
		$this->proxy_port = 0;
38
		$this->connected = false;
39
		$this->session_string = "";
40
		$this->session_group_id = 0;		// By default don't use a group
41
		$this->session_user = "";
42
        $this->session_user_id = 0;
43
		$this->fileChunkSize = 6000000; // ~6 Mo;
44
		$this->maxRetry      = 0;
45
		$this->callDelay     = 5;
46
47
		// Try to find a dir where to put the session file
48
		$session_dir = 0;
49
		if (array_key_exists("HOME", $_ENV)) {
50
			$session_dir = $_ENV["HOME"]."/";
51
		} else if (array_key_exists("HOMEPATH", $_ENV) && array_key_exists("HOMEDRIVE", $_ENV)) {		// For Windows
52
			$session_dir = $_ENV["HOMEDRIVE"]."\\".$_ENV["HOMEPATH"]."\\";
53
54
		}
55
				
56
		$this->session_file = $session_dir.".codendirc";
57
		if (file_exists($this->session_file)) {
58
 			$this->readSession();
59
		}
60
	}
61
	
62
	/**
63
	 * call - Calls a SOAP method
64
	 *
65
	 * @param string	Command name
66
	 * @param array	Parameter array
67
	 * @param bool		Specify if we should pass the server common parameters like the session ID
68
	 */
69
	function call($command,$params=array(),$use_extra_params=true) {
70
		global $LOG;
71
		
72
		// checks if a session is established
73
		if ($command != "login" && strlen($this->session_string) == 0) {
74
			exit_error("You must start a session first using the \"login\" function");
75
		}
76
		
77
		if (!$this->connected) {		// try to connect to the server
78
			$this->connect();
79
		}
80
		
81
		// Add session parameters
82
		if ($use_extra_params) {
83
			if (!array_key_exists("sessionKey", $params)) {
84
                //$params["sessionKey"] = $this->session_string;
85
                $params = array('sessionKey' => $this->session_string) + $params;   // params need to be in the right order (sessionKey first)
86
            }
87
		}
88
89
		$nbAttempt       = 0;
90
		$soapCallSuccess = false;
91
		do {
92
			$nbAttempt++;
93
			try {
94
				$LOG->add("CodendiSOAP::Executing command ".$command." ...");
95
				return call_user_func_array(array($this, $command), $params);
96
			}
97
			catch (SoapFault $e) {
98
				if (strtolower($e->faultcode) == 'http' &&
0 ignored issues
show
Bug introduced by
The property faultcode does not seem to exist in SoapFault.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
					strtolower($e->faultstring) == 'error fetching http headers' &&
100
					$nbAttempt < $this->getMaxRetry()) {
101
					$GLOBALS['LOG']->add('CodendiSOAP::An error occured while executing '.$command.', try again [Nb attempt: '.$nbAttempt.'/'.$GLOBALS['soap']->getMaxRetry().']. Wait for '.($nbAttempt * $this->getCallDelay()).' seconds (mitigate network congestion) ...');
102
					sleep($nbAttempt * $this->getCallDelay());
103
				} else {
104
					throw $e;
105
				}
106
			}
107
		} while ($nbAttempt < $this->getMaxRetry());
108
	}
109
110
	/**
111
	 * connect - Establish the connection to the server. This is done in the constructor
112
	 * of the soap_client class
113
	 */
114
	function connect() {
115
		global $LOG;
116
		
117
        try {
118
        	$log_proxy = '';
119
        	if ($this->proxy_host && $this->proxy_port) {
120
        		$log_proxy = ', using proxy '.$this->proxy_host.':'.$this->proxy_port;
121
        	}
122
            $LOG->add("CodendiSOAP::Connecting to the server ".$this->getWSDLString().$log_proxy."...");
123
            $options = array('trace' => true);
124
            if ($this->proxy_host && $this->proxy_port) {
125
            	$options['proxy_host'] = $this->proxy_host;
126
            	$options['proxy_port'] = (int)$this->proxy_port;
127
            }
128
            parent::__construct($this->getWSDLString(), $options);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (__construct() instead of connect()). Are you sure this is correct? If so, you might want to change this to $this->__construct().

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...
129
        } catch (SoapFault $fault) {
130
            exit_error($fault, $this->faultcode);
131
		}
132
		$LOG->add("CodendiSOAP::Connected!");
133
		$this->connected = true;
134
		
135
	}
136
	
137
	/** 
138
	 * setSessionString - Set the session ID for future calls
139
	 *
140
	 * @param string Session string ID
141
	 */
142
	function setSessionString($string) {
143
		$this->session_string = $string;
144
	}
145
	
146
	function setSessionGroupID($group_id) {
147
		$this->session_group_id = $group_id;
148
	}
149
	
150
	function getSessionGroupID() {
151
		return $this->session_group_id;
152
	}
153
	
154
	function setSessionUser($user) {
155
		$this->session_user = $user;
156
	}
157
	
158
	function getSessionUser() {
159
		return $this->session_user;
160
	}
161
	
162
    function setSessionUserID($user_id) {
163
		$this->session_user_id = $user_id;
164
	}
165
	
166
	function getSessionUserID() {
167
		return $this->session_user_id;
168
	}
169
    
170
	function setWSDLString($wsdl) {
171
		$this->wsdl_string = $wsdl;
172
	}
173
    function getWSDLString() {
174
		if (!$this->wsdl_string) {
175
			if (defined("WSDL_URL")) {
176
				$this->wsdl_string = WSDL_URL;
177
			} else {
178
				exit_error("SOAP API: URL of the WSDL is not defined. Please set your TULEAP_WSDL environment variable.");
179
			}
180
		}
181
        return $this->wsdl_string;
182
    }
183
184
	function setProxy($proxy) {
185
		$arr_proxy = explode(":", $proxy);
186
		$this->proxy_host = $arr_proxy[0];
187
		$this->proxy_port = $arr_proxy[1];
188
	}
189
	function getProxyHost() {
190
		return $this->proxy_host;
191
	}
192
	function getProxyPort() {
193
		return $this->proxy_port;
194
	}
195
	
196
	function getFileChunkSize() {
197
		return $this->fileChunkSize;
198
	}
199
	function setFileChunkSize($size) {
200
		$this->fileChunkSize = $size;
201
	}
202
203
	function getMaxRetry() {
204
		return $this->maxRetry;
205
	}
206
	function setMaxRetry($maxRetry) {
207
		$this->maxRetry = $maxRetry;
208
	}
209
210
	function getCallDelay() {
211
		return $this->callDelay;
212
	}
213
	function setCallDelay($callDelay) {
214
		$this->callDelay = $callDelay;
215
	}
216
217
	function saveSession() {
218
		// If file doesn't exist, create first and set the right permissions
219
		if (!file_exists($this->session_file)) {
220
			touch($this->session_file);
221
			chmod($this->session_file, 0600);
222
		}
223
224
		$content = '';
225
		$content .= "wsdl_string=\"".$this->getWSDLString()."\"".PHP_EOL;
226
		$content .= "session_string=\"".$this->session_string."\"".PHP_EOL;
227
		$content .= "session_group_id=\"".$this->session_group_id."\"".PHP_EOL;
228
		$content .= "session_user=\"".$this->session_user."\"".PHP_EOL;
229
		$content .= "session_user_id=\"".$this->session_user_id."\"".PHP_EOL;
230
		$content .= "proxy_host=\"".$this->proxy_host."\"".PHP_EOL;
231
		$content .= "proxy_port=\"".$this->proxy_port."\"".PHP_EOL;
232
		$content .= "file_chunk_size=\"".$this->fileChunkSize."\"".PHP_EOL;
233
234
		if (!file_put_contents($this->session_file, $content)) {
235
			exit_error("Could not open session file ".$this->session_file." for writing");
236
		}
237
		chmod($this->session_file, 0600);
238
	}
239
240
	function readSession() {
241
		// Read session info (if exists)
242
		if (file_exists($this->session_file)) {
243
			$session = parse_ini_file($this->session_file, false);
244
			if (array_key_exists("session_string", $session)) {
245
				$this->session_string = $session["session_string"];
246
				$this->session_group_id = $session["session_group_id"];
247
				$this->session_user = $session["session_user"];
248
                $this->session_user_id = $session["session_user_id"];
249
				$this->wsdl_string = $session["wsdl_string"];
250
				$this->proxy_host = $session["proxy_host"];
251
				$this->proxy_port = $session["proxy_port"];
252
				if (isset($session["file_chunk_size"])) {
253
				    $this->fileChunkSize = $session["file_chunk_size"];
254
				}
255
			}
256
		}
257
	}
258
	
259
	function endSession() {
260
		if (file_exists($this->session_file) && !@unlink($this->session_file)) {
261
			exit_error("Could not delete existing session file ".$this->session_file);
262
		}
263
		
264
		$this->session_group_id = 0;
265
		$this->session_string = "";
266
		$this->session_user = "";
267
        $this->session_user_id = 0;
268
	}
269
}
270
?>