Passed
Pull Request — master (#407)
by Kirill
11:08 queued 03:58
created
src/storage/src/Storage.php 2 patches
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $this->config = $config;
52 52
         $this->uriParser = $parser ?? new UriParser();
53 53
 
54
-        foreach ($config->getBucketsKeys() as $fs) {
54
+        foreach ($config->getBucketsKeys() as $fs){
55 55
             $this->mountFilesystem($fs, new Filesystem(
56 56
                 AdapterFactory::build($this->config->buildFileSystemInfo($fs))
57 57
             ));
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function getFileSystem(string $key): FilesystemOperator
65 65
     {
66
-        if (!$this->isFileSystemExists($key)) {
66
+        if (!$this->isFileSystemExists($key)){
67 67
             throw new MountException(\sprintf('Filesystem `%s` has not been defined', $key));
68 68
         }
69 69
 
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
         /** @var FilesystemOperator $filesystem */
87 87
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
88 88
 
89
-        try {
89
+        try{
90 90
             return $filesystem->fileExists($path);
91
-        } catch (FilesystemException $e) {
91
+        }catch (FilesystemException $e){
92 92
             throw new FileOperationException($e->getMessage(), $e->getCode(), $e);
93 93
         }
94 94
     }
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
         /** @var FilesystemOperator $filesystem */
102 102
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
103 103
 
104
-        try {
104
+        try{
105 105
             return $filesystem->read($path);
106
-        } catch (FilesystemException $e) {
106
+        }catch (FilesystemException $e){
107 107
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
108 108
         }
109 109
     }
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
         /** @var FilesystemOperator $filesystem */
117 117
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
118 118
 
119
-        try {
119
+        try{
120 120
             return $filesystem->readStream($path);
121
-        } catch (FilesystemException $e) {
121
+        }catch (FilesystemException $e){
122 122
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
123 123
         }
124 124
     }
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
         /** @var FilesystemOperator $filesystem */
132 132
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
133 133
 
134
-        try {
134
+        try{
135 135
             return $filesystem->lastModified($path);
136
-        } catch (FilesystemException $e) {
136
+        }catch (FilesystemException $e){
137 137
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
138 138
         }
139 139
     }
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
         /** @var FilesystemOperator $filesystem */
147 147
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
148 148
 
149
-        try {
149
+        try{
150 150
             return $filesystem->fileSize($path);
151
-        } catch (FilesystemException $e) {
151
+        }catch (FilesystemException $e){
152 152
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
153 153
         }
154 154
     }
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
         /** @var FilesystemOperator $filesystem */
162 162
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
163 163
 
164
-        try {
164
+        try{
165 165
             return $filesystem->mimeType($path);
166
-        } catch (FilesystemException $e) {
166
+        }catch (FilesystemException $e){
167 167
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
168 168
         }
169 169
     }
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
         /** @var FilesystemOperator $filesystem */
177 177
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
178 178
 
179
-        try {
179
+        try{
180 180
             return $filesystem->visibility($path);
181
-        } catch (FilesystemException $e) {
181
+        }catch (FilesystemException $e){
182 182
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
183 183
         }
184 184
     }
@@ -188,24 +188,24 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public function tempFilename(string $uri = null): string
190 190
     {
191
-        try {
191
+        try{
192 192
             $prefix = 'tmpStorageFile_';
193 193
 
194
-            if ($uri !== null) {
194
+            if ($uri !== null){
195 195
                 /** @var FilesystemOperator $filesystem */
196 196
                 [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
197 197
                 $content = $filesystem->readStream($path);
198
-                $prefix = basename($uri) . '_';
198
+                $prefix = basename($uri).'_';
199 199
             }
200 200
 
201 201
             $filePath = tempnam($this->config->getTmpDir(), $prefix);
202 202
 
203
-            if (isset($content)) {
203
+            if (isset($content)){
204 204
                 file_put_contents($filePath, $content);
205 205
             }
206 206
 
207 207
             return $filePath;
208
-        } catch (\Throwable $e) {
208
+        }catch (\Throwable $e){
209 209
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
210 210
         }
211 211
     }
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
         /** @var FilesystemOperator $filesystem */
221 221
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
222 222
 
223
-        try {
223
+        try{
224 224
             $filesystem->write($path, $content, $config);
225 225
 
226 226
             return $uri;
227
-        } catch (FilesystemException $e) {
227
+        }catch (FilesystemException $e){
228 228
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
229 229
         }
230 230
     }
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
         /** @var FilesystemOperator $filesystem */
240 240
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
241 241
 
242
-        try {
242
+        try{
243 243
             $filesystem->writeStream($path, $content, $config);
244 244
 
245 245
             return $uri;
246
-        } catch (FilesystemException $e) {
246
+        }catch (FilesystemException $e){
247 247
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
248 248
         }
249 249
     }
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         /** @var FilesystemOperator $filesystem */
257 257
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
258 258
 
259
-        try {
259
+        try{
260 260
             $filesystem->setVisibility($path, $visibility);
261
-        } catch (FilesystemException $e) {
261
+        }catch (FilesystemException $e){
262 262
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
263 263
         }
264 264
     }
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
         $destinationFilesystem = $this->getFileSystem($destinationFileSystem);
279 279
 
280
-        try {
280
+        try{
281 281
             $targetFilePath = $targetFilePath ?: $sourcePath;
282 282
 
283 283
             $sourceFilesystem === $destinationFilesystem
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                 : $this->moveAcrossFilesystems($sourceUri, $destinationFileSystem, $targetFilePath, $config);
286 286
 
287 287
             return (string)Uri::create($destinationFileSystem, $targetFilePath);
288
-        } catch (FilesystemException $e) {
288
+        }catch (FilesystemException $e){
289 289
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
290 290
         }
291 291
     }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 
305 305
         $destinationFilesystem = $this->getFileSystem($destinationFileSystem);
306 306
 
307
-        try {
307
+        try{
308 308
             $targetFilePath = $targetFilePath ?: $sourcePath;
309 309
 
310 310
             $sourceFilesystem === $destinationFilesystem
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
                 );
320 320
 
321 321
             return (string)Uri::create($destinationFileSystem, $targetFilePath);
322
-        } catch (FilesystemException $e) {
322
+        }catch (FilesystemException $e){
323 323
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
324 324
         }
325 325
     }
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
         /** @var FilesystemOperator $filesystem */
333 333
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
334 334
 
335
-        try {
335
+        try{
336 336
             $filesystem->delete($path);
337
-        } catch (FilesystemException $e) {
337
+        }catch (FilesystemException $e){
338 338
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
339 339
         }
340 340
     }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
      */
351 351
     protected function mountFilesystem(string $key, FilesystemOperator $filesystem): void
352 352
     {
353
-        if ($this->isFileSystemExists($key)) {
353
+        if ($this->isFileSystemExists($key)){
354 354
             throw new MountException(\sprintf('Filesystem %s is already mounted', $key));
355 355
         }
356 356
 
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
         string $destinationPath,
456 456
         array $config = []
457 457
     ): void {
458
-        if ($sourcePath === $destinationPath && empty($config)) {
458
+        if ($sourcePath === $destinationPath && empty($config)){
459 459
             return;
460 460
         }
461 461
 
Please login to merge, or discard this patch.
Braces   +82 added lines, -34 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
         $this->config = $config;
52 52
         $this->uriParser = $parser ?? new UriParser();
53 53
 
54
-        foreach ($config->getBucketsKeys() as $fs) {
54
+        foreach ($config->getBucketsKeys() as $fs)
55
+        {
55 56
             $this->mountFilesystem($fs, new Filesystem(
56 57
                 AdapterFactory::build($this->config->buildFileSystemInfo($fs))
57 58
             ));
@@ -63,7 +64,8 @@  discard block
 block discarded – undo
63 64
      */
64 65
     public function getFileSystem(string $key): FilesystemOperator
65 66
     {
66
-        if (!$this->isFileSystemExists($key)) {
67
+        if (!$this->isFileSystemExists($key))
68
+        {
67 69
             throw new MountException(\sprintf('Filesystem `%s` has not been defined', $key));
68 70
         }
69 71
 
@@ -86,9 +88,12 @@  discard block
 block discarded – undo
86 88
         /** @var FilesystemOperator $filesystem */
87 89
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
88 90
 
89
-        try {
91
+        try
92
+        {
90 93
             return $filesystem->fileExists($path);
91
-        } catch (FilesystemException $e) {
94
+        }
95
+        catch (FilesystemException $e)
96
+        {
92 97
             throw new FileOperationException($e->getMessage(), $e->getCode(), $e);
93 98
         }
94 99
     }
@@ -101,9 +106,12 @@  discard block
 block discarded – undo
101 106
         /** @var FilesystemOperator $filesystem */
102 107
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
103 108
 
104
-        try {
109
+        try
110
+        {
105 111
             return $filesystem->read($path);
106
-        } catch (FilesystemException $e) {
112
+        }
113
+        catch (FilesystemException $e)
114
+        {
107 115
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
108 116
         }
109 117
     }
@@ -116,9 +124,12 @@  discard block
 block discarded – undo
116 124
         /** @var FilesystemOperator $filesystem */
117 125
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
118 126
 
119
-        try {
127
+        try
128
+        {
120 129
             return $filesystem->readStream($path);
121
-        } catch (FilesystemException $e) {
130
+        }
131
+        catch (FilesystemException $e)
132
+        {
122 133
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
123 134
         }
124 135
     }
@@ -131,9 +142,12 @@  discard block
 block discarded – undo
131 142
         /** @var FilesystemOperator $filesystem */
132 143
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
133 144
 
134
-        try {
145
+        try
146
+        {
135 147
             return $filesystem->lastModified($path);
136
-        } catch (FilesystemException $e) {
148
+        }
149
+        catch (FilesystemException $e)
150
+        {
137 151
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
138 152
         }
139 153
     }
@@ -146,9 +160,12 @@  discard block
 block discarded – undo
146 160
         /** @var FilesystemOperator $filesystem */
147 161
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
148 162
 
149
-        try {
163
+        try
164
+        {
150 165
             return $filesystem->fileSize($path);
151
-        } catch (FilesystemException $e) {
166
+        }
167
+        catch (FilesystemException $e)
168
+        {
152 169
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
153 170
         }
154 171
     }
@@ -161,9 +178,12 @@  discard block
 block discarded – undo
161 178
         /** @var FilesystemOperator $filesystem */
162 179
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
163 180
 
164
-        try {
181
+        try
182
+        {
165 183
             return $filesystem->mimeType($path);
166
-        } catch (FilesystemException $e) {
184
+        }
185
+        catch (FilesystemException $e)
186
+        {
167 187
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
168 188
         }
169 189
     }
@@ -176,9 +196,12 @@  discard block
 block discarded – undo
176 196
         /** @var FilesystemOperator $filesystem */
177 197
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
178 198
 
179
-        try {
199
+        try
200
+        {
180 201
             return $filesystem->visibility($path);
181
-        } catch (FilesystemException $e) {
202
+        }
203
+        catch (FilesystemException $e)
204
+        {
182 205
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
183 206
         }
184 207
     }
@@ -188,10 +211,12 @@  discard block
 block discarded – undo
188 211
      */
189 212
     public function tempFilename(string $uri = null): string
190 213
     {
191
-        try {
214
+        try
215
+        {
192 216
             $prefix = 'tmpStorageFile_';
193 217
 
194
-            if ($uri !== null) {
218
+            if ($uri !== null)
219
+            {
195 220
                 /** @var FilesystemOperator $filesystem */
196 221
                 [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
197 222
                 $content = $filesystem->readStream($path);
@@ -200,12 +225,15 @@  discard block
 block discarded – undo
200 225
 
201 226
             $filePath = tempnam($this->config->getTmpDir(), $prefix);
202 227
 
203
-            if (isset($content)) {
228
+            if (isset($content))
229
+            {
204 230
                 file_put_contents($filePath, $content);
205 231
             }
206 232
 
207 233
             return $filePath;
208
-        } catch (\Throwable $e) {
234
+        }
235
+        catch (\Throwable $e)
236
+        {
209 237
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
210 238
         }
211 239
     }
@@ -220,11 +248,14 @@  discard block
 block discarded – undo
220 248
         /** @var FilesystemOperator $filesystem */
221 249
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
222 250
 
223
-        try {
251
+        try
252
+        {
224 253
             $filesystem->write($path, $content, $config);
225 254
 
226 255
             return $uri;
227
-        } catch (FilesystemException $e) {
256
+        }
257
+        catch (FilesystemException $e)
258
+        {
228 259
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
229 260
         }
230 261
     }
@@ -239,11 +270,14 @@  discard block
 block discarded – undo
239 270
         /** @var FilesystemOperator $filesystem */
240 271
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
241 272
 
242
-        try {
273
+        try
274
+        {
243 275
             $filesystem->writeStream($path, $content, $config);
244 276
 
245 277
             return $uri;
246
-        } catch (FilesystemException $e) {
278
+        }
279
+        catch (FilesystemException $e)
280
+        {
247 281
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
248 282
         }
249 283
     }
@@ -256,9 +290,12 @@  discard block
 block discarded – undo
256 290
         /** @var FilesystemOperator $filesystem */
257 291
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
258 292
 
259
-        try {
293
+        try
294
+        {
260 295
             $filesystem->setVisibility($path, $visibility);
261
-        } catch (FilesystemException $e) {
296
+        }
297
+        catch (FilesystemException $e)
298
+        {
262 299
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
263 300
         }
264 301
     }
@@ -277,7 +314,8 @@  discard block
 block discarded – undo
277 314
 
278 315
         $destinationFilesystem = $this->getFileSystem($destinationFileSystem);
279 316
 
280
-        try {
317
+        try
318
+        {
281 319
             $targetFilePath = $targetFilePath ?: $sourcePath;
282 320
 
283 321
             $sourceFilesystem === $destinationFilesystem
@@ -285,7 +323,9 @@  discard block
 block discarded – undo
285 323
                 : $this->moveAcrossFilesystems($sourceUri, $destinationFileSystem, $targetFilePath, $config);
286 324
 
287 325
             return (string)Uri::create($destinationFileSystem, $targetFilePath);
288
-        } catch (FilesystemException $e) {
326
+        }
327
+        catch (FilesystemException $e)
328
+        {
289 329
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
290 330
         }
291 331
     }
@@ -304,7 +344,8 @@  discard block
 block discarded – undo
304 344
 
305 345
         $destinationFilesystem = $this->getFileSystem($destinationFileSystem);
306 346
 
307
-        try {
347
+        try
348
+        {
308 349
             $targetFilePath = $targetFilePath ?: $sourcePath;
309 350
 
310 351
             $sourceFilesystem === $destinationFilesystem
@@ -319,7 +360,9 @@  discard block
 block discarded – undo
319 360
                 );
320 361
 
321 362
             return (string)Uri::create($destinationFileSystem, $targetFilePath);
322
-        } catch (FilesystemException $e) {
363
+        }
364
+        catch (FilesystemException $e)
365
+        {
323 366
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
324 367
         }
325 368
     }
@@ -332,9 +375,12 @@  discard block
 block discarded – undo
332 375
         /** @var FilesystemOperator $filesystem */
333 376
         [$filesystem, $path] = $this->determineFilesystemAndPath($uri);
334 377
 
335
-        try {
378
+        try
379
+        {
336 380
             $filesystem->delete($path);
337
-        } catch (FilesystemException $e) {
381
+        }
382
+        catch (FilesystemException $e)
383
+        {
338 384
             throw new FileOperationException($e->getMessage(), (int)$e->getCode(), $e);
339 385
         }
340 386
     }
@@ -350,7 +396,8 @@  discard block
 block discarded – undo
350 396
      */
351 397
     protected function mountFilesystem(string $key, FilesystemOperator $filesystem): void
352 398
     {
353
-        if ($this->isFileSystemExists($key)) {
399
+        if ($this->isFileSystemExists($key))
400
+        {
354 401
             throw new MountException(\sprintf('Filesystem %s is already mounted', $key));
355 402
         }
356 403
 
@@ -455,7 +502,8 @@  discard block
 block discarded – undo
455 502
         string $destinationPath,
456 503
         array $config = []
457 504
     ): void {
458
-        if ($sourcePath === $destinationPath && empty($config)) {
505
+        if ($sourcePath === $destinationPath && empty($config))
506
+        {
459 507
             return;
460 508
         }
461 509
 
Please login to merge, or discard this patch.