GenericCurl   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B exec() 0 34 4
1
<?php
2
namespace JarvisPHP\TelegramBot;
3
4
/**
5
 * A Generic Curl form POST request to JarvisPHP
6
 * @author Stefano Bianchini
7
 * @website http://www.stefanobianchini.net
8
 */
9
class GenericCurl {
10
11
	static function exec($url, $fields) {
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...
12
13
14
		$fields_string = "";
15
		//url-ify the data for the POST
16
		if(count($fields)>0) {
17
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
18
			rtrim($fields_string, '&');
19
		} 
20
		
21
		//echo $fields_string;
22
		//open connection
23
		$ch = curl_init();
24
25
		//set the url, number of POST vars, POST data
26
		curl_setopt($ch,CURLOPT_URL, $url);
27
		curl_setopt($ch,CURLOPT_POST, count($fields));
28
		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
29
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
		curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
31
		curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); 
32
33
		//execute post
34
		$result = @curl_exec($ch);
35
36
		$http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
37
38
		//close connection
39
		curl_close($ch);
40
41
42
43
		return ($http_response_code==200) ? json_decode($result) : false;
44
	}
45
}