@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * @var string |
22 | 22 | */ |
23 | 23 | private const ERROR_NOT_AVAILABLE = |
24 | - 'The "aws/aws-sdk-php" package is supplied with the Guzzle PSR-7 ' . |
|
25 | - 'implementation, but it is not available. Please install the ' . |
|
24 | + 'The "aws/aws-sdk-php" package is supplied with the Guzzle PSR-7 '. |
|
25 | + 'implementation, but it is not available. Please install the '. |
|
26 | 26 | '"aws/aws-sdk-php" package or use any other implementation of PSR-17 factories.' |
27 | 27 | ; |
28 | 28 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | private function assertAvailable(): void |
43 | 43 | { |
44 | - if (\class_exists(Uri::class)) { |
|
44 | + if (\class_exists(Uri::class)){ |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 |
@@ -41,7 +41,8 @@ |
||
41 | 41 | |
42 | 42 | private function assertAvailable(): void |
43 | 43 | { |
44 | - if (\class_exists(Uri::class)) { |
|
44 | + if (\class_exists(Uri::class)) |
|
45 | + { |
|
45 | 46 | return; |
46 | 47 | } |
47 | 48 |
@@ -17,6 +17,6 @@ |
||
17 | 17 | { |
18 | 18 | // Do nothing |
19 | 19 | |
20 | - return (string) Uuid::uuid4(); |
|
20 | + return (string)Uuid::uuid4(); |
|
21 | 21 | } |
22 | 22 | } |
@@ -38,8 +38,10 @@ |
||
38 | 38 | public function locateCommands(): array |
39 | 39 | { |
40 | 40 | $commands = []; |
41 | - foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) { |
|
42 | - if ($class->isAbstract()) { |
|
41 | + foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) |
|
42 | + { |
|
43 | + if ($class->isAbstract()) |
|
44 | + { |
|
43 | 45 | continue; |
44 | 46 | } |
45 | 47 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | private readonly ScopedClassesInterface $classes, |
18 | 18 | ContainerInterface $container, |
19 | 19 | array $interceptors = [], |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | $this->container = $container; |
22 | 22 | $this->interceptors = $interceptors; |
23 | 23 | } |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | public function locateCommands(): array |
26 | 26 | { |
27 | 27 | $commands = []; |
28 | - foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) { |
|
29 | - if ($class->isAbstract()) { |
|
28 | + foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class){ |
|
29 | + if ($class->isAbstract()){ |
|
30 | 30 | continue; |
31 | 31 | } |
32 | 32 |
@@ -47,7 +47,7 @@ |
||
47 | 47 | 'directories' => [], |
48 | 48 | 'scopes' => [ |
49 | 49 | 'prototypes' => [ |
50 | - 'directories' => [__DIR__ . '/Fixtures'] |
|
50 | + 'directories' => [__DIR__.'/Fixtures'] |
|
51 | 51 | ] |
52 | 52 | ] |
53 | 53 | ]))); |
@@ -23,7 +23,7 @@ |
||
23 | 23 | /** |
24 | 24 | * Default file mode for this manager. |
25 | 25 | */ |
26 | - public const DEFAULT_FILE_MODE = self::READONLY; |
|
26 | + public const DEFAULT_FILE_MODE = self::readonly; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Files to be removed when component destructed. |
@@ -39,30 +39,30 @@ discard block |
||
39 | 39 | ?int $mode = null, |
40 | 40 | bool $recursivePermissions = true, |
41 | 41 | ): bool { |
42 | - if (empty($mode)) { |
|
42 | + if (empty($mode)){ |
|
43 | 43 | $mode = self::DEFAULT_FILE_MODE; |
44 | 44 | } |
45 | 45 | |
46 | 46 | //Directories always executable |
47 | 47 | $mode |= 0o111; |
48 | - if (\is_dir($directory)) { |
|
48 | + if (\is_dir($directory)){ |
|
49 | 49 | //Exists :( |
50 | 50 | return $this->setPermissions($directory, $mode); |
51 | 51 | } |
52 | 52 | |
53 | - if (!$recursivePermissions) { |
|
53 | + if (!$recursivePermissions){ |
|
54 | 54 | return \mkdir($directory, $mode, true); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $directoryChain = [\basename($directory)]; |
58 | 58 | |
59 | 59 | $baseDirectory = $directory; |
60 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
60 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))){ |
|
61 | 61 | $directoryChain[] = \basename($baseDirectory); |
62 | 62 | } |
63 | 63 | |
64 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
65 | - if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
64 | + foreach (\array_reverse($directoryChain) as $dir){ |
|
65 | + if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))){ |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function read(string $filename): string |
76 | 76 | { |
77 | - if (!$this->exists($filename)) { |
|
77 | + if (!$this->exists($filename)){ |
|
78 | 78 | throw new FileNotFoundException($filename); |
79 | 79 | } |
80 | 80 | |
@@ -96,12 +96,12 @@ discard block |
||
96 | 96 | ): bool { |
97 | 97 | $mode ??= self::DEFAULT_FILE_MODE; |
98 | 98 | |
99 | - try { |
|
100 | - if ($ensureDirectory) { |
|
99 | + try{ |
|
100 | + if ($ensureDirectory){ |
|
101 | 101 | $this->ensureDirectory(\dirname($filename), $mode); |
102 | 102 | } |
103 | 103 | |
104 | - if ($this->exists($filename)) { |
|
104 | + if ($this->exists($filename)){ |
|
105 | 105 | //Forcing mode for existed file |
106 | 106 | $this->setPermissions($filename, $mode); |
107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX, |
113 | 113 | ); |
114 | 114 | |
115 | - if ($result !== false) { |
|
115 | + if ($result !== false){ |
|
116 | 116 | //Forcing mode after file creation |
117 | 117 | $this->setPermissions($filename, $mode); |
118 | 118 | } |
119 | - } catch (\Exception $e) { |
|
120 | - throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
|
119 | + }catch (\Exception $e){ |
|
120 | + throw new WriteErrorException($e->getMessage(), (int)$e->getCode(), $e); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return $result !== false; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | public function delete(string $filename): bool |
136 | 136 | { |
137 | - if ($this->exists($filename)) { |
|
137 | + if ($this->exists($filename)){ |
|
138 | 138 | $result = \unlink($filename); |
139 | 139 | |
140 | 140 | //Wiping out changes in local file cache |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
155 | 155 | { |
156 | - if (!$this->isDirectory($directory)) { |
|
156 | + if (!$this->isDirectory($directory)){ |
|
157 | 157 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
158 | 158 | } |
159 | 159 | |
@@ -162,15 +162,15 @@ discard block |
||
162 | 162 | \RecursiveIteratorIterator::CHILD_FIRST, |
163 | 163 | ); |
164 | 164 | |
165 | - foreach ($files as $file) { |
|
166 | - if ($file->isDir()) { |
|
165 | + foreach ($files as $file){ |
|
166 | + if ($file->isDir()){ |
|
167 | 167 | \rmdir($file->getRealPath()); |
168 | - } else { |
|
168 | + }else{ |
|
169 | 169 | $this->delete($file->getRealPath()); |
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - if (!$contentOnly) { |
|
173 | + if (!$contentOnly){ |
|
174 | 174 | return \rmdir($directory); |
175 | 175 | } |
176 | 176 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | public function move(string $filename, string $destination): bool |
181 | 181 | { |
182 | - if (!$this->exists($filename)) { |
|
182 | + if (!$this->exists($filename)){ |
|
183 | 183 | throw new FileNotFoundException($filename); |
184 | 184 | } |
185 | 185 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | public function copy(string $filename, string $destination): bool |
190 | 190 | { |
191 | - if (!$this->exists($filename)) { |
|
191 | + if (!$this->exists($filename)){ |
|
192 | 192 | throw new FileNotFoundException($filename); |
193 | 193 | } |
194 | 194 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | public function touch(string $filename, ?int $mode = null): bool |
199 | 199 | { |
200 | - if (!\touch($filename)) { |
|
200 | + if (!\touch($filename)){ |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | { |
214 | 214 | $this->exists($filename) or throw new FileNotFoundException($filename); |
215 | 215 | |
216 | - return (int) \filesize($filename); |
|
216 | + return (int)\filesize($filename); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | public function extension(string $filename): string |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | public function md5(string $filename): string |
225 | 225 | { |
226 | - if (!$this->exists($filename)) { |
|
226 | + if (!$this->exists($filename)){ |
|
227 | 227 | throw new FileNotFoundException($filename); |
228 | 228 | } |
229 | 229 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | public function time(string $filename): int |
239 | 239 | { |
240 | - if (!$this->exists($filename)) { |
|
240 | + if (!$this->exists($filename)){ |
|
241 | 241 | throw new FileNotFoundException($filename); |
242 | 242 | } |
243 | 243 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | |
269 | 269 | public function setPermissions(string $filename, int $mode): bool |
270 | 270 | { |
271 | - if (\is_dir($filename)) { |
|
271 | + if (\is_dir($filename)){ |
|
272 | 272 | //Directories must always be executable (i.e. 664 for dir => 775) |
273 | 273 | $mode |= 0111; |
274 | 274 | } |
@@ -279,14 +279,14 @@ discard block |
||
279 | 279 | public function getFiles(string $location, ?string $pattern = null): array |
280 | 280 | { |
281 | 281 | $result = []; |
282 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
283 | - if ($this->isDirectory($filename->getPathname())) { |
|
284 | - $result = \array_merge($result, $this->getFiles(((string) $filename) . DIRECTORY_SEPARATOR)); |
|
282 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
283 | + if ($this->isDirectory($filename->getPathname())){ |
|
284 | + $result = \array_merge($result, $this->getFiles(((string)$filename).DIRECTORY_SEPARATOR)); |
|
285 | 285 | |
286 | 286 | continue; |
287 | 287 | } |
288 | 288 | |
289 | - $result[] = $this->normalizePath((string) $filename); |
|
289 | + $result[] = $this->normalizePath((string)$filename); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | return $result; |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | |
295 | 295 | public function tempFilename(string $extension = '', ?string $location = null): string |
296 | 296 | { |
297 | - if (empty($location)) { |
|
297 | + if (empty($location)){ |
|
298 | 298 | $location = \sys_get_temp_dir(); |
299 | 299 | } |
300 | 300 | |
301 | 301 | $filename = \tempnam($location, 'spiral'); |
302 | 302 | $filename === false and throw new FilesException('Unable to create temporary file.'); |
303 | 303 | |
304 | - if (!empty($extension)) { |
|
304 | + if (!empty($extension)){ |
|
305 | 305 | $old = $filename; |
306 | 306 | $filename = \sprintf('%s.%s', $filename, $extension); |
307 | 307 | \rename($old, $filename); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | public function normalizePath(string $path, bool $asDirectory = false): string |
315 | 315 | { |
316 | 316 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
317 | - if ($isUnc) { |
|
317 | + if ($isUnc){ |
|
318 | 318 | $leadingSlashes = \substr($path, 0, 2); |
319 | 319 | $path = \substr($path, 2); |
320 | 320 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | $path = \str_replace(['//', '\\'], '/', $path); |
323 | 323 | |
324 | 324 | //Potentially open links and ../ type directories? |
325 | - return ($isUnc ? $leadingSlashes : '') . \rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
325 | + return ($isUnc ? $leadingSlashes : '').\rtrim($path, '/').($asDirectory ? '/' : ''); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -337,21 +337,21 @@ discard block |
||
337 | 337 | $path = \explode('/', $path); |
338 | 338 | $relative = $path; |
339 | 339 | |
340 | - foreach ($from as $depth => $dir) { |
|
340 | + foreach ($from as $depth => $dir){ |
|
341 | 341 | //Find first non-matching dir |
342 | - if ($dir === $path[$depth]) { |
|
342 | + if ($dir === $path[$depth]){ |
|
343 | 343 | //Ignore this directory |
344 | 344 | \array_shift($relative); |
345 | - } else { |
|
345 | + }else{ |
|
346 | 346 | //Get number of remaining dirs to $from |
347 | 347 | $remaining = \count($from) - $depth; |
348 | - if ($remaining > 1) { |
|
348 | + if ($remaining > 1){ |
|
349 | 349 | //Add traversals up to first matching directory |
350 | 350 | $padLength = (\count($relative) + $remaining - 1) * -1; |
351 | 351 | $relative = \array_pad($relative, $padLength, '..'); |
352 | 352 | break; |
353 | 353 | } |
354 | - $relative[0] = './' . $relative[0]; |
|
354 | + $relative[0] = './'.$relative[0]; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | */ |
364 | 364 | public function __destruct() |
365 | 365 | { |
366 | - foreach ($this->destructFiles as $filename) { |
|
366 | + foreach ($this->destructFiles as $filename){ |
|
367 | 367 | $this->delete($filename); |
368 | 368 | } |
369 | 369 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | private function filesIterator(string $location, ?string $pattern = null): \GlobIterator |
372 | 372 | { |
373 | 373 | $pattern ??= '*'; |
374 | - $regexp = \rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \ltrim($pattern, DIRECTORY_SEPARATOR); |
|
374 | + $regexp = \rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.\ltrim($pattern, DIRECTORY_SEPARATOR); |
|
375 | 375 | |
376 | 376 | return new \GlobIterator($regexp); |
377 | 377 | } |
@@ -39,30 +39,36 @@ discard block |
||
39 | 39 | ?int $mode = null, |
40 | 40 | bool $recursivePermissions = true, |
41 | 41 | ): bool { |
42 | - if (empty($mode)) { |
|
42 | + if (empty($mode)) |
|
43 | + { |
|
43 | 44 | $mode = self::DEFAULT_FILE_MODE; |
44 | 45 | } |
45 | 46 | |
46 | 47 | //Directories always executable |
47 | 48 | $mode |= 0o111; |
48 | - if (\is_dir($directory)) { |
|
49 | + if (\is_dir($directory)) |
|
50 | + { |
|
49 | 51 | //Exists :( |
50 | 52 | return $this->setPermissions($directory, $mode); |
51 | 53 | } |
52 | 54 | |
53 | - if (!$recursivePermissions) { |
|
55 | + if (!$recursivePermissions) |
|
56 | + { |
|
54 | 57 | return \mkdir($directory, $mode, true); |
55 | 58 | } |
56 | 59 | |
57 | 60 | $directoryChain = [\basename($directory)]; |
58 | 61 | |
59 | 62 | $baseDirectory = $directory; |
60 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
63 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))) |
|
64 | + { |
|
61 | 65 | $directoryChain[] = \basename($baseDirectory); |
62 | 66 | } |
63 | 67 | |
64 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
65 | - if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
68 | + foreach (\array_reverse($directoryChain) as $dir) |
|
69 | + { |
|
70 | + if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) |
|
71 | + { |
|
66 | 72 | return false; |
67 | 73 | } |
68 | 74 | |
@@ -74,7 +80,8 @@ discard block |
||
74 | 80 | |
75 | 81 | public function read(string $filename): string |
76 | 82 | { |
77 | - if (!$this->exists($filename)) { |
|
83 | + if (!$this->exists($filename)) |
|
84 | + { |
|
78 | 85 | throw new FileNotFoundException($filename); |
79 | 86 | } |
80 | 87 | |
@@ -96,12 +103,15 @@ discard block |
||
96 | 103 | ): bool { |
97 | 104 | $mode ??= self::DEFAULT_FILE_MODE; |
98 | 105 | |
99 | - try { |
|
100 | - if ($ensureDirectory) { |
|
106 | + try |
|
107 | + { |
|
108 | + if ($ensureDirectory) |
|
109 | + { |
|
101 | 110 | $this->ensureDirectory(\dirname($filename), $mode); |
102 | 111 | } |
103 | 112 | |
104 | - if ($this->exists($filename)) { |
|
113 | + if ($this->exists($filename)) |
|
114 | + { |
|
105 | 115 | //Forcing mode for existed file |
106 | 116 | $this->setPermissions($filename, $mode); |
107 | 117 | } |
@@ -112,11 +122,14 @@ discard block |
||
112 | 122 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX, |
113 | 123 | ); |
114 | 124 | |
115 | - if ($result !== false) { |
|
125 | + if ($result !== false) |
|
126 | + { |
|
116 | 127 | //Forcing mode after file creation |
117 | 128 | $this->setPermissions($filename, $mode); |
118 | 129 | } |
119 | - } catch (\Exception $e) { |
|
130 | + } |
|
131 | + catch (\Exception $e) |
|
132 | + { |
|
120 | 133 | throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
121 | 134 | } |
122 | 135 | |
@@ -134,7 +147,8 @@ discard block |
||
134 | 147 | |
135 | 148 | public function delete(string $filename): bool |
136 | 149 | { |
137 | - if ($this->exists($filename)) { |
|
150 | + if ($this->exists($filename)) |
|
151 | + { |
|
138 | 152 | $result = \unlink($filename); |
139 | 153 | |
140 | 154 | //Wiping out changes in local file cache |
@@ -153,7 +167,8 @@ discard block |
||
153 | 167 | */ |
154 | 168 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
155 | 169 | { |
156 | - if (!$this->isDirectory($directory)) { |
|
170 | + if (!$this->isDirectory($directory)) |
|
171 | + { |
|
157 | 172 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
158 | 173 | } |
159 | 174 | |
@@ -162,15 +177,20 @@ discard block |
||
162 | 177 | \RecursiveIteratorIterator::CHILD_FIRST, |
163 | 178 | ); |
164 | 179 | |
165 | - foreach ($files as $file) { |
|
166 | - if ($file->isDir()) { |
|
180 | + foreach ($files as $file) |
|
181 | + { |
|
182 | + if ($file->isDir()) |
|
183 | + { |
|
167 | 184 | \rmdir($file->getRealPath()); |
168 | - } else { |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
169 | 188 | $this->delete($file->getRealPath()); |
170 | 189 | } |
171 | 190 | } |
172 | 191 | |
173 | - if (!$contentOnly) { |
|
192 | + if (!$contentOnly) |
|
193 | + { |
|
174 | 194 | return \rmdir($directory); |
175 | 195 | } |
176 | 196 | |
@@ -179,7 +199,8 @@ discard block |
||
179 | 199 | |
180 | 200 | public function move(string $filename, string $destination): bool |
181 | 201 | { |
182 | - if (!$this->exists($filename)) { |
|
202 | + if (!$this->exists($filename)) |
|
203 | + { |
|
183 | 204 | throw new FileNotFoundException($filename); |
184 | 205 | } |
185 | 206 | |
@@ -188,7 +209,8 @@ discard block |
||
188 | 209 | |
189 | 210 | public function copy(string $filename, string $destination): bool |
190 | 211 | { |
191 | - if (!$this->exists($filename)) { |
|
212 | + if (!$this->exists($filename)) |
|
213 | + { |
|
192 | 214 | throw new FileNotFoundException($filename); |
193 | 215 | } |
194 | 216 | |
@@ -197,7 +219,8 @@ discard block |
||
197 | 219 | |
198 | 220 | public function touch(string $filename, ?int $mode = null): bool |
199 | 221 | { |
200 | - if (!\touch($filename)) { |
|
222 | + if (!\touch($filename)) |
|
223 | + { |
|
201 | 224 | return false; |
202 | 225 | } |
203 | 226 | |
@@ -223,7 +246,8 @@ discard block |
||
223 | 246 | |
224 | 247 | public function md5(string $filename): string |
225 | 248 | { |
226 | - if (!$this->exists($filename)) { |
|
249 | + if (!$this->exists($filename)) |
|
250 | + { |
|
227 | 251 | throw new FileNotFoundException($filename); |
228 | 252 | } |
229 | 253 | |
@@ -237,7 +261,8 @@ discard block |
||
237 | 261 | |
238 | 262 | public function time(string $filename): int |
239 | 263 | { |
240 | - if (!$this->exists($filename)) { |
|
264 | + if (!$this->exists($filename)) |
|
265 | + { |
|
241 | 266 | throw new FileNotFoundException($filename); |
242 | 267 | } |
243 | 268 | |
@@ -268,7 +293,8 @@ discard block |
||
268 | 293 | |
269 | 294 | public function setPermissions(string $filename, int $mode): bool |
270 | 295 | { |
271 | - if (\is_dir($filename)) { |
|
296 | + if (\is_dir($filename)) |
|
297 | + { |
|
272 | 298 | //Directories must always be executable (i.e. 664 for dir => 775) |
273 | 299 | $mode |= 0111; |
274 | 300 | } |
@@ -279,8 +305,10 @@ discard block |
||
279 | 305 | public function getFiles(string $location, ?string $pattern = null): array |
280 | 306 | { |
281 | 307 | $result = []; |
282 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
283 | - if ($this->isDirectory($filename->getPathname())) { |
|
308 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
309 | + { |
|
310 | + if ($this->isDirectory($filename->getPathname())) |
|
311 | + { |
|
284 | 312 | $result = \array_merge($result, $this->getFiles(((string) $filename) . DIRECTORY_SEPARATOR)); |
285 | 313 | |
286 | 314 | continue; |
@@ -294,14 +322,16 @@ discard block |
||
294 | 322 | |
295 | 323 | public function tempFilename(string $extension = '', ?string $location = null): string |
296 | 324 | { |
297 | - if (empty($location)) { |
|
325 | + if (empty($location)) |
|
326 | + { |
|
298 | 327 | $location = \sys_get_temp_dir(); |
299 | 328 | } |
300 | 329 | |
301 | 330 | $filename = \tempnam($location, 'spiral'); |
302 | 331 | $filename === false and throw new FilesException('Unable to create temporary file.'); |
303 | 332 | |
304 | - if (!empty($extension)) { |
|
333 | + if (!empty($extension)) |
|
334 | + { |
|
305 | 335 | $old = $filename; |
306 | 336 | $filename = \sprintf('%s.%s', $filename, $extension); |
307 | 337 | \rename($old, $filename); |
@@ -314,7 +344,8 @@ discard block |
||
314 | 344 | public function normalizePath(string $path, bool $asDirectory = false): string |
315 | 345 | { |
316 | 346 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
317 | - if ($isUnc) { |
|
347 | + if ($isUnc) |
|
348 | + { |
|
318 | 349 | $leadingSlashes = \substr($path, 0, 2); |
319 | 350 | $path = \substr($path, 2); |
320 | 351 | } |
@@ -337,15 +368,20 @@ discard block |
||
337 | 368 | $path = \explode('/', $path); |
338 | 369 | $relative = $path; |
339 | 370 | |
340 | - foreach ($from as $depth => $dir) { |
|
371 | + foreach ($from as $depth => $dir) |
|
372 | + { |
|
341 | 373 | //Find first non-matching dir |
342 | - if ($dir === $path[$depth]) { |
|
374 | + if ($dir === $path[$depth]) |
|
375 | + { |
|
343 | 376 | //Ignore this directory |
344 | 377 | \array_shift($relative); |
345 | - } else { |
|
378 | + } |
|
379 | + else |
|
380 | + { |
|
346 | 381 | //Get number of remaining dirs to $from |
347 | 382 | $remaining = \count($from) - $depth; |
348 | - if ($remaining > 1) { |
|
383 | + if ($remaining > 1) |
|
384 | + { |
|
349 | 385 | //Add traversals up to first matching directory |
350 | 386 | $padLength = (\count($relative) + $remaining - 1) * -1; |
351 | 387 | $relative = \array_pad($relative, $padLength, '..'); |
@@ -363,7 +399,8 @@ discard block |
||
363 | 399 | */ |
364 | 400 | public function __destruct() |
365 | 401 | { |
366 | - foreach ($this->destructFiles as $filename) { |
|
402 | + foreach ($this->destructFiles as $filename) |
|
403 | + { |
|
367 | 404 | $this->delete($filename); |
368 | 405 | } |
369 | 406 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public const RUNTIME = 0666; |
24 | 24 | |
25 | 25 | //Only owner can write |
26 | - public const READONLY = 0644; |
|
26 | + public const readonly = 0644; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Few size constants for better size manipulations. |
@@ -58,10 +58,10 @@ |
||
58 | 58 | */ |
59 | 59 | public function getChunkSize(): ?int |
60 | 60 | { |
61 | - if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) { |
|
61 | + if (\is_null($this->config['chunkSize']) || (int)$this->config['chunkSize'] < 0){ |
|
62 | 62 | return null; |
63 | 63 | } |
64 | 64 | |
65 | - return (int) $this->config['chunkSize']; |
|
65 | + return (int)$this->config['chunkSize']; |
|
66 | 66 | } |
67 | 67 | } |
@@ -58,7 +58,8 @@ |
||
58 | 58 | */ |
59 | 59 | public function getChunkSize(): ?int |
60 | 60 | { |
61 | - if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) { |
|
61 | + if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) |
|
62 | + { |
|
62 | 63 | return null; |
63 | 64 | } |
64 | 65 |
@@ -43,15 +43,15 @@ |
||
43 | 43 | */ |
44 | 44 | public function getHandler(): ?Autowire |
45 | 45 | { |
46 | - if (empty($this->config['handler'])) { |
|
46 | + if (empty($this->config['handler'])){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | |
50 | - if ($this->config['handler'] instanceof Autowire) { |
|
50 | + if ($this->config['handler'] instanceof Autowire){ |
|
51 | 51 | return $this->config['handler']; |
52 | 52 | } |
53 | 53 | |
54 | - if (\class_exists($this->config['handler'])) { |
|
54 | + if (\class_exists($this->config['handler'])){ |
|
55 | 55 | return new Autowire($this->config['handler']); |
56 | 56 | } |
57 | 57 |
@@ -43,15 +43,18 @@ |
||
43 | 43 | */ |
44 | 44 | public function getHandler(): ?Autowire |
45 | 45 | { |
46 | - if (empty($this->config['handler'])) { |
|
46 | + if (empty($this->config['handler'])) |
|
47 | + { |
|
47 | 48 | return null; |
48 | 49 | } |
49 | 50 | |
50 | - if ($this->config['handler'] instanceof Autowire) { |
|
51 | + if ($this->config['handler'] instanceof Autowire) |
|
52 | + { |
|
51 | 53 | return $this->config['handler']; |
52 | 54 | } |
53 | 55 | |
54 | - if (\class_exists($this->config['handler'])) { |
|
56 | + if (\class_exists($this->config['handler'])) |
|
57 | + { |
|
55 | 58 | return new Autowire($this->config['handler']); |
56 | 59 | } |
57 | 60 |
@@ -10,33 +10,33 @@ |
||
10 | 10 | |
11 | 11 | final class PhpSerializer implements SerializerInterface |
12 | 12 | { |
13 | - public function serialize(mixed $payload): string|\Stringable |
|
13 | + public function serialize(mixed $payload): string | \Stringable |
|
14 | 14 | { |
15 | 15 | return \serialize($payload); |
16 | 16 | } |
17 | 17 | |
18 | - public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
|
18 | + public function unserialize(\Stringable | string $payload, object | string | null $type = null): mixed |
|
19 | 19 | { |
20 | - if (\is_object($type)) { |
|
20 | + if (\is_object($type)){ |
|
21 | 21 | $type = $type::class; |
22 | 22 | } |
23 | 23 | |
24 | - if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) { |
|
24 | + if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)){ |
|
25 | 25 | throw new InvalidArgumentException(\sprintf('Class or interface `%s` doesn\'t exist.', $type)); |
26 | 26 | } |
27 | 27 | |
28 | 28 | return $this->runUnserialize($payload, $type); |
29 | 29 | } |
30 | 30 | |
31 | - private function runUnserialize(\Stringable|string $payload, ?string $type = null): mixed |
|
31 | + private function runUnserialize(\Stringable | string $payload, ?string $type = null): mixed |
|
32 | 32 | { |
33 | - $result = \unserialize((string) $payload, $type ? [] : ['allowed_classes' => false]); |
|
33 | + $result = \unserialize((string)$payload, $type ? [] : ['allowed_classes' => false]); |
|
34 | 34 | |
35 | - if ($result === false) { |
|
35 | + if ($result === false){ |
|
36 | 36 | throw new UnserializeException('Failed to unserialize data.'); |
37 | 37 | } |
38 | 38 | |
39 | - if ($type !== null && !$result instanceof $type) { |
|
39 | + if ($type !== null && !$result instanceof $type){ |
|
40 | 40 | throw new InvalidArgumentException(\sprintf( |
41 | 41 | 'Data received after unserializing must be of type: `%s`, received `%s`', |
42 | 42 | $type, |
@@ -17,11 +17,13 @@ discard block |
||
17 | 17 | |
18 | 18 | public function unserialize(\Stringable|string $payload, object|string|null $type = null): mixed |
19 | 19 | { |
20 | - if (\is_object($type)) { |
|
20 | + if (\is_object($type)) |
|
21 | + { |
|
21 | 22 | $type = $type::class; |
22 | 23 | } |
23 | 24 | |
24 | - if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) { |
|
25 | + if (\is_string($type) && !\class_exists($type) && !\interface_exists($type)) |
|
26 | + { |
|
25 | 27 | throw new InvalidArgumentException(\sprintf('Class or interface `%s` doesn\'t exist.', $type)); |
26 | 28 | } |
27 | 29 | |
@@ -32,11 +34,13 @@ discard block |
||
32 | 34 | { |
33 | 35 | $result = \unserialize((string) $payload, $type ? [] : ['allowed_classes' => false]); |
34 | 36 | |
35 | - if ($result === false) { |
|
37 | + if ($result === false) |
|
38 | + { |
|
36 | 39 | throw new UnserializeException('Failed to unserialize data.'); |
37 | 40 | } |
38 | 41 | |
39 | - if ($type !== null && !$result instanceof $type) { |
|
42 | + if ($type !== null && !$result instanceof $type) |
|
43 | + { |
|
40 | 44 | throw new InvalidArgumentException(\sprintf( |
41 | 45 | 'Data received after unserializing must be of type: `%s`, received `%s`', |
42 | 46 | $type, |