Complex classes like ftp_pure 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_pure, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class ftp_pure extends ftp_base { |
||
| 29 | |||
| 30 | function __construct($verb=FALSE, $le=FALSE) { |
||
| 33 | |||
| 34 | // <!-- --------------------------------------------------------------------------------------- --> |
||
| 35 | // <!-- Private functions --> |
||
| 36 | // <!-- --------------------------------------------------------------------------------------- --> |
||
| 37 | |||
| 38 | function _settimeout($sock) { |
||
| 46 | |||
| 47 | function _connect($host, $port) { |
||
| 57 | |||
| 58 | function _readmsg($fnction="_readmsg"){ |
||
| 81 | |||
| 82 | function _exec($cmd, $fnction="_exec") { |
||
| 97 | |||
| 98 | function _data_prepare($mode=FTP_ASCII) { |
||
| 126 | |||
| 127 | function _data_read($mode=FTP_ASCII, $fp=NULL) { |
||
| 128 | if(is_resource($fp)) $out=0; |
||
| 129 | else $out=""; |
||
| 130 | if(!$this->_passive) { |
||
| 131 | $this->SendMSG("Only passive connections available!"); |
||
| 132 | return FALSE; |
||
| 133 | } |
||
| 134 | while (!feof($this->_ftp_data_sock)) { |
||
| 135 | $block=fread($this->_ftp_data_sock, $this->_ftp_buff_size); |
||
| 136 | if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block); |
||
| 137 | if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block)); |
||
| 138 | else $out.=$block; |
||
| 139 | } |
||
| 140 | return $out; |
||
| 141 | } |
||
| 142 | |||
| 143 | function _data_write($mode=FTP_ASCII, $fp=NULL) { |
||
| 144 | if(is_resource($fp)) $out=0; |
||
| 145 | else $out=""; |
||
| 146 | if(!$this->_passive) { |
||
| 147 | $this->SendMSG("Only passive connections available!"); |
||
| 148 | return FALSE; |
||
| 149 | } |
||
| 150 | if(is_resource($fp)) { |
||
| 151 | while(!feof($fp)) { |
||
| 152 | $block=fread($fp, $this->_ftp_buff_size); |
||
| 153 | if(!$this->_data_write_block($mode, $block)) return false; |
||
| 154 | } |
||
| 155 | } elseif(!$this->_data_write_block($mode, $fp)) return false; |
||
| 156 | return TRUE; |
||
| 157 | } |
||
| 158 | |||
| 159 | function _data_write_block($mode, $block) { |
||
| 160 | if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block); |
||
| 161 | do { |
||
| 162 | if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) { |
||
| 163 | $this->PushError("_data_write","Can't write to socket"); |
||
| 164 | return FALSE; |
||
| 165 | } |
||
| 166 | $block=substr($block, $t); |
||
| 167 | } while(!empty($block)); |
||
| 168 | return true; |
||
| 169 | } |
||
| 170 | |||
| 171 | function _data_close() { |
||
| 176 | |||
| 177 | function _quit($force=FALSE) { |
||
| 184 | } |
||
| 185 | |||
| 186 | ?> |
||
| 187 |
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: