Completed
Push — master ( 29b356...bb0851 )
by Joe
02:55 queued 23s
created

Cloudlinux::status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * Cloudlinux Functionality
4
 *
5
 * API Documentation at: .. ill fill this in later from forum posts
6
 *
7
 * Last Changed: $LastChangedDate: 2017-05-26 04:36:01 -0400 (Fri, 26 May 2017) $
8
 * @author detain
9
 * @version $Revision: 24803 $
10
 * @copyright 2017
11
 * @package MyAdmin
12
 * @category Licenses
13
 */
14
15
namespace Detain\Cloudlinux;
16
17
/**
18
 * Cloudlinux Licensing Class
19
 *
20
 * XMLRPC Exception codes:
21
 * 	1 ­ Internal (unknown) Error
22
 * 	10 ­ Not authorized
23
 * 	30 ­ Invalid call arguments
24
 * 	40 ­ Invalid IP format
25
 *
26
 * @link https://cln.cloudlinux.com/clweb/downloads/cloudlinux-xmlrpc-api.pdf XML API Documentation
27
 * @link https://cln.cloudlinux.com/clweb/downloads/cloudlinux-rest-api.pdf REST API Documentation
28
 *
29
 * @access public
30
 */
31
class Cloudlinux
32
{
33
	private $login = '';
34
	private $key = '';
35
	public $prefix = 'registration.';
36
	public $encoding = 'utf-8'; // utf-8 / UTF-8
37
	public $apiType = 'rest';
38
	public $sslverify = false;
39
	public $xmlOptions = [];
40
	public $xmlUrl = 'https://cln.cloudlinux.com/clweb/xmlrpc';
41
	public $restUrl = 'https://cln.cloudlinux.com/api/';
42
	public $restOptions = [];
43
	/**
44
	 * @var \XML_RPC2_Client
45
	 */
46
	public $xmlClient;
47
	public $response;
48
49
	/**
50
	 * Cloudlinux::__construct()
51
	 *
52
	 * @param string $login API Login Name
53
	 * @param string $key API Key
54
	 * @param string $apiType API type to use, can be 'rest' or 'xml'
55
	 */
56
	public function __construct($login, $key, $apiType = 'rest') {
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
57
		$this->login = $login;
58
		$this->key = $key;
59
		$this->apiType = $apiType;
60
		if (!isset($GLOBALS['HTTP_RAW_POST_DATA']))
61
			$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
62
		//if ($this->apiType == 'xml') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
			include_once('XML/RPC2/Client.php');
64
			$this->xmlOptions['prefix'] = $this->prefix;
65
			$this->xmlOptions['encoding'] = $this->encoding;
66
			$this->xmlOptions['sslverify'] = $this->sslverify;
67
			$this->xmlClient = \XML_RPC2_Client::create($this->xmlUrl, $this->xmlOptions);
68
		//} elseif ($this->apiType == 'rest') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
			//$this->restOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslverify;
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
		//}
71
	}
72
73
	/**
74
	 * getcurlpage()
75
	 * gets a webpage via curl and returns the response.
76
	 * also it sets a mozilla type agent.
77
	 * @param string $url        the url of the page you want
78
	 * @param string $postfields postfields in the format of "v1=10&v2=20&v3=30"
79
	 * @param string $options
80
	 * @return string the webpage
81
	 */
82
	public function getcurlpage($url, $postfields = '', $options = '') {
83
		//myadmin_log('myadmin', 'info', "Get Url Page $url", __LINE__, __FILE__);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
84
		$agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2790.0 Safari/537.36';
85
		$curl = curl_init($url);
86
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
87
		curl_setopt($curl, CURLOPT_USERAGENT, $agent);
88
		if (is_array($postfields) || $postfields != '') {
89
			if (is_array($postfields)) {
90
				$postdata = [];
91
				foreach ($postfields as $field => $value) {
92
					$postdata[] = $field . '=' . urlencode($value);
93
				}
94
				curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $postdata));
95
			} else {
96
				curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
97
			}
98
		}
99
		if (is_array($options) && sizeof($options) > 0) {
100
			foreach ($options as $key => $value) {
101
				curl_setopt($curl, $key, $value);
102
			}
103
		}
104
		$tmp = curl_exec($curl);
105
		curl_close($curl);
106
		$ret = $tmp;
107
		return $ret;
108
	}
109
110
	public function log($level, $text, $line = '', $file = '') {
111
		if (function_exists('myadmin_log'))
112
			myadmin_log('cloudlinux', $level, $text, $line, $file);
113
		else
114
			error_log($text);
115
	}
116
117
	/**
118
	 * Return system information about several Cloudlinux services
119
	 *
120
	 * @return array array of system information
121
	 */
122
	public function status() {
123
		$this->response = $this->getcurlpage($this->restUrl.'status.json', '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
		return json_decode($this->response, true);
125
	}
126
127
	/**
128
	 * Will return information about what kind of license types are available for registration and what types are already used by current account.
129
	 * @param string $ipAddress ip address to check
130
	 * @return array returns an array with  available(int[]) ­ list of types that can be used to register new IP license, and owned(int[]) ­ list of types that already registered(owned) by this account
131
	 */
132
	public function availability($ipAddress) {
133
		$this->response = $this->getcurlpage($this->restUrl.'ipl/availability.json?ip='.$ipAddress.'&token='.$this->authToken(), '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
134
		return json_decode($this->response, true);
135
	}
136
137
	/**
138
	 * Check if IP license is registered by any customer.
139
	 *
140
	 * @param string $ipAddress ip address to check
141
	 * @return array Will return list of registered license types or empty list if provided IP is not registered yet.
142
	 */
143
	public function check($ipAddress) {
144
		$this->response = $this->getcurlpage($this->restUrl.'ipl/check.json?ip='.$ipAddress.'&token='.$this->authToken(), '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
145
		$response = json_decode($this->response, true);
146
		if ($response['success'] == 1)
147
			return $response['data'];
148
		else
149
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Detain\Cloudlinux\Cloudlinux::check of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
150
	}
151
152
	/**
153
	 * Will register IP based license for authorized user.
154
	 *
155
	 * @param string $ipAddress ip address to registger
156
	 * @param int $type IP license type (1,2 or 16)
157
	 * @return array On success response returns information about created or already registered license.   ip(string)    type(int) ­ license type (1,2,16)   registered(boolean) ­ true if server was registered in CLN with this license (CLN licenses only).     created(string) ­ license creation time
158
	 */
159
	public function register($ipAddress, $type) {
160
		$this->response = $this->getcurlpage($this->restUrl.'ipl/register.json?ip='.$ipAddress.'&type='.$type.'&token='.$this->authToken(), '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
		return json_decode($this->response, true);
162
	}
163
164
	/**
165
	 * Will remove IP based license from authorized user licenses.
166
	 *
167
	 * @param string $ipAddress ip address to remove licenses on
168
	 * @param int $type optional license type. If empty, will remove licenses with all types
169
	 * @return bool
170
	 */
171
	public function restRemove($ipAddress, $type = 0) {
172
		if ($type != 0)
173
			$this->response = $this->getcurlpage($this->restUrl.'ipl/remove.json?ip='.$ipAddress.'&type='.$type.'&token='.$this->authToken(), '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
174
		else
175
			$this->response = $this->getcurlpage($this->restUrl.'ipl/remove.json?ip='.$ipAddress.'&token='.$this->authToken(), '', $this->restOptions);
0 ignored issues
show
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
176
		return json_decode($this->response, true);
177
	}
178
179
	/**
180
	 * Will remove IP based license from authorized user licenses.
181
	 *
182
	 * @param string $ipAddress ip address to remove licenses on
183
	 * @param int $type optional license type. If empty or 0, will remove licenses with all types
184
	 * @return bool
185
	 */
186
	public function remove($ipAddress, $type = 0) {
187
		if ($this->apiType == 'xml')
188
			return $this->removeLicense($ipAddress, $type);
189
		else
190
			return $this->restRemove($ipAddress, $type);
191
	}
192
193
	/**
194
	 * Return all IP licenses owned by authorized user.
195
	 *
196
	 * @return array an array of licenses each one containing these fields: ip(string)   ype(int) ­ license type (1,2,16)   registered(boolean) ­ true if server was registered in CLN with this license (CLN licenses only).    created(string) ­ license creation time
197
	 */
198
	public function restList() {
199
		$this->response = $this->getcurlpage($this->restUrl.'ipl/list.json?token='.$this->uthToken(), '', $this->restOptions);
0 ignored issues
show
Bug introduced by
The method uthToken() does not exist on Detain\Cloudlinux\Cloudlinux. Did you maybe mean authToken()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Documentation introduced by
$this->restOptions is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
200
		return json_decode($this->response, true);
201
	}
202
203
	/**
204
	 * automatic authToken generator
205
	 *
206
	 * @return string the authToken
207
	 */
208
	public function authToken() {
209
		$time = time();
210
		try {
211
			return $this->login . '|' . $time . '|' . sha1($this->key . $time);
212
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
213
			$this->log('error', 'Caught exception code: ' . $e->getCode());
214
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
215
			return false;
216
		}
217
	}
218
219
	/**
220
	 * Register new IP license.
221
	 *
222
	 * @param string $ipAddress IP Address
223
	 * @param integer $type license type (1,2 or 16)
224
	 * @throws XmlRpcException for critical errors
225
	 * @return integer 0 on success, -1 on error
226
	 */
227
	public function license($ipAddress, $type) {
228
		$type = (int)$type;
229
		try {
230
			$this->log('error', 'Calling License(' . $this->authToken() . ',' . $ipAddress . ',' . $type . ')');
231
			$this->response = $this->xmlClient->license($this->authToken(), $ipAddress, $type);
232
			$this->log('error', 'Response: ' . var_export($this->response, true));
233
			return $this->response;
234
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
235
			$this->log('error', 'Caught exception code: ' . $e->getCode());
236
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
237
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Detain\Cloudlinux\Cloudlinux::license of type integer.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
238
		}
239
	}
240
241
	/**
242
	 * Remove IP licenses with specified type for customer. Also un­registers from CLN server associated with IP.
243
	 * or
244
	 * Remove IP licenses with specified type for customer. Also un­registers from CLN server associated with IP.
245
	 * @param string         $ipAddress   ip address to remove
246
	 * @param bool|false|int $type optional parameter to specify the type of license to remove (1,2, or 16)
247
	 * @return integer 0 on success, -1 on error, Error will be returned also if account have no licenses for provided IP.
248
	 */
249
	public function removeLicense($ipAddress, $type = false) {
250
		$this->log('info', "Calling CLoudLinux->xmlClient->removeLicense({$this->authToken()}, {$ipAddress}, {$type})", __LINE__, __FILE__);
251
		try {
252
			if ($type === false)
253
				return $this->response = $this->remove($ipAddress);
254
			else
255
				return $this->response = $this->remove($ipAddress, $type);
0 ignored issues
show
Bug introduced by
It seems like $type defined by parameter $type on line 249 can also be of type boolean; however, Detain\Cloudlinux\Cloudlinux::remove() does only seem to accept integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
256
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
257
			$this->log('error', 'Caught exception code: ' . $e->getCode());
258
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
259
			return false;
260
		}
261
	}
262
263
	/**
264
	 * Check if IP license was registered by any customer. Arguments:
265
	 *
266
	 * @param string $ipAddress ip address to remove
267
	 * @param bool $checkAll True will search for any type of license. False ­ only for types 1 or 2
268
	 * @throws XmlRpcException for critical errors
269
	 * @return array (list<int>): List of registered license types or empty list if no license found
270
	 */
271
	public function isLicensed($ipAddress, $checkAll = true) {
272
		if ($this->apiType == 'xml')
273
			return $this->xmlIsLicensed($ipAddress, $checkAll);
274
		else
275
			return $this->check($ipAddress, $checkAll);
0 ignored issues
show
Unused Code introduced by
The call to Cloudlinux::check() has too many arguments starting with $checkAll.

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...
276
	}
277
	/**
278
	 * Check if IP license was registered by any customer. Arguments:
279
	 *
280
	 * @param string $ipAddress ip address to remove
281
	 * @param bool $checkAll True will search for any type of license. False ­ only for types 1 or 2
282
	 * @throws XmlRpcException for critical errors
283
	 * @return array (list<int>): List of registered license types or empty list if no license found
284
	 */
285 View Code Duplication
	public function xmlIsLicensed($ipAddress, $checkAll = true) {
1 ignored issue
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...
286
		try {
287
			return $this->response = $this->xmlClient->isLicensed($this->authToken(), $ipAddress, $checkAll);
288
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
289
			$this->log('error', 'Caught exception code: ' . $e->getCode());
290
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
291
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Detain\Cloudlinux\Cloudlinux::xmlIsLicensed of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
292
		}
293
	}
294
295
	/**
296
	 * @return bool|mixed
297
	 */
298
	public function licenseList() {
299
		try {
300
			return json_decode($this->getcurlpage($this->restUrl.'ipl/list.json?token=' . $this->authToken()));
301
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
302
			$this->log('error', 'Caught exception code: ' . $e->getCode());
303
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
304
			return false;
305
		}
306
	}
307
308
	/**
309
	 * Return list of all IP licenses owned by authorized user
310
	 *
311
	 * @throws XmlRpcException for critical errors
312
	 * @return array (list<structure>): List of structures or empty list. Each structure contains keys:
313
	 * 	IP(string)
314
	 * 	TYPE(int) ­ license type
315
	 * 	REGISTERED(boolean) ­ True if server was registered in CLN with this license
316
	 */
317 View Code Duplication
	public function reconcile() {
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...
318
		try {
319
			return $this->response = $this->xmlClient->reconcile($this->authToken());
320
		} catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Detain\Cloudlinux\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
321
			$this->log('error', 'Caught exception code: ' . $e->getCode());
322
			$this->log('error', 'Caught exception message: ' . $e->getMessage());
323
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Detain\Cloudlinux\Cloudlinux::reconcile of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
324
		}
325
	}
326
327
	/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
328
	public function getKeyInfo($Key) {
329
	$this->response = $this->xml->__call('partner10.getKeyInfo', array(
330
	$this->AuthInfo(),
331
	$Key,
332
	));
333
	return $this->response;
334
	}
335
	*/
336
}
337
338