@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | foreach ($contents as $i) |
| 94 | 94 | { |
| 95 | - if (is_file($directory.'/'.$i)) |
|
| 95 | + if (is_file($directory . '/' . $i)) |
|
| 96 | 96 | { |
| 97 | 97 | $allContents[] = $i; |
| 98 | 98 | |
| 99 | - $this->buffer = $directory.'/'.$i; |
|
| 99 | + $this->buffer = $directory . '/' . $i; |
|
| 100 | 100 | call_user_func($fileCallback, $this); |
| 101 | 101 | } |
| 102 | - else if (is_dir($directory.'/'.$i)) |
|
| 102 | + else if (is_dir($directory . '/' . $i)) |
|
| 103 | 103 | { |
| 104 | 104 | $allContents[] = $i; |
| 105 | - $contents = $this->getContents($directory.'/'.$i, $fileCallback, $dirCallback); |
|
| 105 | + $contents = $this->getContents($directory . '/' . $i, $fileCallback, $dirCallback); |
|
| 106 | 106 | |
| 107 | 107 | if (count($contents)) |
| 108 | 108 | $allContents[] = $contents; |
| 109 | 109 | |
| 110 | - $this->buffer = $directory.'/'.$i; |
|
| 110 | + $this->buffer = $directory . '/' . $i; |
|
| 111 | 111 | call_user_func($dirCallback, $this); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | if (!empty($path)) |
| 182 | 182 | if (!strlen(stristr($item, $path)) > 0) |
| 183 | 183 | continue; |
| 184 | - if (strstr($item,'~') === false && $item != '.' && $item != '..') |
|
| 184 | + if (strstr($item, '~') === false && $item != '.' && $item != '..') |
|
| 185 | 185 | $filesToReturn[] = $item; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | { |
| 320 | 320 | foreach ($files["folders"] as $folder) |
| 321 | 321 | { |
| 322 | - if (!file_exists($dest.'/'.$folder)) |
|
| 322 | + if (!file_exists($dest . '/' . $folder)) |
|
| 323 | 323 | mkdir("$dest/$folder", 0777, true); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | foreach ($files["files"] as $item) |
| 329 | 329 | { |
| 330 | 330 | if (!file_exists("$dest/$files")) |
| 331 | - copy($item, $dest.'/'.$item); |
|
| 331 | + copy($item, $dest . '/' . $item); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | ); |
| 337 | 337 | } |
| 338 | 338 | else if (is_dir($dest)) |
| 339 | - copy($file, $dest.'/'.$file); |
|
| 339 | + copy($file, $dest . '/' . $file); |
|
| 340 | 340 | else |
| 341 | 341 | copy($file, $dest); |
| 342 | 342 | |
@@ -357,12 +357,12 @@ discard block |
||
| 357 | 357 | throw new \InvalidArgumentException("Missing first parameter"); |
| 358 | 358 | |
| 359 | 359 | if (is_dir($newfile)) |
| 360 | - $newfile .= '/'.basename($oldfile); |
|
| 360 | + $newfile .= '/' . basename($oldfile); |
|
| 361 | 361 | |
| 362 | 362 | if ($oldfile == $newfile) |
| 363 | 363 | throw new \Exception("'$oldfile' and '$newfile' are the same file"); |
| 364 | 364 | |
| 365 | - if(!rename($oldfile, $newfile)) |
|
| 365 | + if (!rename($oldfile, $newfile)) |
|
| 366 | 366 | return false; |
| 367 | 367 | |
| 368 | 368 | return true; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | else { |
| 393 | 393 | if (!is_dir($dir)) |
| 394 | 394 | { |
| 395 | - if(!mkdir("$dir", 0777)) |
|
| 395 | + if (!mkdir("$dir", 0777)) |
|
| 396 | 396 | return false; |
| 397 | 397 | } |
| 398 | 398 | } |
@@ -84,8 +84,9 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | foreach ($this->ls($directory) as $item) |
| 86 | 86 | { |
| 87 | - if ($item != '.' && $item != '..') |
|
| 88 | - $contents[] = $item; |
|
| 87 | + if ($item != '.' && $item != '..') { |
|
| 88 | + $contents[] = $item; |
|
| 89 | + } |
|
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | if (count($contents) > 0) |
@@ -98,28 +99,29 @@ discard block |
||
| 98 | 99 | |
| 99 | 100 | $this->buffer = $directory.'/'.$i; |
| 100 | 101 | call_user_func($fileCallback, $this); |
| 101 | - } |
|
| 102 | - else if (is_dir($directory.'/'.$i)) |
|
| 102 | + } else if (is_dir($directory.'/'.$i)) |
|
| 103 | 103 | { |
| 104 | 104 | $allContents[] = $i; |
| 105 | 105 | $contents = $this->getContents($directory.'/'.$i, $fileCallback, $dirCallback); |
| 106 | 106 | |
| 107 | - if (count($contents)) |
|
| 108 | - $allContents[] = $contents; |
|
| 107 | + if (count($contents)) { |
|
| 108 | + $allContents[] = $contents; |
|
| 109 | + } |
|
| 109 | 110 | |
| 110 | 111 | $this->buffer = $directory.'/'.$i; |
| 111 | 112 | call_user_func($dirCallback, $this); |
| 112 | 113 | } |
| 113 | 114 | } |
| 114 | 115 | } |
| 116 | + } else if (is_file($directory)) { |
|
| 117 | + throw new \InvalidArgumentException("'$directory' is actually a file"); |
|
| 118 | + } else { |
|
| 119 | + throw new \InvalidArgumentException("The directory '$directory' does not exists"); |
|
| 115 | 120 | } |
| 116 | - else if (is_file($directory)) |
|
| 117 | - throw new \InvalidArgumentException("'$directory' is actually a file"); |
|
| 118 | - else |
|
| 119 | - throw new \InvalidArgumentException("The directory '$directory' does not exists"); |
|
| 120 | 121 | |
| 121 | - if (!is_null($callback)) |
|
| 122 | - call_user_func($callback, $this); |
|
| 122 | + if (!is_null($callback)) { |
|
| 123 | + call_user_func($callback, $this); |
|
| 124 | + } |
|
| 123 | 125 | |
| 124 | 126 | return $allContents; |
| 125 | 127 | } |
@@ -131,10 +133,11 @@ discard block |
||
| 131 | 133 | */ |
| 132 | 134 | public function pwd() |
| 133 | 135 | { |
| 134 | - if (getcwd()) |
|
| 135 | - $this->buffer = getcwd(); |
|
| 136 | - else |
|
| 137 | - return false; |
|
| 136 | + if (getcwd()) { |
|
| 137 | + $this->buffer = getcwd(); |
|
| 138 | + } else { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 138 | 141 | |
| 139 | 142 | return $this->buffer; |
| 140 | 143 | } |
@@ -153,36 +156,38 @@ discard block |
||
| 153 | 156 | |
| 154 | 157 | $path = (is_null($path) || empty($path)) ? '.' : $path; |
| 155 | 158 | |
| 156 | - if (is_file($path)) |
|
| 157 | - $filesToReturn = array($path); |
|
| 158 | - else if (is_dir($path)) |
|
| 159 | + if (is_file($path)) { |
|
| 160 | + $filesToReturn = array($path); |
|
| 161 | + } else if (is_dir($path)) |
|
| 159 | 162 | { |
| 160 | 163 | $pathIns = dir($path); |
| 161 | 164 | |
| 162 | - if ($recursive) |
|
| 163 | - $filesToReturn = $this->getContents($path); |
|
| 164 | - else |
|
| 165 | + if ($recursive) { |
|
| 166 | + $filesToReturn = $this->getContents($path); |
|
| 167 | + } else |
|
| 165 | 168 | { |
| 166 | 169 | while (($item = $pathIns->read()) !== false) |
| 167 | 170 | { |
| 168 | - if ($item != '.' && $item != '..') |
|
| 169 | - $filesToReturn[] = $item; |
|
| 171 | + if ($item != '.' && $item != '..') { |
|
| 172 | + $filesToReturn[] = $item; |
|
| 173 | + } |
|
| 170 | 174 | } |
| 171 | 175 | |
| 172 | 176 | $pathIns->close(); |
| 173 | 177 | } |
| 174 | - } |
|
| 175 | - else { |
|
| 178 | + } else { |
|
| 176 | 179 | |
| 177 | 180 | $contents = $this->ls(); |
| 178 | 181 | |
| 179 | 182 | foreach ($contents as $item) |
| 180 | 183 | { |
| 181 | - if (!empty($path)) |
|
| 182 | - if (!strlen(stristr($item, $path)) > 0) |
|
| 184 | + if (!empty($path)) { |
|
| 185 | + if (!strlen(stristr($item, $path)) > 0) |
|
| 183 | 186 | continue; |
| 184 | - if (strstr($item,'~') === false && $item != '.' && $item != '..') |
|
| 185 | - $filesToReturn[] = $item; |
|
| 187 | + } |
|
| 188 | + if (strstr($item,'~') === false && $item != '.' && $item != '..') { |
|
| 189 | + $filesToReturn[] = $item; |
|
| 190 | + } |
|
| 186 | 191 | } |
| 187 | 192 | } |
| 188 | 193 | |
@@ -202,8 +207,9 @@ discard block |
||
| 202 | 207 | |
| 203 | 208 | if (is_dir($path)) |
| 204 | 209 | { |
| 205 | - if (chdir($path)) |
|
| 206 | - return true; |
|
| 210 | + if (chdir($path)) { |
|
| 211 | + return true; |
|
| 212 | + } |
|
| 207 | 213 | } |
| 208 | 214 | |
| 209 | 215 | return false; |
@@ -245,12 +251,13 @@ discard block |
||
| 245 | 251 | { |
| 246 | 252 | $recursive = is_null($recursive) ? false : $recursive; |
| 247 | 253 | |
| 248 | - if (is_null($file)) |
|
| 249 | - throw new \InvalidArgumentException("Missing first parameter"); |
|
| 254 | + if (is_null($file)) { |
|
| 255 | + throw new \InvalidArgumentException("Missing first parameter"); |
|
| 256 | + } |
|
| 250 | 257 | |
| 251 | - if (file_exists($file) && !$recursive) |
|
| 252 | - unlink($file); |
|
| 253 | - elseif (is_dir($file) && $recursive) |
|
| 258 | + if (file_exists($file) && !$recursive) { |
|
| 259 | + unlink($file); |
|
| 260 | + } elseif (is_dir($file) && $recursive) |
|
| 254 | 261 | { |
| 255 | 262 | $that = $this; |
| 256 | 263 | |
@@ -279,11 +286,13 @@ discard block |
||
| 279 | 286 | { |
| 280 | 287 | $recursive = (is_null($recursive)) ? false : $recursive; |
| 281 | 288 | |
| 282 | - if (empty($file) || empty($dest)) |
|
| 283 | - throw new \InvalidArgumentException("Missing parameters"); |
|
| 289 | + if (empty($file) || empty($dest)) { |
|
| 290 | + throw new \InvalidArgumentException("Missing parameters"); |
|
| 291 | + } |
|
| 284 | 292 | |
| 285 | - if (is_dir($file) && !$recursive) |
|
| 286 | - throw new \RuntimeException("Ommiting directory <<$foo>>"); |
|
| 293 | + if (is_dir($file) && !$recursive) { |
|
| 294 | + throw new \RuntimeException("Ommiting directory <<$foo>>"); |
|
| 295 | + } |
|
| 287 | 296 | |
| 288 | 297 | $dest_exists = file_exists($dest); |
| 289 | 298 | |
@@ -296,8 +305,9 @@ discard block |
||
| 296 | 305 | |
| 297 | 306 | $files["folders"][] = is_dir($dest) ? basename($file) : $dest; |
| 298 | 307 | |
| 299 | - if (!$dest_exists) |
|
| 300 | - mkdir($dest); |
|
| 308 | + if (!$dest_exists) { |
|
| 309 | + mkdir($dest); |
|
| 310 | + } |
|
| 301 | 311 | |
| 302 | 312 | $that = $this; |
| 303 | 313 | |
@@ -319,26 +329,28 @@ discard block |
||
| 319 | 329 | { |
| 320 | 330 | foreach ($files["folders"] as $folder) |
| 321 | 331 | { |
| 322 | - if (!file_exists($dest.'/'.$folder)) |
|
| 323 | - mkdir("$dest/$folder", 0777, true); |
|
| 332 | + if (!file_exists($dest.'/'.$folder)) { |
|
| 333 | + mkdir("$dest/$folder", 0777, true); |
|
| 334 | + } |
|
| 324 | 335 | } |
| 325 | 336 | |
| 326 | 337 | if (count($files["files"])) |
| 327 | 338 | { |
| 328 | 339 | foreach ($files["files"] as $item) |
| 329 | 340 | { |
| 330 | - if (!file_exists("$dest/$files")) |
|
| 331 | - copy($item, $dest.'/'.$item); |
|
| 341 | + if (!file_exists("$dest/$files")) { |
|
| 342 | + copy($item, $dest.'/'.$item); |
|
| 343 | + } |
|
| 332 | 344 | } |
| 333 | 345 | } |
| 334 | 346 | } |
| 335 | 347 | } |
| 336 | 348 | ); |
| 349 | + } else if (is_dir($dest)) { |
|
| 350 | + copy($file, $dest.'/'.$file); |
|
| 351 | + } else { |
|
| 352 | + copy($file, $dest); |
|
| 337 | 353 | } |
| 338 | - else if (is_dir($dest)) |
|
| 339 | - copy($file, $dest.'/'.$file); |
|
| 340 | - else |
|
| 341 | - copy($file, $dest); |
|
| 342 | 354 | |
| 343 | 355 | return true; |
| 344 | 356 | } |
@@ -353,17 +365,21 @@ discard block |
||
| 353 | 365 | */ |
| 354 | 366 | public function mv($oldfile, $newfile) |
| 355 | 367 | { |
| 356 | - if (empty($oldfile)) |
|
| 357 | - throw new \InvalidArgumentException("Missing first parameter"); |
|
| 368 | + if (empty($oldfile)) { |
|
| 369 | + throw new \InvalidArgumentException("Missing first parameter"); |
|
| 370 | + } |
|
| 358 | 371 | |
| 359 | - if (is_dir($newfile)) |
|
| 360 | - $newfile .= '/'.basename($oldfile); |
|
| 372 | + if (is_dir($newfile)) { |
|
| 373 | + $newfile .= '/'.basename($oldfile); |
|
| 374 | + } |
|
| 361 | 375 | |
| 362 | - if ($oldfile == $newfile) |
|
| 363 | - throw new \Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 376 | + if ($oldfile == $newfile) { |
|
| 377 | + throw new \Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 378 | + } |
|
| 364 | 379 | |
| 365 | - if(!rename($oldfile, $newfile)) |
|
| 366 | - return false; |
|
| 380 | + if(!rename($oldfile, $newfile)) { |
|
| 381 | + return false; |
|
| 382 | + } |
|
| 367 | 383 | |
| 368 | 384 | return true; |
| 369 | 385 | } |
@@ -379,21 +395,24 @@ discard block |
||
| 379 | 395 | */ |
| 380 | 396 | public function mkdir($dir, $dest = null, $recursive = null) |
| 381 | 397 | { |
| 382 | - if (empty($dir)) |
|
| 383 | - throw new \InvalidArgumentException("Missing first parameter"); |
|
| 398 | + if (empty($dir)) { |
|
| 399 | + throw new \InvalidArgumentException("Missing first parameter"); |
|
| 400 | + } |
|
| 384 | 401 | |
| 385 | - if (empty($dest)) |
|
| 386 | - $dest = '.'; |
|
| 402 | + if (empty($dest)) { |
|
| 403 | + $dest = '.'; |
|
| 404 | + } |
|
| 387 | 405 | |
| 388 | 406 | $recursive = (is_null($recursive)) ? false : $recursive; |
| 389 | 407 | |
| 390 | - if ($recursive) |
|
| 391 | - mkdir("$dest/$dir", 0777, true); |
|
| 392 | - else { |
|
| 408 | + if ($recursive) { |
|
| 409 | + mkdir("$dest/$dir", 0777, true); |
|
| 410 | + } else { |
|
| 393 | 411 | if (!is_dir($dir)) |
| 394 | 412 | { |
| 395 | - if(!mkdir("$dir", 0777)) |
|
| 396 | - return false; |
|
| 413 | + if(!mkdir("$dir", 0777)) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 397 | 416 | } |
| 398 | 417 | } |
| 399 | 418 | return true; |
@@ -408,12 +427,14 @@ discard block |
||
| 408 | 427 | */ |
| 409 | 428 | public function rmdir($dir) |
| 410 | 429 | { |
| 411 | - if (is_null($dir) || empty($dir)) |
|
| 412 | - throw new \RuntimeException("Missing first parameter"); |
|
| 430 | + if (is_null($dir) || empty($dir)) { |
|
| 431 | + throw new \RuntimeException("Missing first parameter"); |
|
| 432 | + } |
|
| 413 | 433 | |
| 414 | - if (rmdir($dir)) |
|
| 415 | - return true; |
|
| 416 | - else |
|
| 417 | - return false; |
|
| 434 | + if (rmdir($dir)) { |
|
| 435 | + return true; |
|
| 436 | + } else { |
|
| 437 | + return false; |
|
| 438 | + } |
|
| 418 | 439 | } |
| 419 | 440 | } |
| 420 | 441 | \ No newline at end of file |