@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __destruct() |
| 47 | 47 | { |
| 48 | - foreach ($this->destructFiles as $filename) { |
|
| 48 | + foreach ($this->destructFiles as $filename){ |
|
| 49 | 49 | $this->delete($filename); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -60,30 +60,30 @@ discard block |
||
| 60 | 60 | int $mode = null, |
| 61 | 61 | bool $recursivePermissions = true |
| 62 | 62 | ): bool { |
| 63 | - if (empty($mode)) { |
|
| 63 | + if (empty($mode)){ |
|
| 64 | 64 | $mode = self::DEFAULT_FILE_MODE; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | //Directories always executable |
| 68 | 68 | $mode = $mode | 0111; |
| 69 | - if (is_dir($directory)) { |
|
| 69 | + if (is_dir($directory)){ |
|
| 70 | 70 | //Exists :( |
| 71 | 71 | return $this->setPermissions($directory, $mode); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if (!$recursivePermissions) { |
|
| 74 | + if (!$recursivePermissions){ |
|
| 75 | 75 | return mkdir($directory, $mode, true); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $directoryChain = [basename($directory)]; |
| 79 | 79 | |
| 80 | 80 | $baseDirectory = $directory; |
| 81 | - while (!is_dir($baseDirectory = dirname($baseDirectory))) { |
|
| 81 | + while (!is_dir($baseDirectory = dirname($baseDirectory))){ |
|
| 82 | 82 | $directoryChain[] = basename($baseDirectory); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - foreach (array_reverse($directoryChain) as $directory) { |
|
| 86 | - if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) { |
|
| 85 | + foreach (array_reverse($directoryChain) as $directory){ |
|
| 86 | + if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")){ |
|
| 87 | 87 | return false; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function read(string $filename): string |
| 100 | 100 | { |
| 101 | - if (!$this->exists($filename)) { |
|
| 101 | + if (!$this->exists($filename)){ |
|
| 102 | 102 | throw new FileNotFoundException($filename); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | ): bool { |
| 120 | 120 | $mode = $mode ?? self::DEFAULT_FILE_MODE; |
| 121 | 121 | |
| 122 | - try { |
|
| 123 | - if ($ensureDirectory) { |
|
| 122 | + try{ |
|
| 123 | + if ($ensureDirectory){ |
|
| 124 | 124 | $this->ensureDirectory(dirname($filename), $mode); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ($this->exists($filename)) { |
|
| 127 | + if ($this->exists($filename)){ |
|
| 128 | 128 | //Forcing mode for existed file |
| 129 | 129 | $this->setPermissions($filename, $mode); |
| 130 | 130 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - if ($result !== false) { |
|
| 138 | + if ($result !== false){ |
|
| 139 | 139 | //Forcing mode after file creation |
| 140 | 140 | $this->setPermissions($filename, $mode); |
| 141 | 141 | } |
| 142 | - } catch (\Exception $e) { |
|
| 142 | + }catch (\Exception $e){ |
|
| 143 | 143 | throw new WriteErrorException($e->getMessage(), $e->getCode(), $e); |
| 144 | 144 | } |
| 145 | 145 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function delete(string $filename) |
| 165 | 165 | { |
| 166 | - if ($this->exists($filename)) { |
|
| 166 | + if ($this->exists($filename)){ |
|
| 167 | 167 | $result = unlink($filename); |
| 168 | 168 | |
| 169 | 169 | //Wiping out changes in local file cache |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function deleteDirectory(string $directory, bool $contentOnly = false): void |
| 189 | 189 | { |
| 190 | - if (!$this->isDirectory($directory)) { |
|
| 190 | + if (!$this->isDirectory($directory)){ |
|
| 191 | 191 | throw new FilesException("Undefined or invalid directory {$directory}"); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -196,15 +196,15 @@ discard block |
||
| 196 | 196 | \RecursiveIteratorIterator::CHILD_FIRST |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - foreach ($files as $file) { |
|
| 200 | - if ($file->isDir()) { |
|
| 199 | + foreach ($files as $file){ |
|
| 200 | + if ($file->isDir()){ |
|
| 201 | 201 | rmdir($file->getRealPath()); |
| 202 | - } else { |
|
| 202 | + }else{ |
|
| 203 | 203 | $this->delete($file->getRealPath()); |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if (!$contentOnly) { |
|
| 207 | + if (!$contentOnly){ |
|
| 208 | 208 | rmdir($directory); |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function move(string $filename, string $destination): bool |
| 216 | 216 | { |
| 217 | - if (!$this->exists($filename)) { |
|
| 217 | + if (!$this->exists($filename)){ |
|
| 218 | 218 | throw new FileNotFoundException($filename); |
| 219 | 219 | } |
| 220 | 220 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function copy(string $filename, string $destination): bool |
| 228 | 228 | { |
| 229 | - if (!$this->exists($filename)) { |
|
| 229 | + if (!$this->exists($filename)){ |
|
| 230 | 230 | throw new FileNotFoundException($filename); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | public function touch(string $filename, int $mode = null): bool |
| 240 | 240 | { |
| 241 | - if (!touch($filename)) { |
|
| 241 | + if (!touch($filename)){ |
|
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function size(string $filename): int |
| 260 | 260 | { |
| 261 | - if (!$this->exists($filename)) { |
|
| 261 | + if (!$this->exists($filename)){ |
|
| 262 | 262 | throw new FileNotFoundException($filename); |
| 263 | 263 | } |
| 264 | 264 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | public function md5(string $filename): string |
| 280 | 280 | { |
| 281 | - if (!$this->exists($filename)) { |
|
| 281 | + if (!$this->exists($filename)){ |
|
| 282 | 282 | throw new FileNotFoundException($filename); |
| 283 | 283 | } |
| 284 | 284 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | public function time(string $filename): int |
| 292 | 292 | { |
| 293 | - if (!$this->exists($filename)) { |
|
| 293 | + if (!$this->exists($filename)){ |
|
| 294 | 294 | throw new FileNotFoundException($filename); |
| 295 | 295 | } |
| 296 | 296 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function getPermissions(string $filename): int |
| 320 | 320 | { |
| 321 | - if (!$this->exists($filename)) { |
|
| 321 | + if (!$this->exists($filename)){ |
|
| 322 | 322 | throw new FileNotFoundException($filename); |
| 323 | 323 | } |
| 324 | 324 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public function setPermissions(string $filename, int $mode) |
| 332 | 332 | { |
| 333 | - if (is_dir($filename)) { |
|
| 333 | + if (is_dir($filename)){ |
|
| 334 | 334 | //Directories must always be executable (i.e. 664 for dir => 775) |
| 335 | 335 | $mode |= 0111; |
| 336 | 336 | } |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | public function getFiles(string $location, string $pattern = null): array |
| 345 | 345 | { |
| 346 | 346 | $result = []; |
| 347 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
| 348 | - if ($this->isDirectory($filename->getPathname())) { |
|
| 349 | - $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
| 347 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
| 348 | + if ($this->isDirectory($filename->getPathname())){ |
|
| 349 | + $result = array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
| 350 | 350 | |
| 351 | 351 | continue; |
| 352 | 352 | } |
@@ -362,13 +362,13 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | public function tempFilename(string $extension = '', string $location = null): string |
| 364 | 364 | { |
| 365 | - if (empty($location)) { |
|
| 365 | + if (empty($location)){ |
|
| 366 | 366 | $location = sys_get_temp_dir(); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | $filename = tempnam($location, 'spiral'); |
| 370 | 370 | |
| 371 | - if (!empty($extension)) { |
|
| 371 | + if (!empty($extension)){ |
|
| 372 | 372 | [$old, $filename] = [$filename, "{$filename}.{$extension}"]; |
| 373 | 373 | rename($old, $filename); |
| 374 | 374 | $this->destructFiles[] = $filename; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | $path = str_replace(['//', '\\'], '/', $path); |
| 386 | 386 | |
| 387 | 387 | //Potentially open links and ../ type directories? |
| 388 | - return rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
| 388 | + return rtrim($path, '/').($asDirectory ? '/' : ''); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -402,21 +402,21 @@ discard block |
||
| 402 | 402 | $path = explode('/', $path); |
| 403 | 403 | $relative = $path; |
| 404 | 404 | |
| 405 | - foreach ($from as $depth => $dir) { |
|
| 405 | + foreach ($from as $depth => $dir){ |
|
| 406 | 406 | //Find first non-matching dir |
| 407 | - if ($dir === $path[$depth]) { |
|
| 407 | + if ($dir === $path[$depth]){ |
|
| 408 | 408 | //Ignore this directory |
| 409 | 409 | array_shift($relative); |
| 410 | - } else { |
|
| 410 | + }else{ |
|
| 411 | 411 | //Get number of remaining dirs to $from |
| 412 | 412 | $remaining = count($from) - $depth; |
| 413 | - if ($remaining > 1) { |
|
| 413 | + if ($remaining > 1){ |
|
| 414 | 414 | //Add traversals up to first matching directory |
| 415 | 415 | $padLength = (count($relative) + $remaining - 1) * -1; |
| 416 | 416 | $relative = array_pad($relative, $padLength, '..'); |
| 417 | 417 | break; |
| 418 | 418 | } |
| 419 | - $relative[0] = './' . $relative[0]; |
|
| 419 | + $relative[0] = './'.$relative[0]; |
|
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | private function filesIterator(string $location, string $pattern = null): \GlobIterator |
| 433 | 433 | { |
| 434 | 434 | $pattern = $pattern ?? '*'; |
| 435 | - $regexp = rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 435 | + $regexp = rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 436 | 436 | |
| 437 | 437 | return new \GlobIterator($regexp); |
| 438 | 438 | } |