Completed
Pull Request — master (#2)
by Stephen
13:19
created

ftp_sockets   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 218
rs 6.8
c 0
b 0
f 0
wmc 55
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _connect() 0 16 4
B _readmsg() 0 23 5
B _exec() 0 15 5
A _data_close() 0 6 1
A _quit() 0 7 2
A _settimeout() 0 13 3
C _data_prepare() 0 63 14
C _data_read() 0 22 8
B _data_write() 0 21 8
A _data_write_block() 0 12 4

How to fix   Complexity   

Complex Class

Complex classes like ftp_sockets often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ftp_sockets, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * PemFTP - A Ftp implementation in pure PHP
4
 *
5
 * @package PemFTP
6
 * @since 2.5.0
7
 *
8
 * @version 1.0
9
 * @copyright Alexey Dotsenko
10
 * @author Alexey Dotsenko
11
 * @link http://www.phpclasses.org/browse/package/1743.html Site
12
 * @license LGPL http://www.opensource.org/licenses/lgpl-license.html
13
 */
14
15
/**
16
 * Socket Based FTP implementation
17
 *
18
 * @package PemFTP
19
 * @subpackage Socket
20
 * @since 2.5.0
21
 *
22
 * @version 1.0
23
 * @copyright Alexey Dotsenko
24
 * @author Alexey Dotsenko
25
 * @link http://www.phpclasses.org/browse/package/1743.html Site
26
 * @license LGPL http://www.opensource.org/licenses/lgpl-license.html
27
 */
28
class ftp_sockets extends ftp_base {
29
30
	function __construct($verb=FALSE, $le=FALSE) {
31
		parent::__construct(true, $verb, $le);
32
	}
33
34
// <!-- --------------------------------------------------------------------------------------- -->
35
// <!--       Private functions                                                                 -->
36
// <!-- --------------------------------------------------------------------------------------- -->
37
38
	function _settimeout($sock) {
39
		if(!@socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
40
			$this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_last_error($sock)) is of type string, but the function expects a boolean.

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...
41
			@socket_close($sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
42
			return FALSE;
43
		}
44
		if(!@socket_set_option($sock, SOL_SOCKET , SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
45
			$this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_last_error($sock)) is of type string, but the function expects a boolean.

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...
46
			@socket_close($sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
47
			return FALSE;
48
		}
49
		return true;
50
	}
51
52
	function _connect($host, $port) {
53
		$this->SendMSG("Creating socket");
54
		if(!($sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
55
			$this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_last_error($sock)) is of type string, but the function expects a boolean.

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...
56
			return FALSE;
57
		}
58
		if(!$this->_settimeout($sock)) return FALSE;
59
		$this->SendMSG("Connecting to \"".$host.":".$port."\"");
60
		if (!($res = @socket_connect($sock, $host, $port))) {
61
			$this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_last_error($sock)) is of type string, but the function expects a boolean.

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...
62
			@socket_close($sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
63
			return FALSE;
64
		}
65
		$this->_connected=true;
66
		return $sock;
67
	}
68
69
	function _readmsg($fnction="_readmsg"){
70
		if(!$this->_connected) {
71
			$this->PushError($fnction,'Connect first');
72
			return FALSE;
73
		}
74
		$result=true;
75
		$this->_message="";
76
		$this->_code=0;
77
		$go=true;
0 ignored issues
show
Unused Code introduced by
$go 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...
78
		do {
79
			$tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
80
			if($tmp===false) {
81
				$go=$result=false;
82
				$this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...is->_ftp_control_sock)) is of type string, but the function expects a boolean.

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...
83
			} else {
84
				$this->_message.=$tmp;
85
				$go = !preg_match("/^([0-9]{3})(-.+\\1)? [^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
86
			}
87
		} while($go);
88
		if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
89
		$this->_code=(int)$regs[1];
0 ignored issues
show
Bug introduced by
The variable $regs does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
90
		return $result;
91
	}
92
93
	function _exec($cmd, $fnction="_exec") {
94
		if(!$this->_ready) {
95
			$this->PushError($fnction,'Connect first');
96
			return FALSE;
97
		}
98
		if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
99
		$status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
100
		if($status===false) {
101
			$this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
0 ignored issues
show
Bug introduced by
The property stream does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Documentation introduced by
socket_strerror(socket_last_error($this->stream)) is of type string, but the function expects a boolean.

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...
102
			return FALSE;
103
		}
104
		$this->_lastaction=time();
105
		if(!$this->_readmsg($fnction)) return FALSE;
106
		return TRUE;
107
	}
108
109
	function _data_prepare($mode=FTP_ASCII) {
110
		if(!$this->_settype($mode)) return FALSE;
111
		$this->SendMSG("Creating data socket");
112
		$this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
113
		if ($this->_ftp_data_sock < 0) {
114
			$this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_data_sock)) is of type string, but the function expects a boolean.

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...
115
			return FALSE;
116
		}
117
		if(!$this->_settimeout($this->_ftp_data_sock)) {
118
			$this->_data_close();
119
			return FALSE;
120
		}
121
		if($this->_passive) {
122
			if(!$this->_exec("PASV", "pasv")) {
123
				$this->_data_close();
124
				return FALSE;
125
			}
126
			if(!$this->_checkCode()) {
127
				$this->_data_close();
128
				return FALSE;
129
			}
130
			$ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
131
			$this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
132
			$this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
133
			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
134
			if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
135
				$this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_data_sock)) is of type string, but the function expects a boolean.

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...
136
				$this->_data_close();
137
				return FALSE;
138
			}
139
			else $this->_ftp_temp_sock=$this->_ftp_data_sock;
140
		} else {
141
			if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
142
				$this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...is->_ftp_control_sock)) is of type string, but the function expects a boolean.

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...
143
				$this->_data_close();
144
				return FALSE;
145
			}
146
			if(!@socket_bind($this->_ftp_data_sock,$addr)){
147
				$this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_data_sock)) is of type string, but the function expects a boolean.

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...
148
				$this->_data_close();
149
				return FALSE;
150
			}
151
			if(!@socket_listen($this->_ftp_data_sock)) {
152
				$this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_data_sock)) is of type string, but the function expects a boolean.

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...
153
				$this->_data_close();
154
				return FALSE;
155
			}
156
			if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
157
				$this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_data_sock)) is of type string, but the function expects a boolean.

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...
158
				$this->_data_close();
159
				return FALSE;
160
			}
161
			if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
162
				$this->_data_close();
163
				return FALSE;
164
			}
165
			if(!$this->_checkCode()) {
166
				$this->_data_close();
167
				return FALSE;
168
			}
169
		}
170
		return TRUE;
171
	}
172
173
	function _data_read($mode=FTP_ASCII, $fp=NULL) {
174
		$NewLine=$this->_eol_code[$this->OS_local];
0 ignored issues
show
Unused Code introduced by
$NewLine 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...
175
		if(is_resource($fp)) $out=0;
176
		else $out="";
177
		if(!$this->_passive) {
178
			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
179
			$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
180
			if($this->_ftp_temp_sock===FALSE) {
181
				$this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_temp_sock)) is of type string, but the function expects a boolean.

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...
182
				$this->_data_close();
183
				return FALSE;
184
			}
185
		}
186
187
		while(($block=@socket_read($this->_ftp_temp_sock, $this->_ftp_buff_size, PHP_BINARY_READ))!==false) {
188
			if($block==="") break;
189
			if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
190
			if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
191
			else $out.=$block;
192
		}
193
		return $out;
194
	}
195
196
	function _data_write($mode=FTP_ASCII, $fp=NULL) {
197
		$NewLine=$this->_eol_code[$this->OS_local];
0 ignored issues
show
Unused Code introduced by
$NewLine 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...
198
		if(is_resource($fp)) $out=0;
0 ignored issues
show
Unused Code introduced by
$out 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...
199
		else $out="";
0 ignored issues
show
Unused Code introduced by
$out 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...
200
		if(!$this->_passive) {
201
			$this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
202
			$this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
203
			if($this->_ftp_temp_sock===FALSE) {
204
				$this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_temp_sock)) is of type string, but the function expects a boolean.

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...
205
				$this->_data_close();
206
				return false;
207
			}
208
		}
209
		if(is_resource($fp)) {
210
			while(!feof($fp)) {
211
				$block=fread($fp, $this->_ftp_buff_size);
212
				if(!$this->_data_write_block($mode, $block)) return false;
213
			}
214
		} elseif(!$this->_data_write_block($mode, $fp)) return false;
215
		return true;
216
	}
217
218
	function _data_write_block($mode, $block) {
219
		if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
220
		do {
221
			if(($t=@socket_write($this->_ftp_temp_sock, $block))===FALSE) {
222
				$this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
0 ignored issues
show
Documentation introduced by
socket_strerror(socket_l...$this->_ftp_temp_sock)) is of type string, but the function expects a boolean.

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...
223
				$this->_data_close();
224
				return FALSE;
225
			}
226
			$block=substr($block, $t);
227
		} while(!empty($block));
228
		return true;
229
	}
230
231
	function _data_close() {
232
		@socket_close($this->_ftp_temp_sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
233
		@socket_close($this->_ftp_data_sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
234
		$this->SendMSG("Disconnected data from remote host");
235
		return TRUE;
236
	}
237
238
	function _quit() {
239
		if($this->_connected) {
240
			@socket_close($this->_ftp_control_sock);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
241
			$this->_connected=false;
242
			$this->SendMSG("Socket closed");
243
		}
244
	}
245
}
246
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
247