| Conditions | 10 |
| Paths | 24 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 210 | public function syncDirectory($src, $dst, callable $syncop = null) |
||
| 211 | { |
||
| 212 | $this->login(); |
||
| 213 | |||
| 214 | $this->syncDelete($src, $dst, $syncop); |
||
| 215 | |||
| 216 | // create new directories |
||
| 217 | $finderdir = new Finder(); |
||
| 218 | $finderdir->directories()->ignoreDotFiles(false)->followLinks()->in($src)->notName('.git*'); |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @var SplFileInfo $dir |
||
| 222 | */ |
||
| 223 | foreach ($finderdir as $dir) { |
||
| 224 | $dirpathFtp = $dst . "/" . strtr($dir->getRelativePathname(), ["\\" => "/"]); |
||
| 225 | $stat = $this->sftp->stat($dirpathFtp); |
||
| 226 | if (!$stat) { |
||
| 227 | if ($syncop) { |
||
| 228 | $syncop(self::CREATE_DIR, $dirpathFtp); |
||
| 229 | } |
||
| 230 | $this->sftp->mkdir($dirpathFtp, $dir->getRealPath(), SFTP::SOURCE_LOCAL_FILE); |
||
| 231 | $this->sftp->chmod(0755, $dirpathFtp, $dir->getRealPath()); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | // copy new files or update if younger |
||
| 236 | $finderdir = new Finder(); |
||
| 237 | $finderdir->files()->ignoreDotFiles(false)->followLinks()->in($src)->notName('.git*'); |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @var SplFileInfo $file |
||
| 241 | */ |
||
| 242 | foreach ($finderdir as $file) { |
||
| 243 | $filepathFtp = $dst . "/" . strtr($file->getRelativePathname(), ["\\" => "/"]); |
||
| 244 | $stat = $this->sftp->stat($filepathFtp); |
||
| 245 | if (!$stat) { |
||
| 246 | if ($syncop) { |
||
| 247 | $syncop(self::NEW_FILE, $filepathFtp); |
||
| 248 | } |
||
| 249 | $this->sftp->put($filepathFtp, $file->getRealPath(), SFTP::SOURCE_LOCAL_FILE); |
||
| 250 | } else { |
||
| 251 | $size = $this->sftp->size($filepathFtp); |
||
| 252 | if (($file->getMTime() > $stat['mtime']) || ($file->getSize() != $size)) { |
||
| 253 | if ($syncop) { |
||
| 254 | $syncop(self::UPDATE_FILE, $filepathFtp); |
||
| 255 | } |
||
| 256 | $this->sftp->put($filepathFtp, $file->getRealPath(), SFTP::SOURCE_LOCAL_FILE); |
||
| 257 | } |
||
| 258 | } |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 263 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.