@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly string $header = 'X-Auth-Token', |
| 18 | 18 | private readonly string $valueFormat = '%s' |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function fetchToken(Request $request): ?string |
| 23 | 23 | { |
| 24 | - if ($request->hasHeader($this->header)) { |
|
| 24 | + if ($request->hasHeader($this->header)){ |
|
| 25 | 25 | return $this->extractToken($request); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | string $tokenID, |
| 35 | 35 | ?\DateTimeInterface $expiresAt = null |
| 36 | 36 | ): Response { |
| 37 | - if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) { |
|
| 37 | + if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID){ |
|
| 38 | 38 | return $response; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $headerLine = $request->getHeaderLine($this->header); |
| 52 | 52 | |
| 53 | - if ($this->valueFormat !== '%s') { |
|
| 53 | + if ($this->valueFormat !== '%s'){ |
|
| 54 | 54 | [$token] = sscanf($headerLine, $this->valueFormat); |
| 55 | 55 | |
| 56 | - return $token !== null ? (string) $token : null; |
|
| 56 | + return $token !== null ? (string)$token : null; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | return $headerLine; |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function fetchToken(Request $request): ?string |
| 23 | 23 | { |
| 24 | - if ($request->hasHeader($this->header)) { |
|
| 24 | + if ($request->hasHeader($this->header)) |
|
| 25 | + { |
|
| 25 | 26 | return $this->extractToken($request); |
| 26 | 27 | } |
| 27 | 28 | |
@@ -34,7 +35,8 @@ discard block |
||
| 34 | 35 | string $tokenID, |
| 35 | 36 | ?\DateTimeInterface $expiresAt = null |
| 36 | 37 | ): Response { |
| 37 | - if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) { |
|
| 38 | + if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) |
|
| 39 | + { |
|
| 38 | 40 | return $response; |
| 39 | 41 | } |
| 40 | 42 | |
@@ -50,7 +52,8 @@ discard block |
||
| 50 | 52 | { |
| 51 | 53 | $headerLine = $request->getHeaderLine($this->header); |
| 52 | 54 | |
| 53 | - if ($this->valueFormat !== '%s') { |
|
| 55 | + if ($this->valueFormat !== '%s') |
|
| 56 | + { |
|
| 54 | 57 | [$token] = sscanf($headerLine, $this->valueFormat); |
| 55 | 58 | |
| 56 | 59 | return $token !== null ? (string) $token : null; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __destruct() |
| 38 | 38 | { |
| 39 | - foreach ($this->destructFiles as $filename) { |
|
| 39 | + foreach ($this->destructFiles as $filename){ |
|
| 40 | 40 | $this->delete($filename); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -49,30 +49,30 @@ discard block |
||
| 49 | 49 | ?int $mode = null, |
| 50 | 50 | bool $recursivePermissions = true |
| 51 | 51 | ): bool { |
| 52 | - if (empty($mode)) { |
|
| 52 | + if (empty($mode)){ |
|
| 53 | 53 | $mode = self::DEFAULT_FILE_MODE; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | //Directories always executable |
| 57 | 57 | $mode |= 0o111; |
| 58 | - if (\is_dir($directory)) { |
|
| 58 | + if (\is_dir($directory)){ |
|
| 59 | 59 | //Exists :( |
| 60 | 60 | return $this->setPermissions($directory, $mode); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (!$recursivePermissions) { |
|
| 63 | + if (!$recursivePermissions){ |
|
| 64 | 64 | return \mkdir($directory, $mode, true); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $directoryChain = [\basename($directory)]; |
| 68 | 68 | |
| 69 | 69 | $baseDirectory = $directory; |
| 70 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
| 70 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))){ |
|
| 71 | 71 | $directoryChain[] = \basename($baseDirectory); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
| 75 | - if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
| 74 | + foreach (\array_reverse($directoryChain) as $dir){ |
|
| 75 | + if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))){ |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | public function read(string $filename): string |
| 86 | 86 | { |
| 87 | - if (!$this->exists($filename)) { |
|
| 87 | + if (!$this->exists($filename)){ |
|
| 88 | 88 | throw new FileNotFoundException($filename); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | ): bool { |
| 104 | 104 | $mode ??= self::DEFAULT_FILE_MODE; |
| 105 | 105 | |
| 106 | - try { |
|
| 107 | - if ($ensureDirectory) { |
|
| 106 | + try{ |
|
| 107 | + if ($ensureDirectory){ |
|
| 108 | 108 | $this->ensureDirectory(\dirname($filename), $mode); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if ($this->exists($filename)) { |
|
| 111 | + if ($this->exists($filename)){ |
|
| 112 | 112 | //Forcing mode for existed file |
| 113 | 113 | $this->setPermissions($filename, $mode); |
| 114 | 114 | } |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - if ($result !== false) { |
|
| 122 | + if ($result !== false){ |
|
| 123 | 123 | //Forcing mode after file creation |
| 124 | 124 | $this->setPermissions($filename, $mode); |
| 125 | 125 | } |
| 126 | - } catch (\Exception $e) { |
|
| 127 | - throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 126 | + }catch (\Exception $e){ |
|
| 127 | + throw new WriteErrorException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return $result !== false; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | public function delete(string $filename): bool |
| 143 | 143 | { |
| 144 | - if ($this->exists($filename)) { |
|
| 144 | + if ($this->exists($filename)){ |
|
| 145 | 145 | $result = \unlink($filename); |
| 146 | 146 | |
| 147 | 147 | //Wiping out changes in local file cache |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
| 162 | 162 | { |
| 163 | - if (!$this->isDirectory($directory)) { |
|
| 163 | + if (!$this->isDirectory($directory)){ |
|
| 164 | 164 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,15 +169,15 @@ discard block |
||
| 169 | 169 | \RecursiveIteratorIterator::CHILD_FIRST |
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | - foreach ($files as $file) { |
|
| 173 | - if ($file->isDir()) { |
|
| 172 | + foreach ($files as $file){ |
|
| 173 | + if ($file->isDir()){ |
|
| 174 | 174 | \rmdir($file->getRealPath()); |
| 175 | - } else { |
|
| 175 | + }else{ |
|
| 176 | 176 | $this->delete($file->getRealPath()); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if (!$contentOnly) { |
|
| 180 | + if (!$contentOnly){ |
|
| 181 | 181 | return \rmdir($directory); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | public function move(string $filename, string $destination): bool |
| 188 | 188 | { |
| 189 | - if (!$this->exists($filename)) { |
|
| 189 | + if (!$this->exists($filename)){ |
|
| 190 | 190 | throw new FileNotFoundException($filename); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | public function copy(string $filename, string $destination): bool |
| 197 | 197 | { |
| 198 | - if (!$this->exists($filename)) { |
|
| 198 | + if (!$this->exists($filename)){ |
|
| 199 | 199 | throw new FileNotFoundException($filename); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | public function touch(string $filename, ?int $mode = null): bool |
| 206 | 206 | { |
| 207 | - if (!\touch($filename)) { |
|
| 207 | + if (!\touch($filename)){ |
|
| 208 | 208 | return false; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | public function size(string $filename): int |
| 220 | 220 | { |
| 221 | - if (!$this->exists($filename)) { |
|
| 221 | + if (!$this->exists($filename)){ |
|
| 222 | 222 | throw new FileNotFoundException($filename); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | public function md5(string $filename): string |
| 234 | 234 | { |
| 235 | - if (!$this->exists($filename)) { |
|
| 235 | + if (!$this->exists($filename)){ |
|
| 236 | 236 | throw new FileNotFoundException($filename); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | public function time(string $filename): int |
| 243 | 243 | { |
| 244 | - if (!$this->exists($filename)) { |
|
| 244 | + if (!$this->exists($filename)){ |
|
| 245 | 245 | throw new FileNotFoundException($filename); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | public function getPermissions(string $filename): int |
| 262 | 262 | { |
| 263 | - if (!$this->exists($filename)) { |
|
| 263 | + if (!$this->exists($filename)){ |
|
| 264 | 264 | throw new FileNotFoundException($filename); |
| 265 | 265 | } |
| 266 | 266 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | public function setPermissions(string $filename, int $mode): bool |
| 271 | 271 | { |
| 272 | - if (\is_dir($filename)) { |
|
| 272 | + if (\is_dir($filename)){ |
|
| 273 | 273 | //Directories must always be executable (i.e. 664 for dir => 775) |
| 274 | 274 | $mode |= 0111; |
| 275 | 275 | } |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | public function getFiles(string $location, ?string $pattern = null): array |
| 281 | 281 | { |
| 282 | 282 | $result = []; |
| 283 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
| 284 | - if ($this->isDirectory($filename->getPathname())) { |
|
| 285 | - $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
| 283 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
| 284 | + if ($this->isDirectory($filename->getPathname())){ |
|
| 285 | + $result = \array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
| 286 | 286 | |
| 287 | 287 | continue; |
| 288 | 288 | } |
@@ -295,13 +295,13 @@ discard block |
||
| 295 | 295 | |
| 296 | 296 | public function tempFilename(string $extension = '', ?string $location = null): string |
| 297 | 297 | { |
| 298 | - if (empty($location)) { |
|
| 298 | + if (empty($location)){ |
|
| 299 | 299 | $location = \sys_get_temp_dir(); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $filename = \tempnam($location, 'spiral'); |
| 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 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | private function filesIterator(string $location, ?string $pattern = null): \GlobIterator |
| 362 | 362 | { |
| 363 | 363 | $pattern ??= '*'; |
| 364 | - $regexp = \rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 364 | + $regexp = \rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.\ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 365 | 365 | |
| 366 | 366 | return new \GlobIterator($regexp); |
| 367 | 367 | } |
@@ -36,7 +36,8 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __destruct() |
| 38 | 38 | { |
| 39 | - foreach ($this->destructFiles as $filename) { |
|
| 39 | + foreach ($this->destructFiles as $filename) |
|
| 40 | + { |
|
| 40 | 41 | $this->delete($filename); |
| 41 | 42 | } |
| 42 | 43 | } |
@@ -49,30 +50,36 @@ discard block |
||
| 49 | 50 | ?int $mode = null, |
| 50 | 51 | bool $recursivePermissions = true |
| 51 | 52 | ): bool { |
| 52 | - if (empty($mode)) { |
|
| 53 | + if (empty($mode)) |
|
| 54 | + { |
|
| 53 | 55 | $mode = self::DEFAULT_FILE_MODE; |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | //Directories always executable |
| 57 | 59 | $mode |= 0o111; |
| 58 | - if (\is_dir($directory)) { |
|
| 60 | + if (\is_dir($directory)) |
|
| 61 | + { |
|
| 59 | 62 | //Exists :( |
| 60 | 63 | return $this->setPermissions($directory, $mode); |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | - if (!$recursivePermissions) { |
|
| 66 | + if (!$recursivePermissions) |
|
| 67 | + { |
|
| 64 | 68 | return \mkdir($directory, $mode, true); |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | 71 | $directoryChain = [\basename($directory)]; |
| 68 | 72 | |
| 69 | 73 | $baseDirectory = $directory; |
| 70 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
| 74 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))) |
|
| 75 | + { |
|
| 71 | 76 | $directoryChain[] = \basename($baseDirectory); |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
| 75 | - if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
| 79 | + foreach (\array_reverse($directoryChain) as $dir) |
|
| 80 | + { |
|
| 81 | + if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) |
|
| 82 | + { |
|
| 76 | 83 | return false; |
| 77 | 84 | } |
| 78 | 85 | |
@@ -84,7 +91,8 @@ discard block |
||
| 84 | 91 | |
| 85 | 92 | public function read(string $filename): string |
| 86 | 93 | { |
| 87 | - if (!$this->exists($filename)) { |
|
| 94 | + if (!$this->exists($filename)) |
|
| 95 | + { |
|
| 88 | 96 | throw new FileNotFoundException($filename); |
| 89 | 97 | } |
| 90 | 98 | |
@@ -103,12 +111,15 @@ discard block |
||
| 103 | 111 | ): bool { |
| 104 | 112 | $mode ??= self::DEFAULT_FILE_MODE; |
| 105 | 113 | |
| 106 | - try { |
|
| 107 | - if ($ensureDirectory) { |
|
| 114 | + try |
|
| 115 | + { |
|
| 116 | + if ($ensureDirectory) |
|
| 117 | + { |
|
| 108 | 118 | $this->ensureDirectory(\dirname($filename), $mode); |
| 109 | 119 | } |
| 110 | 120 | |
| 111 | - if ($this->exists($filename)) { |
|
| 121 | + if ($this->exists($filename)) |
|
| 122 | + { |
|
| 112 | 123 | //Forcing mode for existed file |
| 113 | 124 | $this->setPermissions($filename, $mode); |
| 114 | 125 | } |
@@ -119,11 +130,14 @@ discard block |
||
| 119 | 130 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 120 | 131 | ); |
| 121 | 132 | |
| 122 | - if ($result !== false) { |
|
| 133 | + if ($result !== false) |
|
| 134 | + { |
|
| 123 | 135 | //Forcing mode after file creation |
| 124 | 136 | $this->setPermissions($filename, $mode); |
| 125 | 137 | } |
| 126 | - } catch (\Exception $e) { |
|
| 138 | + } |
|
| 139 | + catch (\Exception $e) |
|
| 140 | + { |
|
| 127 | 141 | throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
| 128 | 142 | } |
| 129 | 143 | |
@@ -141,7 +155,8 @@ discard block |
||
| 141 | 155 | |
| 142 | 156 | public function delete(string $filename): bool |
| 143 | 157 | { |
| 144 | - if ($this->exists($filename)) { |
|
| 158 | + if ($this->exists($filename)) |
|
| 159 | + { |
|
| 145 | 160 | $result = \unlink($filename); |
| 146 | 161 | |
| 147 | 162 | //Wiping out changes in local file cache |
@@ -160,7 +175,8 @@ discard block |
||
| 160 | 175 | */ |
| 161 | 176 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
| 162 | 177 | { |
| 163 | - if (!$this->isDirectory($directory)) { |
|
| 178 | + if (!$this->isDirectory($directory)) |
|
| 179 | + { |
|
| 164 | 180 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
| 165 | 181 | } |
| 166 | 182 | |
@@ -169,15 +185,20 @@ discard block |
||
| 169 | 185 | \RecursiveIteratorIterator::CHILD_FIRST |
| 170 | 186 | ); |
| 171 | 187 | |
| 172 | - foreach ($files as $file) { |
|
| 173 | - if ($file->isDir()) { |
|
| 188 | + foreach ($files as $file) |
|
| 189 | + { |
|
| 190 | + if ($file->isDir()) |
|
| 191 | + { |
|
| 174 | 192 | \rmdir($file->getRealPath()); |
| 175 | - } else { |
|
| 193 | + } |
|
| 194 | + else |
|
| 195 | + { |
|
| 176 | 196 | $this->delete($file->getRealPath()); |
| 177 | 197 | } |
| 178 | 198 | } |
| 179 | 199 | |
| 180 | - if (!$contentOnly) { |
|
| 200 | + if (!$contentOnly) |
|
| 201 | + { |
|
| 181 | 202 | return \rmdir($directory); |
| 182 | 203 | } |
| 183 | 204 | |
@@ -186,7 +207,8 @@ discard block |
||
| 186 | 207 | |
| 187 | 208 | public function move(string $filename, string $destination): bool |
| 188 | 209 | { |
| 189 | - if (!$this->exists($filename)) { |
|
| 210 | + if (!$this->exists($filename)) |
|
| 211 | + { |
|
| 190 | 212 | throw new FileNotFoundException($filename); |
| 191 | 213 | } |
| 192 | 214 | |
@@ -195,7 +217,8 @@ discard block |
||
| 195 | 217 | |
| 196 | 218 | public function copy(string $filename, string $destination): bool |
| 197 | 219 | { |
| 198 | - if (!$this->exists($filename)) { |
|
| 220 | + if (!$this->exists($filename)) |
|
| 221 | + { |
|
| 199 | 222 | throw new FileNotFoundException($filename); |
| 200 | 223 | } |
| 201 | 224 | |
@@ -204,7 +227,8 @@ discard block |
||
| 204 | 227 | |
| 205 | 228 | public function touch(string $filename, ?int $mode = null): bool |
| 206 | 229 | { |
| 207 | - if (!\touch($filename)) { |
|
| 230 | + if (!\touch($filename)) |
|
| 231 | + { |
|
| 208 | 232 | return false; |
| 209 | 233 | } |
| 210 | 234 | |
@@ -218,7 +242,8 @@ discard block |
||
| 218 | 242 | |
| 219 | 243 | public function size(string $filename): int |
| 220 | 244 | { |
| 221 | - if (!$this->exists($filename)) { |
|
| 245 | + if (!$this->exists($filename)) |
|
| 246 | + { |
|
| 222 | 247 | throw new FileNotFoundException($filename); |
| 223 | 248 | } |
| 224 | 249 | |
@@ -232,7 +257,8 @@ discard block |
||
| 232 | 257 | |
| 233 | 258 | public function md5(string $filename): string |
| 234 | 259 | { |
| 235 | - if (!$this->exists($filename)) { |
|
| 260 | + if (!$this->exists($filename)) |
|
| 261 | + { |
|
| 236 | 262 | throw new FileNotFoundException($filename); |
| 237 | 263 | } |
| 238 | 264 | |
@@ -241,7 +267,8 @@ discard block |
||
| 241 | 267 | |
| 242 | 268 | public function time(string $filename): int |
| 243 | 269 | { |
| 244 | - if (!$this->exists($filename)) { |
|
| 270 | + if (!$this->exists($filename)) |
|
| 271 | + { |
|
| 245 | 272 | throw new FileNotFoundException($filename); |
| 246 | 273 | } |
| 247 | 274 | |
@@ -260,7 +287,8 @@ discard block |
||
| 260 | 287 | |
| 261 | 288 | public function getPermissions(string $filename): int |
| 262 | 289 | { |
| 263 | - if (!$this->exists($filename)) { |
|
| 290 | + if (!$this->exists($filename)) |
|
| 291 | + { |
|
| 264 | 292 | throw new FileNotFoundException($filename); |
| 265 | 293 | } |
| 266 | 294 | |
@@ -269,7 +297,8 @@ discard block |
||
| 269 | 297 | |
| 270 | 298 | public function setPermissions(string $filename, int $mode): bool |
| 271 | 299 | { |
| 272 | - if (\is_dir($filename)) { |
|
| 300 | + if (\is_dir($filename)) |
|
| 301 | + { |
|
| 273 | 302 | //Directories must always be executable (i.e. 664 for dir => 775) |
| 274 | 303 | $mode |= 0111; |
| 275 | 304 | } |
@@ -280,8 +309,10 @@ discard block |
||
| 280 | 309 | public function getFiles(string $location, ?string $pattern = null): array |
| 281 | 310 | { |
| 282 | 311 | $result = []; |
| 283 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
| 284 | - if ($this->isDirectory($filename->getPathname())) { |
|
| 312 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
| 313 | + { |
|
| 314 | + if ($this->isDirectory($filename->getPathname())) |
|
| 315 | + { |
|
| 285 | 316 | $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
| 286 | 317 | |
| 287 | 318 | continue; |
@@ -295,13 +326,15 @@ discard block |
||
| 295 | 326 | |
| 296 | 327 | public function tempFilename(string $extension = '', ?string $location = null): string |
| 297 | 328 | { |
| 298 | - if (empty($location)) { |
|
| 329 | + if (empty($location)) |
|
| 330 | + { |
|
| 299 | 331 | $location = \sys_get_temp_dir(); |
| 300 | 332 | } |
| 301 | 333 | |
| 302 | 334 | $filename = \tempnam($location, 'spiral'); |
| 303 | 335 | |
| 304 | - if (!empty($extension)) { |
|
| 336 | + if (!empty($extension)) |
|
| 337 | + { |
|
| 305 | 338 | $old = $filename; |
| 306 | 339 | $filename = \sprintf('%s.%s', $filename, $extension); |
| 307 | 340 | \rename($old, $filename); |
@@ -314,7 +347,8 @@ discard block |
||
| 314 | 347 | public function normalizePath(string $path, bool $asDirectory = false): string |
| 315 | 348 | { |
| 316 | 349 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
| 317 | - if ($isUnc) { |
|
| 350 | + if ($isUnc) |
|
| 351 | + { |
|
| 318 | 352 | $leadingSlashes = \substr($path, 0, 2); |
| 319 | 353 | $path = \substr($path, 2); |
| 320 | 354 | } |
@@ -337,15 +371,20 @@ discard block |
||
| 337 | 371 | $path = \explode('/', $path); |
| 338 | 372 | $relative = $path; |
| 339 | 373 | |
| 340 | - foreach ($from as $depth => $dir) { |
|
| 374 | + foreach ($from as $depth => $dir) |
|
| 375 | + { |
|
| 341 | 376 | //Find first non-matching dir |
| 342 | - if ($dir === $path[$depth]) { |
|
| 377 | + if ($dir === $path[$depth]) |
|
| 378 | + { |
|
| 343 | 379 | //Ignore this directory |
| 344 | 380 | \array_shift($relative); |
| 345 | - } else { |
|
| 381 | + } |
|
| 382 | + else |
|
| 383 | + { |
|
| 346 | 384 | //Get number of remaining dirs to $from |
| 347 | 385 | $remaining = \count($from) - $depth; |
| 348 | - if ($remaining > 1) { |
|
| 386 | + if ($remaining > 1) |
|
| 387 | + { |
|
| 349 | 388 | //Add traversals up to first matching directory |
| 350 | 389 | $padLength = (\count($relative) + $remaining - 1) * -1; |
| 351 | 390 | $relative = \array_pad($relative, $padLength, '..'); |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | public function __construct(?\Throwable $previous = null, ?string $message = null) |
| 10 | 10 | { |
| 11 | 11 | parent::__construct( |
| 12 | - message: $message ?? 'Unable to set value. The given data was invalid.', |
|
| 13 | - previous: $previous, |
|
| 12 | + message : $message ?? 'Unable to set value. The given data was invalid.', |
|
| 13 | + previous : $previous, |
|
| 14 | 14 | ); |
| 15 | 15 | } |
| 16 | 16 | } |
@@ -56,24 +56,24 @@ discard block |
||
| 56 | 56 | yield [$from(fn(string $string = self::STRING_CONST) => 0), 'mixed $string = self::STRING_CONST']; |
| 57 | 57 | yield [ |
| 58 | 58 | $from(fn(string $string = ProxyClassRendererTest::STRING_CONST) => 0), |
| 59 | - 'mixed $string = \\' . self::class . '::STRING_CONST', |
|
| 59 | + 'mixed $string = \\'.self::class.'::STRING_CONST', |
|
| 60 | 60 | ]; |
| 61 | - yield [$from(fn(string|int $string = self::INT_CONST) => 0), 'mixed $string = self::INT_CONST']; |
|
| 61 | + yield [$from(fn(string | int $string = self::INT_CONST) => 0), 'mixed $string = self::INT_CONST']; |
|
| 62 | 62 | yield [$from(fn(mixed $string = 42) => 0), 'mixed $string = 42']; |
| 63 | 63 | yield [$from(fn(int $string = 42) => 0), 'mixed $string = 42']; |
| 64 | 64 | yield [$from(fn(float $string = 42) => 0), 'mixed $string = 42.0']; |
| 65 | 65 | yield [$from(fn(?bool $string = false) => 0), 'mixed $string = false']; |
| 66 | - yield [$from(fn(bool|null $string = true) => 0), 'mixed $string = true']; |
|
| 66 | + yield [$from(fn(bool | null $string = true) => 0), 'mixed $string = true']; |
|
| 67 | 67 | yield [$from(fn(?object $string = null) => 0), 'mixed $string = NULL']; |
| 68 | 68 | yield [$from(fn(?iterable $string = null) => 0), 'mixed $string = NULL']; |
| 69 | 69 | yield [$from(fn(Countable&ArrayAccess $val) => 0), 'mixed $val']; |
| 70 | 70 | yield [$from(fn(string ...$val) => 0), 'mixed ...$val']; |
| 71 | - yield [$from(fn(string|int ...$val) => 0), 'mixed ...$val']; |
|
| 72 | - yield [$from(fn(string|int &$link) => 0), 'mixed &$link']; |
|
| 71 | + yield [$from(fn(string | int ...$val) => 0), 'mixed ...$val']; |
|
| 72 | + yield [$from(fn(string | int &$link) => 0), 'mixed &$link']; |
|
| 73 | 73 | yield [$from(self::withSelf(...)), 'mixed $self = new self()']; |
| 74 | 74 | yield [$from(fn(object $link = new \stdClass()) => 0), 'mixed $link = new \stdClass()']; |
| 75 | 75 | yield [ |
| 76 | - $from(fn(#[Proxy] float|int|\stdClass|null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0), |
|
| 76 | + $from(fn(#[Proxy] float | int | \stdClass | null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0), |
|
| 77 | 77 | "mixed \$string = new \stdClass(1, 2, bar: '\n\'zero')", |
| 78 | 78 | ]; |
| 79 | 79 | yield [ |
@@ -97,18 +97,18 @@ discard block |
||
| 97 | 97 | public const INT_CONST = 42; |
| 98 | 98 | |
| 99 | 99 | #[ExpectedAttribute('public function test1(...$variadic)')] |
| 100 | - public function test1(...$variadic) {} |
|
| 100 | + public function test1(...$variadic){} |
|
| 101 | 101 | #[ExpectedAttribute('public function test2(mixed $string = self::INT_CONST): string|int')] |
| 102 | - public function test2(string|int $string = self::INT_CONST): string|int {} |
|
| 102 | + public function test2(string | int $string = self::INT_CONST): string | int {} |
|
| 103 | 103 | #[ExpectedAttribute('public function test3(mixed $obj = new \stdClass(new \stdClass(), new \stdClass()))')] |
| 104 | - public function test3(object $obj = new stdClass(new stdClass(), new stdClass())) {} |
|
| 105 | - #[ExpectedAttribute('public function test4(): \\' . ProxyClassRendererTest::class)] |
|
| 104 | + public function test3(object $obj = new stdClass(new stdClass(), new stdClass())){} |
|
| 105 | + #[ExpectedAttribute('public function test4(): \\'.ProxyClassRendererTest::class)] |
|
| 106 | 106 | public function test4(): ProxyClassRendererTest {} |
| 107 | 107 | #[ExpectedAttribute('public function &test5(): string')] |
| 108 | 108 | public function &test5(): string {} |
| 109 | 109 | }; |
| 110 | 110 | |
| 111 | - foreach ((new \ReflectionClass($class))->getMethods() as $method) { |
|
| 111 | + foreach ((new \ReflectionClass($class))->getMethods() as $method){ |
|
| 112 | 112 | $expected = $method->getAttributes(ExpectedAttribute::class)[0]->newInstance(); |
| 113 | 113 | |
| 114 | 114 | yield [$method, $expected->value]; |
@@ -145,22 +145,22 @@ discard block |
||
| 145 | 145 | $from = static fn(\Closure $closure): \ReflectionParameter => new \ReflectionParameter($closure, 0); |
| 146 | 146 | |
| 147 | 147 | yield [$from(fn(string $string) => 0), 'string']; |
| 148 | - yield [$from(fn(string|int $string) => 0), 'string|int']; |
|
| 148 | + yield [$from(fn(string | int $string) => 0), 'string|int']; |
|
| 149 | 149 | yield [$from(fn(mixed $string) => 0), 'mixed']; |
| 150 | 150 | yield [$from(fn(int $string) => 0), 'int']; |
| 151 | 151 | yield [$from(fn(float $string) => 0), 'float']; |
| 152 | 152 | yield [$from(fn(?bool $string) => 0), '?bool']; |
| 153 | - yield [$from(fn(bool|null $string) => 0), '?bool']; |
|
| 153 | + yield [$from(fn(bool | null $string) => 0), '?bool']; |
|
| 154 | 154 | yield [$from(fn(object $string) => 0), 'object']; |
| 155 | 155 | yield [$from(fn(iterable $string) => 0), 'iterable']; |
| 156 | 156 | yield [$from(fn(Countable&ArrayAccess $val) => 0), '\Countable&\ArrayAccess']; |
| 157 | 157 | yield [$from(fn(string ...$val) => 0), 'string']; |
| 158 | - yield [$from(fn(string|int ...$val) => 0), 'string|int']; |
|
| 159 | - yield [$from(fn(string|int &$link) => 0), 'string|int']; |
|
| 160 | - yield [$from(self::withSelf(...)), '\\' . self::class]; |
|
| 158 | + yield [$from(fn(string | int ...$val) => 0), 'string|int']; |
|
| 159 | + yield [$from(fn(string | int &$link) => 0), 'string|int']; |
|
| 160 | + yield [$from(self::withSelf(...)), '\\'.self::class]; |
|
| 161 | 161 | yield [$from(fn(object $link) => 0), 'object']; |
| 162 | - yield [$from(fn(#[Proxy] float|int|\stdClass|null $string) => 0), '\stdClass|int|float|null']; |
|
| 163 | - yield [$from(fn(SimpleEnum $val) => 0), '\\' . SimpleEnum::class]; |
|
| 162 | + yield [$from(fn(#[Proxy] float | int | \stdClass | null $string) => 0), '\stdClass|int|float|null']; |
|
| 163 | + yield [$from(fn(SimpleEnum $val) => 0), '\\'.SimpleEnum::class]; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | private static function withSelf(self $self = new self()): void |
@@ -173,6 +173,6 @@ discard block |
||
| 173 | 173 | { |
| 174 | 174 | public function __construct( |
| 175 | 175 | public readonly string $value, |
| 176 | - ) { |
|
| 176 | + ){ |
|
| 177 | 177 | } |
| 178 | 178 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | ): array { |
| 54 | 54 | $state = new ResolvingState($reflection, $parameters); |
| 55 | 55 | |
| 56 | - foreach ($reflection->getParameters() as $parameter) { |
|
| 56 | + foreach ($reflection->getParameters() as $parameter){ |
|
| 57 | 57 | $this->resolveParameter($parameter, $state, $validate) |
| 58 | 58 | or |
| 59 | 59 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +67,47 @@ discard block |
||
| 67 | 67 | $positional = true; |
| 68 | 68 | $variadic = false; |
| 69 | 69 | $parameters = $reflection->getParameters(); |
| 70 | - if (\count($parameters) === 0) { |
|
| 70 | + if (\count($parameters) === 0){ |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $parameter = null; |
| 75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
| 75 | + while (\count($parameters) > 0 || \count($arguments) > 0){ |
|
| 76 | 76 | // get related argument value |
| 77 | 77 | $key = \key($arguments); |
| 78 | 78 | |
| 79 | 79 | // For a variadic parameter it's no sense - named or positional argument will be sent |
| 80 | 80 | // But you can't send positional argument after named in any case |
| 81 | - if (\is_int($key) && !$positional) { |
|
| 81 | + if (\is_int($key) && !$positional){ |
|
| 82 | 82 | throw new PositionalArgumentException($reflection, $key); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $positional = $positional && \is_int($key); |
| 86 | 86 | |
| 87 | - if (!$variadic) { |
|
| 87 | + if (!$variadic){ |
|
| 88 | 88 | $parameter = \array_shift($parameters); |
| 89 | 89 | $variadic = $parameter?->isVariadic() ?? false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ($parameter === null) { |
|
| 92 | + if ($parameter === null){ |
|
| 93 | 93 | throw new UnknownParameterException($reflection, $key); |
| 94 | 94 | } |
| 95 | 95 | $name = $parameter->getName(); |
| 96 | 96 | |
| 97 | - if (($positional || $variadic) && $key !== null) { |
|
| 97 | + if (($positional || $variadic) && $key !== null){ |
|
| 98 | 98 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
| 99 | 99 | $value = \array_shift($arguments); |
| 100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
| 101 | - if ($parameter->isOptional()) { |
|
| 100 | + } elseif ($key === null || !\array_key_exists($name, $arguments)){ |
|
| 101 | + if ($parameter->isOptional()){ |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | throw new MissingRequiredArgumentException($reflection, $name); |
| 105 | - } else { |
|
| 105 | + }else{ |
|
| 106 | 106 | $value = &$arguments[$name]; |
| 107 | 107 | unset($arguments[$name]); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
| 110 | + if (!$this->validateValueToParameter($parameter, $value)){ |
|
| 111 | 111 | throw new InvalidArgumentException($reflection, $name); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
| 117 | 117 | { |
| 118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
| 118 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){ |
|
| 119 | 119 | return true; |
| 120 | 120 | } |
| 121 | 121 | $type = $parameter->getType(); |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
| 127 | 127 | }; |
| 128 | 128 | |
| 129 | - foreach ($types as $t) { |
|
| 129 | + foreach ($types as $t){ |
|
| 130 | 130 | \assert($t instanceof ReflectionNamedType); |
| 131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
| 131 | + if (!$this->validateValueNamedType($t, $value)){ |
|
| 132 | 132 | // If it is TypeIntersection |
| 133 | - if ($or) { |
|
| 133 | + if ($or){ |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | // If it is not type intersection then we can skip that value after first successful check |
| 139 | - if ($or) { |
|
| 139 | + if ($or){ |
|
| 140 | 140 | return true; |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $name = $type->getName(); |
| 153 | 153 | |
| 154 | - if ($type->isBuiltin()) { |
|
| 154 | + if ($type->isBuiltin()){ |
|
| 155 | 155 | return match ($name) { |
| 156 | 156 | 'mixed' => true, |
| 157 | 157 | 'string' => \is_string($value), |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | // Try to resolve parameter by name |
| 186 | 186 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
| 187 | - if ($res !== [] || $isVariadic) { |
|
| 187 | + if ($res !== [] || $isVariadic){ |
|
| 188 | 188 | // validate |
| 189 | - if ($isVariadic) { |
|
| 190 | - foreach ($res as $k => &$v) { |
|
| 191 | - $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
|
| 189 | + if ($isVariadic){ |
|
| 190 | + foreach ($res as $k => &$v){ |
|
| 191 | + $this->processArgument($state, $v, validateWith: $validate ? $param : null, key : $k); |
|
| 192 | 192 | } |
| 193 | - } else { |
|
| 193 | + }else{ |
|
| 194 | 194 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -198,18 +198,18 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $error = null; |
| 201 | - while ($hasType) { |
|
| 201 | + while ($hasType){ |
|
| 202 | 202 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
| 203 | 203 | $refType = $param->getType(); |
| 204 | 204 | |
| 205 | - if ($refType::class === ReflectionNamedType::class) { |
|
| 206 | - if ($refType->isBuiltin()) { |
|
| 205 | + if ($refType::class === ReflectionNamedType::class){ |
|
| 206 | + if ($refType->isBuiltin()){ |
|
| 207 | 207 | break; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | if (\interface_exists($refType->getName()) && !empty( |
| 211 | 211 | $attrs = $param->getAttributes(ProxyAttribute::class) |
| 212 | - )) { |
|
| 212 | + )){ |
|
| 213 | 213 | $proxy = Proxy::create( |
| 214 | 214 | new \ReflectionClass($refType->getName()), |
| 215 | 215 | $param, |
@@ -219,23 +219,23 @@ discard block |
||
| 219 | 219 | return true; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - try { |
|
| 223 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
| 222 | + try{ |
|
| 223 | + if ($this->resolveObject($state, $refType, $param, $validate)){ |
|
| 224 | 224 | return true; |
| 225 | 225 | } |
| 226 | - } catch (Throwable $e) { |
|
| 226 | + }catch (Throwable $e){ |
|
| 227 | 227 | $error = $e; |
| 228 | 228 | } |
| 229 | 229 | break; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ($refType::class === ReflectionUnionType::class) { |
|
| 233 | - foreach ($refType->getTypes() as $namedType) { |
|
| 234 | - try { |
|
| 235 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
| 232 | + if ($refType::class === ReflectionUnionType::class){ |
|
| 233 | + foreach ($refType->getTypes() as $namedType){ |
|
| 234 | + try{ |
|
| 235 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)){ |
|
| 236 | 236 | return true; |
| 237 | 237 | } |
| 238 | - } catch (Throwable $e) { |
|
| 238 | + }catch (Throwable $e){ |
|
| 239 | 239 | $error = $e; |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -245,19 +245,19 @@ discard block |
||
| 245 | 245 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ($param->isDefaultValueAvailable()) { |
|
| 248 | + if ($param->isDefaultValueAvailable()){ |
|
| 249 | 249 | $argument = $param->getDefaultValue(); |
| 250 | 250 | $this->processArgument($state, $argument); |
| 251 | 251 | return true; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - if ($hasType && $param->allowsNull()) { |
|
| 254 | + if ($hasType && $param->allowsNull()){ |
|
| 255 | 255 | $argument = null; |
| 256 | 256 | $this->processArgument($state, $argument); |
| 257 | 257 | return true; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ($error === null) { |
|
| 260 | + if ($error === null){ |
|
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -295,15 +295,15 @@ discard block |
||
| 295 | 295 | ResolvingState $state, |
| 296 | 296 | mixed &$value, |
| 297 | 297 | ?ReflectionParameter $validateWith = null, |
| 298 | - int|string|null $key = null |
|
| 298 | + int | string | null $key = null |
|
| 299 | 299 | ): void { |
| 300 | 300 | // Resolve Autowire objects |
| 301 | - if ($value instanceof Autowire) { |
|
| 301 | + if ($value instanceof Autowire){ |
|
| 302 | 302 | $value = $value->resolve($this->factory); |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // Validation |
| 306 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
| 306 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){ |
|
| 307 | 307 | throw new InvalidArgumentException( |
| 308 | 308 | $validateWith->getDeclaringFunction(), |
| 309 | 309 | $validateWith->getName() |
@@ -53,7 +53,8 @@ discard block |
||
| 53 | 53 | ): array { |
| 54 | 54 | $state = new ResolvingState($reflection, $parameters); |
| 55 | 55 | |
| 56 | - foreach ($reflection->getParameters() as $parameter) { |
|
| 56 | + foreach ($reflection->getParameters() as $parameter) |
|
| 57 | + { |
|
| 57 | 58 | $this->resolveParameter($parameter, $state, $validate) |
| 58 | 59 | or |
| 59 | 60 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +68,59 @@ discard block |
||
| 67 | 68 | $positional = true; |
| 68 | 69 | $variadic = false; |
| 69 | 70 | $parameters = $reflection->getParameters(); |
| 70 | - if (\count($parameters) === 0) { |
|
| 71 | + if (\count($parameters) === 0) |
|
| 72 | + { |
|
| 71 | 73 | return; |
| 72 | 74 | } |
| 73 | 75 | |
| 74 | 76 | $parameter = null; |
| 75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
| 77 | + while (\count($parameters) > 0 || \count($arguments) > 0) |
|
| 78 | + { |
|
| 76 | 79 | // get related argument value |
| 77 | 80 | $key = \key($arguments); |
| 78 | 81 | |
| 79 | 82 | // For a variadic parameter it's no sense - named or positional argument will be sent |
| 80 | 83 | // But you can't send positional argument after named in any case |
| 81 | - if (\is_int($key) && !$positional) { |
|
| 84 | + if (\is_int($key) && !$positional) |
|
| 85 | + { |
|
| 82 | 86 | throw new PositionalArgumentException($reflection, $key); |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | $positional = $positional && \is_int($key); |
| 86 | 90 | |
| 87 | - if (!$variadic) { |
|
| 91 | + if (!$variadic) |
|
| 92 | + { |
|
| 88 | 93 | $parameter = \array_shift($parameters); |
| 89 | 94 | $variadic = $parameter?->isVariadic() ?? false; |
| 90 | 95 | } |
| 91 | 96 | |
| 92 | - if ($parameter === null) { |
|
| 97 | + if ($parameter === null) |
|
| 98 | + { |
|
| 93 | 99 | throw new UnknownParameterException($reflection, $key); |
| 94 | 100 | } |
| 95 | 101 | $name = $parameter->getName(); |
| 96 | 102 | |
| 97 | - if (($positional || $variadic) && $key !== null) { |
|
| 103 | + if (($positional || $variadic) && $key !== null) |
|
| 104 | + { |
|
| 98 | 105 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
| 99 | 106 | $value = \array_shift($arguments); |
| 100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
| 101 | - if ($parameter->isOptional()) { |
|
| 107 | + } |
|
| 108 | + elseif ($key === null || !\array_key_exists($name, $arguments)) |
|
| 109 | + { |
|
| 110 | + if ($parameter->isOptional()) |
|
| 111 | + { |
|
| 102 | 112 | continue; |
| 103 | 113 | } |
| 104 | 114 | throw new MissingRequiredArgumentException($reflection, $name); |
| 105 | - } else { |
|
| 115 | + } |
|
| 116 | + else |
|
| 117 | + { |
|
| 106 | 118 | $value = &$arguments[$name]; |
| 107 | 119 | unset($arguments[$name]); |
| 108 | 120 | } |
| 109 | 121 | |
| 110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
| 122 | + if (!$this->validateValueToParameter($parameter, $value)) |
|
| 123 | + { |
|
| 111 | 124 | throw new InvalidArgumentException($reflection, $name); |
| 112 | 125 | } |
| 113 | 126 | } |
@@ -115,7 +128,8 @@ discard block |
||
| 115 | 128 | |
| 116 | 129 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
| 117 | 130 | { |
| 118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
| 131 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) |
|
| 132 | + { |
|
| 119 | 133 | return true; |
| 120 | 134 | } |
| 121 | 135 | $type = $parameter->getType(); |
@@ -126,17 +140,21 @@ discard block |
||
| 126 | 140 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
| 127 | 141 | }; |
| 128 | 142 | |
| 129 | - foreach ($types as $t) { |
|
| 143 | + foreach ($types as $t) |
|
| 144 | + { |
|
| 130 | 145 | \assert($t instanceof ReflectionNamedType); |
| 131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
| 146 | + if (!$this->validateValueNamedType($t, $value)) |
|
| 147 | + { |
|
| 132 | 148 | // If it is TypeIntersection |
| 133 | - if ($or) { |
|
| 149 | + if ($or) |
|
| 150 | + { |
|
| 134 | 151 | continue; |
| 135 | 152 | } |
| 136 | 153 | return false; |
| 137 | 154 | } |
| 138 | 155 | // If it is not type intersection then we can skip that value after first successful check |
| 139 | - if ($or) { |
|
| 156 | + if ($or) |
|
| 157 | + { |
|
| 140 | 158 | return true; |
| 141 | 159 | } |
| 142 | 160 | } |
@@ -151,7 +169,8 @@ discard block |
||
| 151 | 169 | { |
| 152 | 170 | $name = $type->getName(); |
| 153 | 171 | |
| 154 | - if ($type->isBuiltin()) { |
|
| 172 | + if ($type->isBuiltin()) |
|
| 173 | + { |
|
| 155 | 174 | return match ($name) { |
| 156 | 175 | 'mixed' => true, |
| 157 | 176 | 'string' => \is_string($value), |
@@ -184,13 +203,18 @@ discard block |
||
| 184 | 203 | |
| 185 | 204 | // Try to resolve parameter by name |
| 186 | 205 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
| 187 | - if ($res !== [] || $isVariadic) { |
|
| 206 | + if ($res !== [] || $isVariadic) |
|
| 207 | + { |
|
| 188 | 208 | // validate |
| 189 | - if ($isVariadic) { |
|
| 190 | - foreach ($res as $k => &$v) { |
|
| 209 | + if ($isVariadic) |
|
| 210 | + { |
|
| 211 | + foreach ($res as $k => &$v) |
|
| 212 | + { |
|
| 191 | 213 | $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
| 192 | 214 | } |
| 193 | - } else { |
|
| 215 | + } |
|
| 216 | + else |
|
| 217 | + { |
|
| 194 | 218 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
| 195 | 219 | } |
| 196 | 220 | |
@@ -198,18 +222,22 @@ discard block |
||
| 198 | 222 | } |
| 199 | 223 | |
| 200 | 224 | $error = null; |
| 201 | - while ($hasType) { |
|
| 225 | + while ($hasType) |
|
| 226 | + { |
|
| 202 | 227 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
| 203 | 228 | $refType = $param->getType(); |
| 204 | 229 | |
| 205 | - if ($refType::class === ReflectionNamedType::class) { |
|
| 206 | - if ($refType->isBuiltin()) { |
|
| 230 | + if ($refType::class === ReflectionNamedType::class) |
|
| 231 | + { |
|
| 232 | + if ($refType->isBuiltin()) |
|
| 233 | + { |
|
| 207 | 234 | break; |
| 208 | 235 | } |
| 209 | 236 | |
| 210 | 237 | if (\interface_exists($refType->getName()) && !empty( |
| 211 | 238 | $attrs = $param->getAttributes(ProxyAttribute::class) |
| 212 | - )) { |
|
| 239 | + )) |
|
| 240 | + { |
|
| 213 | 241 | $proxy = Proxy::create( |
| 214 | 242 | new \ReflectionClass($refType->getName()), |
| 215 | 243 | $param, |
@@ -219,23 +247,33 @@ discard block |
||
| 219 | 247 | return true; |
| 220 | 248 | } |
| 221 | 249 | |
| 222 | - try { |
|
| 223 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
| 250 | + try |
|
| 251 | + { |
|
| 252 | + if ($this->resolveObject($state, $refType, $param, $validate)) |
|
| 253 | + { |
|
| 224 | 254 | return true; |
| 225 | 255 | } |
| 226 | - } catch (Throwable $e) { |
|
| 256 | + } |
|
| 257 | + catch (Throwable $e) |
|
| 258 | + { |
|
| 227 | 259 | $error = $e; |
| 228 | 260 | } |
| 229 | 261 | break; |
| 230 | 262 | } |
| 231 | 263 | |
| 232 | - if ($refType::class === ReflectionUnionType::class) { |
|
| 233 | - foreach ($refType->getTypes() as $namedType) { |
|
| 234 | - try { |
|
| 235 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
| 264 | + if ($refType::class === ReflectionUnionType::class) |
|
| 265 | + { |
|
| 266 | + foreach ($refType->getTypes() as $namedType) |
|
| 267 | + { |
|
| 268 | + try |
|
| 269 | + { |
|
| 270 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) |
|
| 271 | + { |
|
| 236 | 272 | return true; |
| 237 | 273 | } |
| 238 | - } catch (Throwable $e) { |
|
| 274 | + } |
|
| 275 | + catch (Throwable $e) |
|
| 276 | + { |
|
| 239 | 277 | $error = $e; |
| 240 | 278 | } |
| 241 | 279 | } |
@@ -245,19 +283,22 @@ discard block |
||
| 245 | 283 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
| 246 | 284 | } |
| 247 | 285 | |
| 248 | - if ($param->isDefaultValueAvailable()) { |
|
| 286 | + if ($param->isDefaultValueAvailable()) |
|
| 287 | + { |
|
| 249 | 288 | $argument = $param->getDefaultValue(); |
| 250 | 289 | $this->processArgument($state, $argument); |
| 251 | 290 | return true; |
| 252 | 291 | } |
| 253 | 292 | |
| 254 | - if ($hasType && $param->allowsNull()) { |
|
| 293 | + if ($hasType && $param->allowsNull()) |
|
| 294 | + { |
|
| 255 | 295 | $argument = null; |
| 256 | 296 | $this->processArgument($state, $argument); |
| 257 | 297 | return true; |
| 258 | 298 | } |
| 259 | 299 | |
| 260 | - if ($error === null) { |
|
| 300 | + if ($error === null) |
|
| 301 | + { |
|
| 261 | 302 | return false; |
| 262 | 303 | } |
| 263 | 304 | |
@@ -298,12 +339,14 @@ discard block |
||
| 298 | 339 | int|string|null $key = null |
| 299 | 340 | ): void { |
| 300 | 341 | // Resolve Autowire objects |
| 301 | - if ($value instanceof Autowire) { |
|
| 342 | + if ($value instanceof Autowire) |
|
| 343 | + { |
|
| 302 | 344 | $value = $value->resolve($this->factory); |
| 303 | 345 | } |
| 304 | 346 | |
| 305 | 347 | // Validation |
| 306 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
| 348 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) |
|
| 349 | + { |
|
| 307 | 350 | throw new InvalidArgumentException( |
| 308 | 351 | $validateWith->getDeclaringFunction(), |
| 309 | 352 | $validateWith->getName() |
@@ -23,15 +23,15 @@ discard block |
||
| 23 | 23 | public function __construct( |
| 24 | 24 | public readonly ReflectionFunctionAbstract $reflection, |
| 25 | 25 | private array $arguments, |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | $this->modeNamed = $this->isNamedMode(); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function addResolvedValue(mixed &$value, ?string $key = null): void |
| 31 | 31 | { |
| 32 | - if ($key === null) { |
|
| 32 | + if ($key === null){ |
|
| 33 | 33 | $this->resolvedValues[] = &$value; |
| 34 | - } else { |
|
| 34 | + }else{ |
|
| 35 | 35 | $this->resolvedValues[$key] = &$value; |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | ? $parameter->getName() |
| 43 | 43 | : $parameter->getPosition(); |
| 44 | 44 | |
| 45 | - if (!\array_key_exists($key, $this->arguments)) { |
|
| 45 | + if (!\array_key_exists($key, $this->arguments)){ |
|
| 46 | 46 | return []; |
| 47 | 47 | } |
| 48 | 48 | $_val = &$this->arguments[$key]; |
| 49 | 49 | |
| 50 | - if ($variadic && \is_array($_val)) { |
|
| 50 | + if ($variadic && \is_array($_val)){ |
|
| 51 | 51 | // Save keys is possible |
| 52 | 52 | $positional = true; |
| 53 | 53 | $result = []; |
| 54 | - foreach ($_val as $key => &$item) { |
|
| 55 | - if (!$positional && \is_int($key)) { |
|
| 54 | + foreach ($_val as $key => &$item){ |
|
| 55 | + if (!$positional && \is_int($key)){ |
|
| 56 | 56 | throw new ResolvingException( |
| 57 | 57 | 'Cannot use positional argument after named argument during unpacking named variadic argument.' |
| 58 | 58 | ); |
| 59 | 59 | } |
| 60 | 60 | $positional = $positional && \is_int($key); |
| 61 | - if ($positional) { |
|
| 61 | + if ($positional){ |
|
| 62 | 62 | $result[] = &$item; |
| 63 | - } else { |
|
| 63 | + }else{ |
|
| 64 | 64 | $result[$key] = &$item; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $nums = 0; |
| 80 | 80 | $strings = 0; |
| 81 | - foreach ($this->arguments as $key => $_) { |
|
| 82 | - if (\is_int($key)) { |
|
| 81 | + foreach ($this->arguments as $key => $_){ |
|
| 82 | + if (\is_int($key)){ |
|
| 83 | 83 | ++$nums; |
| 84 | - } else { |
|
| 84 | + }else{ |
|
| 85 | 85 | ++$strings; |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -29,9 +29,12 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function addResolvedValue(mixed &$value, ?string $key = null): void |
| 31 | 31 | { |
| 32 | - if ($key === null) { |
|
| 32 | + if ($key === null) |
|
| 33 | + { |
|
| 33 | 34 | $this->resolvedValues[] = &$value; |
| 34 | - } else { |
|
| 35 | + } |
|
| 36 | + else |
|
| 37 | + { |
|
| 35 | 38 | $this->resolvedValues[$key] = &$value; |
| 36 | 39 | } |
| 37 | 40 | } |
@@ -42,25 +45,32 @@ discard block |
||
| 42 | 45 | ? $parameter->getName() |
| 43 | 46 | : $parameter->getPosition(); |
| 44 | 47 | |
| 45 | - if (!\array_key_exists($key, $this->arguments)) { |
|
| 48 | + if (!\array_key_exists($key, $this->arguments)) |
|
| 49 | + { |
|
| 46 | 50 | return []; |
| 47 | 51 | } |
| 48 | 52 | $_val = &$this->arguments[$key]; |
| 49 | 53 | |
| 50 | - if ($variadic && \is_array($_val)) { |
|
| 54 | + if ($variadic && \is_array($_val)) |
|
| 55 | + { |
|
| 51 | 56 | // Save keys is possible |
| 52 | 57 | $positional = true; |
| 53 | 58 | $result = []; |
| 54 | - foreach ($_val as $key => &$item) { |
|
| 55 | - if (!$positional && \is_int($key)) { |
|
| 59 | + foreach ($_val as $key => &$item) |
|
| 60 | + { |
|
| 61 | + if (!$positional && \is_int($key)) |
|
| 62 | + { |
|
| 56 | 63 | throw new ResolvingException( |
| 57 | 64 | 'Cannot use positional argument after named argument during unpacking named variadic argument.' |
| 58 | 65 | ); |
| 59 | 66 | } |
| 60 | 67 | $positional = $positional && \is_int($key); |
| 61 | - if ($positional) { |
|
| 68 | + if ($positional) |
|
| 69 | + { |
|
| 62 | 70 | $result[] = &$item; |
| 63 | - } else { |
|
| 71 | + } |
|
| 72 | + else |
|
| 73 | + { |
|
| 64 | 74 | $result[$key] = &$item; |
| 65 | 75 | } |
| 66 | 76 | } |
@@ -78,10 +88,14 @@ discard block |
||
| 78 | 88 | { |
| 79 | 89 | $nums = 0; |
| 80 | 90 | $strings = 0; |
| 81 | - foreach ($this->arguments as $key => $_) { |
|
| 82 | - if (\is_int($key)) { |
|
| 91 | + foreach ($this->arguments as $key => $_) |
|
| 92 | + { |
|
| 93 | + if (\is_int($key)) |
|
| 94 | + { |
|
| 83 | 95 | ++$nums; |
| 84 | - } else { |
|
| 96 | + } |
|
| 97 | + else |
|
| 98 | + { |
|
| 85 | 99 | ++$strings; |
| 86 | 100 | } |
| 87 | 101 | } |
@@ -19,28 +19,28 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly SessionScope $session |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function load(string $id): ?TokenInterface |
| 26 | 26 | { |
| 27 | - try { |
|
| 27 | + try{ |
|
| 28 | 28 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
| 29 | - if ($tokenData === null) { |
|
| 29 | + if ($tokenData === null){ |
|
| 30 | 30 | return null; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $token = Token::unpack($tokenData); |
| 34 | - } catch (\Throwable $e) { |
|
| 35 | - throw new TokenStorageException('Unable to load session token', (int) $e->getCode(), $e); |
|
| 34 | + }catch (\Throwable $e){ |
|
| 35 | + throw new TokenStorageException('Unable to load session token', (int)$e->getCode(), $e); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (!\hash_equals($token->getID(), $id)) { |
|
| 38 | + if (!\hash_equals($token->getID(), $id)){ |
|
| 39 | 39 | return null; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $expiresAt = $token->getExpiresAt(); |
| 43 | - if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) { |
|
| 43 | + if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()){ |
|
| 44 | 44 | $this->delete($token); |
| 45 | 45 | return null; |
| 46 | 46 | } |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | public function create(array $payload, ?\DateTimeInterface $expiresAt = null): TokenInterface |
| 52 | 52 | { |
| 53 | - try { |
|
| 53 | + try{ |
|
| 54 | 54 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
| 55 | 55 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
| 56 | 56 | |
| 57 | 57 | return $token; |
| 58 | - } catch (\Throwable $e) { |
|
| 59 | - throw new TokenStorageException('Unable to create session token', (int) $e->getCode(), $e); |
|
| 58 | + }catch (\Throwable $e){ |
|
| 59 | + throw new TokenStorageException('Unable to create session token', (int)$e->getCode(), $e); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
@@ -24,23 +24,29 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function load(string $id): ?TokenInterface |
| 26 | 26 | { |
| 27 | - try { |
|
| 27 | + try |
|
| 28 | + { |
|
| 28 | 29 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
| 29 | - if ($tokenData === null) { |
|
| 30 | + if ($tokenData === null) |
|
| 31 | + { |
|
| 30 | 32 | return null; |
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | $token = Token::unpack($tokenData); |
| 34 | - } catch (\Throwable $e) { |
|
| 36 | + } |
|
| 37 | + catch (\Throwable $e) |
|
| 38 | + { |
|
| 35 | 39 | throw new TokenStorageException('Unable to load session token', (int) $e->getCode(), $e); |
| 36 | 40 | } |
| 37 | 41 | |
| 38 | - if (!\hash_equals($token->getID(), $id)) { |
|
| 42 | + if (!\hash_equals($token->getID(), $id)) |
|
| 43 | + { |
|
| 39 | 44 | return null; |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | 47 | $expiresAt = $token->getExpiresAt(); |
| 43 | - if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) { |
|
| 48 | + if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) |
|
| 49 | + { |
|
| 44 | 50 | $this->delete($token); |
| 45 | 51 | return null; |
| 46 | 52 | } |
@@ -50,12 +56,15 @@ discard block |
||
| 50 | 56 | |
| 51 | 57 | public function create(array $payload, ?\DateTimeInterface $expiresAt = null): TokenInterface |
| 52 | 58 | { |
| 53 | - try { |
|
| 59 | + try |
|
| 60 | + { |
|
| 54 | 61 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
| 55 | 62 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
| 56 | 63 | |
| 57 | 64 | return $token; |
| 58 | - } catch (\Throwable $e) { |
|
| 65 | + } |
|
| 66 | + catch (\Throwable $e) |
|
| 67 | + { |
|
| 59 | 68 | throw new TokenStorageException('Unable to create session token', (int) $e->getCode(), $e); |
| 60 | 69 | } |
| 61 | 70 | } |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | $generator = new ContextGenerator($views->getContext()); |
| 26 | 26 | |
| 27 | 27 | $contexts = $generator->generate(); |
| 28 | - if (empty($contexts)) { |
|
| 28 | + if (empty($contexts)){ |
|
| 29 | 29 | $contexts[] = $views->getContext(); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - foreach ($contexts as $context) { |
|
| 33 | - foreach ($views->getEngines() as $engine) { |
|
| 34 | - if ($engine instanceof NativeEngine) { |
|
| 32 | + foreach ($contexts as $context){ |
|
| 33 | + foreach ($views->getEngines() as $engine){ |
|
| 34 | + if ($engine instanceof NativeEngine){ |
|
| 35 | 35 | // no need to compile |
| 36 | 36 | continue; |
| 37 | 37 | } |
@@ -53,19 +53,19 @@ discard block |
||
| 53 | 53 | $this->describeContext($context) ?? 'default' |
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - foreach ($engine->getLoader()->list() as $path) { |
|
| 56 | + foreach ($engine->getLoader()->list() as $path){ |
|
| 57 | 57 | $start = \microtime(true); |
| 58 | - try { |
|
| 58 | + try{ |
|
| 59 | 59 | $engine->reset($path, $context); |
| 60 | 60 | $engine->compile($path, $context); |
| 61 | 61 | |
| 62 | - if ($this->isVerbose()) { |
|
| 62 | + if ($this->isVerbose()){ |
|
| 63 | 63 | $this->sprintf('<info>•</info> %s', $path); |
| 64 | 64 | } |
| 65 | - } catch (\Throwable $e) { |
|
| 65 | + }catch (\Throwable $e){ |
|
| 66 | 66 | $this->renderError($path, $e); |
| 67 | 67 | continue; |
| 68 | - } finally { |
|
| 68 | + }finally{ |
|
| 69 | 69 | $this->renderElapsed($start); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | protected function renderError(string $path, \Throwable $e): void |
| 77 | 77 | { |
| 78 | - if (!$this->isVerbose()) { |
|
| 78 | + if (!$this->isVerbose()){ |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $values = []; |
| 93 | 93 | |
| 94 | - foreach ($context->getDependencies() as $dependency) { |
|
| 94 | + foreach ($context->getDependencies() as $dependency){ |
|
| 95 | 95 | $values[] = \sprintf( |
| 96 | 96 | '%s%s%s:%s%s%s', |
| 97 | 97 | Color::LIGHT_WHITE, |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | private function renderSuccess(?string $lastPath = null): void |
| 115 | 115 | { |
| 116 | - if (!$this->isVerbose()) { |
|
| 116 | + if (!$this->isVerbose()){ |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ($lastPath === null) { |
|
| 120 | + if ($lastPath === null){ |
|
| 121 | 121 | $this->writeln('• no views found'); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | private function renderElapsed(float $start): void |
| 128 | 128 | { |
| 129 | - if (!$this->isVerbose()) { |
|
| 129 | + if (!$this->isVerbose()){ |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -25,13 +25,17 @@ discard block |
||
| 25 | 25 | $generator = new ContextGenerator($views->getContext()); |
| 26 | 26 | |
| 27 | 27 | $contexts = $generator->generate(); |
| 28 | - if (empty($contexts)) { |
|
| 28 | + if (empty($contexts)) |
|
| 29 | + { |
|
| 29 | 30 | $contexts[] = $views->getContext(); |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | - foreach ($contexts as $context) { |
|
| 33 | - foreach ($views->getEngines() as $engine) { |
|
| 34 | - if ($engine instanceof NativeEngine) { |
|
| 33 | + foreach ($contexts as $context) |
|
| 34 | + { |
|
| 35 | + foreach ($views->getEngines() as $engine) |
|
| 36 | + { |
|
| 37 | + if ($engine instanceof NativeEngine) |
|
| 38 | + { |
|
| 35 | 39 | // no need to compile |
| 36 | 40 | continue; |
| 37 | 41 | } |
@@ -53,19 +57,26 @@ discard block |
||
| 53 | 57 | $this->describeContext($context) ?? 'default' |
| 54 | 58 | ); |
| 55 | 59 | |
| 56 | - foreach ($engine->getLoader()->list() as $path) { |
|
| 60 | + foreach ($engine->getLoader()->list() as $path) |
|
| 61 | + { |
|
| 57 | 62 | $start = \microtime(true); |
| 58 | - try { |
|
| 63 | + try |
|
| 64 | + { |
|
| 59 | 65 | $engine->reset($path, $context); |
| 60 | 66 | $engine->compile($path, $context); |
| 61 | 67 | |
| 62 | - if ($this->isVerbose()) { |
|
| 68 | + if ($this->isVerbose()) |
|
| 69 | + { |
|
| 63 | 70 | $this->sprintf('<info>•</info> %s', $path); |
| 64 | 71 | } |
| 65 | - } catch (\Throwable $e) { |
|
| 72 | + } |
|
| 73 | + catch (\Throwable $e) |
|
| 74 | + { |
|
| 66 | 75 | $this->renderError($path, $e); |
| 67 | 76 | continue; |
| 68 | - } finally { |
|
| 77 | + } |
|
| 78 | + finally |
|
| 79 | + { |
|
| 69 | 80 | $this->renderElapsed($start); |
| 70 | 81 | } |
| 71 | 82 | } |
@@ -75,7 +86,8 @@ discard block |
||
| 75 | 86 | |
| 76 | 87 | protected function renderError(string $path, \Throwable $e): void |
| 77 | 88 | { |
| 78 | - if (!$this->isVerbose()) { |
|
| 89 | + if (!$this->isVerbose()) |
|
| 90 | + { |
|
| 79 | 91 | return; |
| 80 | 92 | } |
| 81 | 93 | |
@@ -91,7 +103,8 @@ discard block |
||
| 91 | 103 | { |
| 92 | 104 | $values = []; |
| 93 | 105 | |
| 94 | - foreach ($context->getDependencies() as $dependency) { |
|
| 106 | + foreach ($context->getDependencies() as $dependency) |
|
| 107 | + { |
|
| 95 | 108 | $values[] = \sprintf( |
| 96 | 109 | '%s%s%s:%s%s%s', |
| 97 | 110 | Color::LIGHT_WHITE, |
@@ -113,11 +126,13 @@ discard block |
||
| 113 | 126 | |
| 114 | 127 | private function renderSuccess(?string $lastPath = null): void |
| 115 | 128 | { |
| 116 | - if (!$this->isVerbose()) { |
|
| 129 | + if (!$this->isVerbose()) |
|
| 130 | + { |
|
| 117 | 131 | return; |
| 118 | 132 | } |
| 119 | 133 | |
| 120 | - if ($lastPath === null) { |
|
| 134 | + if ($lastPath === null) |
|
| 135 | + { |
|
| 121 | 136 | $this->writeln('• no views found'); |
| 122 | 137 | } |
| 123 | 138 | |
@@ -126,7 +141,8 @@ discard block |
||
| 126 | 141 | |
| 127 | 142 | private function renderElapsed(float $start): void |
| 128 | 143 | { |
| 129 | - if (!$this->isVerbose()) { |
|
| 144 | + if (!$this->isVerbose()) |
|
| 145 | + { |
|
| 130 | 146 | return; |
| 131 | 147 | } |
| 132 | 148 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | protected function compile(string $source, array $visitors = [], ?LoaderInterface $loader = null) |
| 29 | 29 | { |
| 30 | - if ($loader === null) { |
|
| 30 | + if ($loader === null){ |
|
| 31 | 31 | $loader = new StringLoader(); |
| 32 | 32 | $loader->set('root', $source); |
| 33 | 33 | } |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
| 63 | 63 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
| 64 | 64 | |
| 65 | - foreach ($this->getVisitors() as $visitor) { |
|
| 65 | + foreach ($this->getVisitors() as $visitor){ |
|
| 66 | 66 | $builder->addVisitor($visitor); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - foreach ($visitors as $visitor) { |
|
| 69 | + foreach ($visitors as $visitor){ |
|
| 70 | 70 | $builder->addVisitor($visitor); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -80,6 +80,6 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | protected function getFixtureLoader(): LoaderInterface |
| 82 | 82 | { |
| 83 | - return new DirectoryLoader(__DIR__ . '/../fixtures'); |
|
| 83 | + return new DirectoryLoader(__DIR__.'/../fixtures'); |
|
| 84 | 84 | } |
| 85 | 85 | } |
@@ -27,7 +27,8 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | protected function compile(string $source, array $visitors = [], ?LoaderInterface $loader = null) |
| 29 | 29 | { |
| 30 | - if ($loader === null) { |
|
| 30 | + if ($loader === null) |
|
| 31 | + { |
|
| 31 | 32 | $loader = new StringLoader(); |
| 32 | 33 | $loader->set('root', $source); |
| 33 | 34 | } |
@@ -62,11 +63,13 @@ discard block |
||
| 62 | 63 | $builder->getCompiler()->addRenderer(new DynamicRenderer(new DirectiveGroup())); |
| 63 | 64 | $builder->getCompiler()->addRenderer(new HTMLRenderer()); |
| 64 | 65 | |
| 65 | - foreach ($this->getVisitors() as $visitor) { |
|
| 66 | + foreach ($this->getVisitors() as $visitor) |
|
| 67 | + { |
|
| 66 | 68 | $builder->addVisitor($visitor); |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | - foreach ($visitors as $visitor) { |
|
| 71 | + foreach ($visitors as $visitor) |
|
| 72 | + { |
|
| 70 | 73 | $builder->addVisitor($visitor); |
| 71 | 74 | } |
| 72 | 75 | |