Passed
Push — master ( 3a0aa4...dae184 )
by Domenico
03:53
created
benchmark/test.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require __DIR__.'/../vendor/autoload.php';
3
+require __DIR__ . '/../vendor/autoload.php';
4 4
 
5 5
 use Matecat\SimpleS3\Components\Cache\RedisCache;
6 6
 
7
-$config = parse_ini_file(__DIR__.'/../config/credentials.ini');
7
+$config = parse_ini_file(__DIR__ . '/../config/credentials.ini');
8 8
 $s3Client = new Matecat\SimpleS3\Client(
9 9
     [
10 10
         'version' => $config['VERSION'],
@@ -30,24 +30,24 @@  discard block
 block discarded – undo
30 30
 echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL . PHP_EOL;
31 31
 
32 32
 $x = microtime(true);
33
-echo 'UPLOAD '. $n . ' ITEMS IN THE BUCKET' . PHP_EOL;
33
+echo 'UPLOAD ' . $n . ' ITEMS IN THE BUCKET' . PHP_EOL;
34 34
 echo '----------------------------------------' . PHP_EOL;
35 35
 
36
-for ($i=0;$i<$n;$i++) {
36
+for ($i = 0; $i < $n; $i++) {
37 37
     $rand = rand(11111111, 99999999);
38 38
     $body = 'lorem ipsum';
39 39
 
40 40
     $s3Client->uploadItemFromBody([
41 41
         'bucket' => 'mauretto78-benchmark-test-bucket',
42
-        'key' => 'folder/'.$rand . '.txt',
42
+        'key' => 'folder/' . $rand . '.txt',
43 43
         'body' => $body
44 44
     ]);
45 45
 }
46 46
 
47
-echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL. PHP_EOL;
47
+echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL . PHP_EOL;
48 48
 
49 49
 $x = microtime(true);
50
-echo 'GET '. $n . ' ITEMS IN THE BUCKET' . PHP_EOL;
50
+echo 'GET ' . $n . ' ITEMS IN THE BUCKET' . PHP_EOL;
51 51
 echo '----------------------------------------' . PHP_EOL;
52 52
 
53 53
 $s3Client->getItemsInABucket([
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     'prefix' => 'folder/',
56 56
 ]);
57 57
 
58
-echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL. PHP_EOL;
58
+echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL . PHP_EOL;
59 59
 
60 60
 $x = microtime(true);
61 61
 echo 'DELETE FOLDER IN THE BUCKET' . PHP_EOL;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     'prefix' => 'folder/',
67 67
 ]);
68 68
 
69
-echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL. PHP_EOL;
69
+echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL . PHP_EOL;
70 70
 
71 71
 $x = microtime(true);
72 72
 echo 'DELETE BUCKET' . PHP_EOL;
@@ -76,4 +76,4 @@  discard block
 block discarded – undo
76 76
     'bucket' => 'mauretto78-benchmark-test-bucket',
77 77
 ]);
78 78
 
79
-echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL. PHP_EOL;
79
+echo 'ELAPSED TIME:' . (microtime(true) - $x) . PHP_EOL . PHP_EOL;
Please login to merge, or discard this patch.
src/Components/Cache/RedisCache.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -172,6 +172,6 @@
 block discarded – undo
172 172
 
173 173
         $fileInfo = File::getPathInfo($item);
174 174
 
175
-        return $fileInfo[ 'dirname' ] . $this->prefixSeparator;
175
+        return $fileInfo['dirname'] . $this->prefixSeparator;
176 176
     }
177 177
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/GetBucketLifeCycleConfiguration.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function handle(array $params = []): Result
32 32
     {
33
-        $bucketName = $params[ 'bucket' ];
33
+        $bucketName = $params['bucket'];
34 34
 
35 35
         try {
36 36
             $result = $this->client->getConn()->getBucketLifecycle([
@@ -54,6 +54,6 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function validateParams(array $params = []): bool
56 56
     {
57
-        return isset($params[ 'bucket' ]);
57
+        return isset($params['bucket']);
58 58
     }
59 59
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/CopyInBatch.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -48,22 +48,22 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function handle(array $params = []): bool
50 50
     {
51
-        if (isset($params[ 'target_bucket' ])) {
52
-            $this->client->createBucketIfItDoesNotExist(['bucket' => $params[ 'target_bucket' ]]);
51
+        if (isset($params['target_bucket'])) {
52
+            $this->client->createBucketIfItDoesNotExist(['bucket' => $params['target_bucket']]);
53 53
         }
54 54
 
55
-        if (empty($params[ 'files' ][ 'source' ])) {
55
+        if (empty($params['files']['source'])) {
56 56
             throw new InvalidArgumentException('source files array cannot be empty.');
57 57
         }
58 58
 
59 59
         $commands     = [];
60 60
         $errors       = [];
61 61
         $targetKeys   = [];
62
-        $targetBucket = (isset($params[ 'target_bucket' ])) ? $params[ 'target_bucket' ] : $params[ 'source_bucket' ];
62
+        $targetBucket = (isset($params['target_bucket'])) ? $params['target_bucket'] : $params['source_bucket'];
63 63
 
64
-        foreach ($params[ 'files' ][ 'source' ] as $key => $file) {
65
-            $targetKey    = (isset($params[ 'files' ][ 'target' ][ $key ])) ? $params[ 'files' ][ 'target' ][ $key ] : $file;
66
-            $sourceBucket = $params[ 'source_bucket' ];
64
+        foreach ($params['files']['source'] as $key => $file) {
65
+            $targetKey    = (isset($params['files']['target'][$key])) ? $params['files']['target'][$key] : $file;
66
+            $sourceBucket = $params['source_bucket'];
67 67
 
68 68
             if ($this->client->hasEncoder()) {
69 69
                 $targetKey = $this->client->getEncoder()->encode($targetKey);
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
             ];
81 81
 
82 82
             if ($this->client->isBucketVersioned(['bucket' => $sourceBucket])) {
83
-                $version                = $this->client->getCurrentItemVersion(['bucket' => $sourceBucket, 'key' => $params[ 'source' ]]);
84
-                $config[ 'CopySource' ] = $copySource . '?versionId=' . $version;
83
+                $version                = $this->client->getCurrentItemVersion(['bucket' => $sourceBucket, 'key' => $params['source']]);
84
+                $config['CopySource'] = $copySource . '?versionId=' . $version;
85 85
             }
86 86
 
87 87
             $commands[] = $this->client->getConn()->getCommand('CopyObject', $config);
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
         try {
91 91
             // Create a pool and provide an optional array of configuration
92 92
             $pool = new CommandPool($this->client->getConn(), $commands, [
93
-                    'concurrency' => (isset($params[ 'concurrency' ])) ? $params[ 'concurrency' ] : 25,
94
-                    'before'      => function (CommandInterface $cmd, $iterKey) {
93
+                    'concurrency' => (isset($params['concurrency'])) ? $params['concurrency'] : 25,
94
+                    'before'      => function(CommandInterface $cmd, $iterKey) {
95 95
                         $this->commandHandlerLogger?->log($this, sprintf('About to send \'%s\'', $iterKey));
96 96
                     },
97 97
                 // Invoke this function for each successful transfer
98
-                    'fulfilled'   => function (
98
+                    'fulfilled'   => function(
99 99
                             ResultInterface $result,
100 100
                             $iterKey
101 101
                     ) use ($targetBucket, $targetKeys) {
102
-                        $this->commandHandlerLogger?->log($this, sprintf('Completed copy of \'%s\'', $targetKeys[ $iterKey ]));
102
+                        $this->commandHandlerLogger?->log($this, sprintf('Completed copy of \'%s\'', $targetKeys[$iterKey]));
103 103
 
104 104
                         if ($this->client->hasCache()) {
105
-                            $this->client->getCache()->set($targetBucket, $targetKeys[ $iterKey ], '');
105
+                            $this->client->getCache()->set($targetBucket, $targetKeys[$iterKey], '');
106 106
                         }
107 107
                     },
108 108
                 // Invoke this function for each failed transfer
109
-                    'rejected'    => function (
109
+                    'rejected'    => function(
110 110
                             AwsException $reason
111 111
                     ) use (&$errors) {
112 112
                         $errors[] = $reason;
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
             $pool->promise()->wait();
122 122
 
123 123
             if (count($errors) === 0) {
124
-                $this->commandHandlerLogger?->log($this, sprintf('Copy in batch from \'%s\' to \'%s\' was succeded without errors', $params[ 'source_bucket' ], $targetBucket));
124
+                $this->commandHandlerLogger?->log($this, sprintf('Copy in batch from \'%s\' to \'%s\' was succeded without errors', $params['source_bucket'], $targetBucket));
125 125
 
126 126
                 return true;
127 127
             }
128 128
 
129
-            $this->commandHandlerLogger?->log($this, sprintf('Something went wrong during copying in batch from \'%s\' to \'%s\'', $params[ 'source_bucket' ], (isset($params[ 'target_bucket' ])) ? $params[ 'target_bucket' ] : $params[ 'source_bucket' ]), 'warning');
129
+            $this->commandHandlerLogger?->log($this, sprintf('Something went wrong during copying in batch from \'%s\' to \'%s\'', $params['source_bucket'], (isset($params['target_bucket'])) ? $params['target_bucket'] : $params['source_bucket']), 'warning');
130 130
 
131 131
             return false;
132 132
         } catch (Exception $e) {
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
     public function validateParams(array $params = []): bool
145 145
     {
146 146
         return (
147
-                isset($params[ 'source_bucket' ]) and
148
-                isset($params[ 'files' ][ 'source' ])
147
+                isset($params['source_bucket']) and
148
+                isset($params['files']['source'])
149 149
         );
150 150
     }
151 151
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/SetBucketVersioning.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function handle(array $params = []): bool
31 31
     {
32
-        $bucketName = $params[ 'bucket' ];
32
+        $bucketName = $params['bucket'];
33 33
         $config     = [
34 34
                 'Bucket'                  => $bucketName,
35 35
                 'VersioningConfiguration' => [
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
                 ],
39 39
         ];
40 40
 
41
-        if (isset($params[ 'md5' ])) {
42
-            $config[ 'ContentMD5' ] = $params[ 'md5' ];
41
+        if (isset($params['md5'])) {
42
+            $config['ContentMD5'] = $params['md5'];
43 43
         }
44 44
 
45
-        if (isset($params[ 'mfa' ])) {
46
-            $config[ 'MFA' ] = $params[ 'mfa' ];
45
+        if (isset($params['mfa'])) {
46
+            $config['MFA'] = $params['mfa'];
47 47
         }
48 48
 
49
-        if (isset($params[ 'mfa_delete' ])) {
50
-            $config[ 'VersioningConfiguration' ][ 'MFADelete' ] = $params[ 'mfa_delete' ];
49
+        if (isset($params['mfa_delete'])) {
50
+            $config['VersioningConfiguration']['MFADelete'] = $params['mfa_delete'];
51 51
         }
52 52
 
53
-        if (isset($params[ 'status' ])) {
54
-            $config[ 'VersioningConfiguration' ][ 'Status' ] = $params[ 'status' ];
53
+        if (isset($params['status'])) {
54
+            $config['VersioningConfiguration']['Status'] = $params['status'];
55 55
         }
56 56
 
57 57
         try {
58 58
             $versioning = $this->client->getConn()->putBucketVersioning($config);
59 59
 
60
-            if (($versioning instanceof ResultInterface) and $versioning[ '@metadata' ][ 'statusCode' ] === 200) {
60
+            if (($versioning instanceof ResultInterface) and $versioning['@metadata']['statusCode'] === 200) {
61 61
                 $this->commandHandlerLogger?->log($this, sprintf('Versioning was successfully enabled for \'%s\' bucket', $bucketName));
62 62
 
63 63
                 return true;
@@ -80,6 +80,6 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function validateParams(array $params = []): bool
82 82
     {
83
-        return isset($params[ 'bucket' ]);
83
+        return isset($params['bucket']);
84 84
     }
85 85
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/UploadItem.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle(array $params = []): bool
42 42
     {
43
-        $bucketName = $params[ 'bucket' ];
44
-        $keyName    = $params[ 'key' ];
45
-        $source     = $params[ 'source' ];
43
+        $bucketName = $params['bucket'];
44
+        $keyName    = $params['key'];
45
+        $source     = $params['source'];
46 46
 
47
-        if (isset($params[ 'bucket_check' ]) and true === $params[ 'bucket_check' ]) {
47
+        if (isset($params['bucket_check']) and true === $params['bucket_check']) {
48 48
             $this->client->createBucketIfItDoesNotExist(['bucket' => $bucketName]);
49 49
         }
50 50
 
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
             throw new InvalidS3NameException(sprintf('%s is not a valid S3 object name. [' . implode(', ', S3ObjectSafeNameValidator::validate($keyName)) . ']', $keyName));
53 53
         }
54 54
 
55
-        if ((isset($params[ 'storage' ]) and false === S3StorageClassNameValidator::isValid($params[ 'storage' ]))) {
56
-            throw new InvalidArgumentException(S3StorageClassNameValidator::validate($params[ 'storage' ])[ 0 ]);
55
+        if ((isset($params['storage']) and false === S3StorageClassNameValidator::isValid($params['storage']))) {
56
+            throw new InvalidArgumentException(S3StorageClassNameValidator::validate($params['storage'])[0]);
57 57
         }
58 58
 
59 59
         if (File::getSize($source) > self::MAX_FILESIZE) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
                 'bucket'  => $bucketName,
65 65
                 'key'     => $keyName,
66 66
                 'body'    => File::open($source),
67
-                'storage' => (isset($params[ 'storage' ])) ? $params[ 'storage' ] : null
67
+                'storage' => (isset($params['storage'])) ? $params['storage'] : null
68 68
         ]);
69 69
     }
70 70
 
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
     public function validateParams(array $params = []): bool
77 77
     {
78 78
         return (
79
-                isset($params[ 'bucket' ]) and
80
-                isset($params[ 'key' ]) and
81
-                isset($params[ 'source' ])
79
+                isset($params['bucket']) and
80
+                isset($params['key']) and
81
+                isset($params['source'])
82 82
         );
83 83
     }
84 84
 
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
                 [
100 100
                         'bucket'          => $bucketName,
101 101
                         'key'             => $keyName,
102
-                        'before_initiate' => function (CommandInterface $command) use ($source, $params, $keyName) {
103
-                            $command[ 'ContentType' ] = File::getMimeType($source);
102
+                        'before_initiate' => function(CommandInterface $command) use ($source, $params, $keyName) {
103
+                            $command['ContentType'] = File::getMimeType($source);
104 104
 
105
-                            if ((isset($params[ 'storage' ]))) {
106
-                                $command[ 'StorageClass' ] = $params[ 'storage' ];
105
+                            if ((isset($params['storage']))) {
106
+                                $command['StorageClass'] = $params['storage'];
107 107
                             }
108 108
 
109
-                            if ((isset($params[ 'Metadata' ]))) {
110
-                                $command[ 'Metadata' ] = $params[ 'meta' ];
109
+                            if ((isset($params['Metadata']))) {
110
+                                $command['Metadata'] = $params['meta'];
111 111
                             }
112 112
 
113
-                            $command[ 'Metadata' ][ 'original_name' ] = File::getBaseName($keyName);
114
-                            $command[ 'MetadataDirective' ]           = 'REPLACE';
113
+                            $command['Metadata']['original_name'] = File::getBaseName($keyName);
114
+                            $command['MetadataDirective']           = 'REPLACE';
115 115
                         }
116 116
                 ]
117 117
         );
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         try {
120 120
             $upload = $uploader->upload();
121 121
 
122
-            if (($upload instanceof ResultInterface) and $upload[ '@metadata' ][ 'statusCode' ] === 200) {
122
+            if (($upload instanceof ResultInterface) and $upload['@metadata']['statusCode'] === 200) {
123 123
                 $this->commandHandlerLogger?->log($this, sprintf('File \'%s\' was successfully uploaded in \'%s\' bucket', $keyName, $bucketName));
124 124
 
125 125
                 return true;
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
             $this->commandHandlerLogger?->log($this, sprintf('Something went wrong during upload of file \'%s\' in \'%s\' bucket', $keyName, $bucketName), 'warning');
129 129
 
130 130
             // update cache
131
-            if ((!isset($params[ 'storage' ])) and $this->client->hasCache()) {
131
+            if ((!isset($params['storage'])) and $this->client->hasCache()) {
132 132
                 $version = null;
133
-                if (isset($upload[ '@metadata' ][ 'headers' ][ 'x-amz-version-id' ])) {
134
-                    $version = $upload[ '@metadata' ][ 'headers' ][ 'x-amz-version-id' ];
133
+                if (isset($upload['@metadata']['headers']['x-amz-version-id'])) {
134
+                    $version = $upload['@metadata']['headers']['x-amz-version-id'];
135 135
                 }
136 136
 
137 137
                 $this->client->getCache()->set($bucketName, $keyName, '', $version);
Please login to merge, or discard this patch.
src/Commands/Handlers/CopyFolder.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function handle(array $params = ['source_bucket' => '', 'source_folder' => '', 'target_bucket' => null, 'target_folder' => '', 'delete_source' => false]): bool
33 33
     {
34
-        $targetBucketName = (isset($params[ 'target_bucket' ])) ? $params[ 'target_bucket' ] : $params[ 'source_bucket' ];
35
-        $targetFolder     = $params[ 'target_folder' ];
36
-        $sourceBucketName = $params[ 'source_bucket' ];
37
-        $sourceFolder     = $params[ 'source_folder' ];
34
+        $targetBucketName = (isset($params['target_bucket'])) ? $params['target_bucket'] : $params['source_bucket'];
35
+        $targetFolder     = $params['target_folder'];
36
+        $sourceBucketName = $params['source_bucket'];
37
+        $sourceFolder     = $params['source_folder'];
38 38
 
39 39
         try {
40 40
             $sourceItems = $this->client->getItemsInABucket([
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                 }
64 64
             }
65 65
 
66
-            if (isset($params[ 'delete_source' ]) and true === $params[ 'delete_source' ]) {
66
+            if (isset($params['delete_source']) and true === $params['delete_source']) {
67 67
                 $deleteSource = $this->client->deleteFolder([
68 68
                         'bucket' => $sourceBucketName,
69 69
                         'prefix' => $sourceFolder,
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
     public function validateParams(array $params = []): bool
91 91
     {
92 92
         return (
93
-                isset($params[ 'target_folder' ]) and
94
-                isset($params[ 'source_bucket' ]) and
95
-                isset($params[ 'source_folder' ])
93
+                isset($params['target_folder']) and
94
+                isset($params['source_bucket']) and
95
+                isset($params['source_folder'])
96 96
         );
97 97
     }
98 98
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/DeleteFolder.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function handle(array $params = []): true
31 31
     {
32
-        $bucketName = $params[ 'bucket' ];
33
-        $prefix     = $params[ 'prefix' ];
32
+        $bucketName = $params['bucket'];
33
+        $prefix     = $params['prefix'];
34 34
 
35 35
         if (false === File::endsWith($prefix, $this->client->getPrefixSeparator())) {
36 36
             $prefix .= $this->client->getPrefixSeparator();
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
     public function validateParams(array $params = []): bool
68 68
     {
69 69
         return (
70
-                isset($params[ 'bucket' ]) and
71
-                isset($params[ 'prefix' ])
70
+                isset($params['bucket']) and
71
+                isset($params['prefix'])
72 72
         );
73 73
     }
74 74
 }
Please login to merge, or discard this patch.
src/Commands/Handlers/DeleteBucketPolicy.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function handle(array $params = []): bool
32 32
     {
33
-        $bucketName = $params[ 'bucket' ];
33
+        $bucketName = $params['bucket'];
34 34
 
35 35
         if (false === $this->client->hasBucket(['bucket' => $bucketName])) {
36 36
             $this->commandHandlerLogger?->log($this, sprintf('Bucket \'%s\' does not exists', $bucketName), 'warning');
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         try {
42 42
             $delete = $this->client->getConn()->deleteBucketPolicy(['Bucket' => $bucketName]);
43 43
 
44
-            if (($delete instanceof ResultInterface) and $delete[ '@metadata' ][ 'statusCode' ] === 204) {
44
+            if (($delete instanceof ResultInterface) and $delete['@metadata']['statusCode'] === 204) {
45 45
                 $this->commandHandlerLogger?->log($this, sprintf('Policy was successfully deleted for bucket \'%s\'', $bucketName));
46 46
 
47 47
                 return true;
@@ -64,6 +64,6 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function validateParams(array $params = []): bool
66 66
     {
67
-        return (isset($params[ 'bucket' ]));
67
+        return (isset($params['bucket']));
68 68
     }
69 69
 }
Please login to merge, or discard this patch.