@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function handle(array $params = []): mixed |
| 28 | 28 | { |
| 29 | - $bucketName = $params[ 'bucket' ]; |
|
| 29 | + $bucketName = $params['bucket']; |
|
| 30 | 30 | |
| 31 | 31 | $result = $this->client->getConn()->getBucketPolicy([ |
| 32 | 32 | 'Bucket' => $bucketName, |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $this->commandHandlerLogger?->log($this, sprintf('Size of \'%s\' bucket was successfully obtained', $bucketName)); |
| 36 | 36 | |
| 37 | - return (isset($result[ 'Policy' ])) ? json_decode($result[ 'Policy' ]->getContents(), true) : ''; |
|
| 37 | + return (isset($result['Policy'])) ? json_decode($result['Policy']->getContents(), true) : ''; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -44,6 +44,6 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function validateParams(array $params = []): bool |
| 46 | 46 | { |
| 47 | - return isset($params[ 'bucket' ]); |
|
| 47 | + return isset($params['bucket']); |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function handle(array $params = []): UriInterface |
| 31 | 31 | { |
| 32 | - $bucketName = $params[ 'bucket' ]; |
|
| 33 | - $keyName = $params[ 'key' ]; |
|
| 34 | - $expires = (isset($params[ 'expires' ])) ? $params[ 'expires' ] : '+1 hour'; |
|
| 32 | + $bucketName = $params['bucket']; |
|
| 33 | + $keyName = $params['key']; |
|
| 34 | + $expires = (isset($params['expires'])) ? $params['expires'] : '+1 hour'; |
|
| 35 | 35 | |
| 36 | 36 | if ($this->client->hasEncoder()) { |
| 37 | 37 | $keyName = $this->client->getEncoder()->encode($keyName); |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | public function validateParams(array $params = []): bool |
| 64 | 64 | { |
| 65 | 65 | return ( |
| 66 | - isset($params[ 'bucket' ]) and |
|
| 67 | - isset($params[ 'key' ]) |
|
| 66 | + isset($params['bucket']) and |
|
| 67 | + isset($params['key']) |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -26,35 +26,35 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function handle(array $params = []): array |
| 28 | 28 | { |
| 29 | - $bucketName = $params[ 'bucket' ]; |
|
| 29 | + $bucketName = $params['bucket']; |
|
| 30 | 30 | |
| 31 | 31 | try { |
| 32 | 32 | $config = [ |
| 33 | 33 | 'Bucket' => $bucketName, |
| 34 | 34 | ]; |
| 35 | 35 | |
| 36 | - if (isset($params[ 'prefix' ])) { |
|
| 36 | + if (isset($params['prefix'])) { |
|
| 37 | 37 | // add a final slash to prefix |
| 38 | - if (false === File::endsWith($params[ 'prefix' ], $this->client->getPrefixSeparator())) { |
|
| 39 | - $params[ 'prefix' ] .= $this->client->getPrefixSeparator(); |
|
| 38 | + if (false === File::endsWith($params['prefix'], $this->client->getPrefixSeparator())) { |
|
| 39 | + $params['prefix'] .= $this->client->getPrefixSeparator(); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $config[ 'Delimiter' ] = (isset($params[ 'delimiter' ])) ? $params[ 'delimiter' ] : $this->client->getPrefixSeparator(); |
|
| 43 | - $config[ 'Prefix' ] = $params[ 'prefix' ]; |
|
| 42 | + $config['Delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : $this->client->getPrefixSeparator(); |
|
| 43 | + $config['Prefix'] = $params['prefix']; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // 1. If 'exclude-cache' is set, return records always from S3 |
| 47 | - if (isset($params[ 'exclude-cache' ]) and true === $params[ 'exclude-cache' ]) { |
|
| 48 | - return $this->returnItemsFromS3($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
| 47 | + if (isset($params['exclude-cache']) and true === $params['exclude-cache']) { |
|
| 48 | + return $this->returnItemsFromS3($bucketName, $config, (isset($params['hydrate'])) ? $params['hydrate'] : null); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // 2. If the cache is set and there is a prefix, return records from cache |
| 52 | - if ($this->client->hasCache() and isset($config[ 'Prefix' ])) { |
|
| 53 | - return $this->returnItemsFromCache($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
| 52 | + if ($this->client->hasCache() and isset($config['Prefix'])) { |
|
| 53 | + return $this->returnItemsFromCache($bucketName, $config, (isset($params['hydrate'])) ? $params['hydrate'] : null); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // 3. Otherwise, return records from S3 |
| 57 | - return $this->returnVersionedItemsFromS3($bucketName, $config, (isset($params[ 'hydrate' ])) ? $params[ 'hydrate' ] : null); |
|
| 57 | + return $this->returnVersionedItemsFromS3($bucketName, $config, (isset($params['hydrate'])) ? $params['hydrate'] : null); |
|
| 58 | 58 | } catch (S3Exception $e) { |
| 59 | 59 | $this->commandHandlerLogger?->logExceptionAndReturnFalse($e); |
| 60 | 60 | |
@@ -25,18 +25,18 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function handle(array $params = []): int |
| 27 | 27 | { |
| 28 | - $bucketName = $params[ 'bucket' ]; |
|
| 28 | + $bucketName = $params['bucket']; |
|
| 29 | 29 | $size = 0; |
| 30 | 30 | |
| 31 | 31 | $items = $this->client->getItemsInABucket([ |
| 32 | 32 | 'bucket' => $bucketName, |
| 33 | - 'prefix' => (isset($params[ 'prefix' ])) ? $params[ 'prefix' ] : null, |
|
| 33 | + 'prefix' => (isset($params['prefix'])) ? $params['prefix'] : null, |
|
| 34 | 34 | 'hydrate' => true |
| 35 | 35 | ]); |
| 36 | 36 | |
| 37 | 37 | /** @var ResultInterface $item */ |
| 38 | 38 | foreach ($items as $item) { |
| 39 | - $size += $item[ 'ContentLength' ]; |
|
| 39 | + $size += $item['ContentLength']; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $this->commandHandlerLogger?->log($this, sprintf('Size of \'%s\' bucket was successfully obtained', $bucketName)); |
@@ -51,6 +51,6 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function validateParams(array $params = []): bool |
| 53 | 53 | { |
| 54 | - return isset($params[ 'bucket' ]); |
|
| 54 | + return isset($params['bucket']); |
|
| 55 | 55 | } |
| 56 | 56 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $credentials = self::getCredentials($config); |
| 74 | 74 | if (!empty($credentials)) { |
| 75 | - $config[ 'credentials' ] = new Credentials( |
|
| 76 | - $credentials[ 'key' ], |
|
| 77 | - $credentials[ 'secret' ], |
|
| 78 | - $credentials[ 'token' ] |
|
| 75 | + $config['credentials'] = new Credentials( |
|
| 76 | + $credentials['key'], |
|
| 77 | + $credentials['secret'], |
|
| 78 | + $credentials['token'] |
|
| 79 | 79 | ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Temp fix: suppressing PHP < 8.1 warnings |
| 83 | - $config[ 'suppress_php_deprecation_warning' ] = true; |
|
| 83 | + $config['suppress_php_deprecation_warning'] = true; |
|
| 84 | 84 | |
| 85 | 85 | return $config; |
| 86 | 86 | } |
@@ -129,31 +129,31 @@ discard block |
||
| 129 | 129 | private static function getCredentials(array $config): array |
| 130 | 130 | { |
| 131 | 131 | // 1. credentials |
| 132 | - if (isset($config[ 'credentials' ][ 'key' ]) and isset($config[ 'credentials' ][ 'secret' ])) { |
|
| 132 | + if (isset($config['credentials']['key']) and isset($config['credentials']['secret'])) { |
|
| 133 | 133 | return [ |
| 134 | - 'key' => $config[ 'credentials' ][ 'key' ], |
|
| 135 | - 'secret' => $config[ 'credentials' ][ 'secret' ], |
|
| 136 | - 'token' => $config[ 'credentials' ][ 'token' ] ?? null |
|
| 134 | + 'key' => $config['credentials']['key'], |
|
| 135 | + 'secret' => $config['credentials']['secret'], |
|
| 136 | + 'token' => $config['credentials']['token'] ?? null |
|
| 137 | 137 | ]; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // 2. IAM |
| 141 | - if (isset($config[ 'iam' ])) { |
|
| 141 | + if (isset($config['iam'])) { |
|
| 142 | 142 | $stsClient = new StsClient([ |
| 143 | - 'profile' => (isset($config[ 'profile' ])) ? $config[ 'profile' ] : 'default', |
|
| 144 | - 'region' => $config[ 'region' ], |
|
| 145 | - 'version' => $config[ 'version' ] |
|
| 143 | + 'profile' => (isset($config['profile'])) ? $config['profile'] : 'default', |
|
| 144 | + 'region' => $config['region'], |
|
| 145 | + 'version' => $config['version'] |
|
| 146 | 146 | ]); |
| 147 | 147 | |
| 148 | 148 | $result = $stsClient->assumeRole([ |
| 149 | - 'RoleArn' => $config[ 'iam' ][ 'arn' ], |
|
| 150 | - 'RoleSessionName' => $config[ 'iam' ][ 'session' ], |
|
| 149 | + 'RoleArn' => $config['iam']['arn'], |
|
| 150 | + 'RoleSessionName' => $config['iam']['session'], |
|
| 151 | 151 | ]); |
| 152 | 152 | |
| 153 | 153 | return [ |
| 154 | - 'key' => $result[ 'Credentials' ][ 'AccessKeyId' ], |
|
| 155 | - 'secret' => $result[ 'Credentials' ][ 'SecretAccessKey' ], |
|
| 156 | - 'token' => isset($result[ 'Credentials' ][ 'SessionToken' ]) ? $result[ 'Credentials' ][ 'SessionToken' ] : null |
|
| 154 | + 'key' => $result['Credentials']['AccessKeyId'], |
|
| 155 | + 'secret' => $result['Credentials']['SecretAccessKey'], |
|
| 156 | + 'token' => isset($result['Credentials']['SessionToken']) ? $result['Credentials']['SessionToken'] : null |
|
| 157 | 157 | ]; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | foreach ($items as $key) { |
| 71 | 71 | $inCache = $this->s3Client->getCache()->search($bucket, $key); |
| 72 | 72 | if (count($inCache) > 0) { |
| 73 | - $index = $this->getDirName($inCache[ 0 ]); |
|
| 73 | + $index = $this->getDirName($inCache[0]); |
|
| 74 | 74 | |
| 75 | 75 | $files = []; |
| 76 | 76 | foreach ($inCache as $item) { |
| 77 | - $files[ $item ] = $this->s3Client->getConn()->doesObjectExist($bucket, $item); |
|
| 77 | + $files[$item] = $this->s3Client->getConn()->doesObjectExist($bucket, $item); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $tableFeed[ $index ] = [ |
|
| 80 | + $tableFeed[$index] = [ |
|
| 81 | 81 | 'count' => count($inCache), |
| 82 | 82 | 'files' => $files, |
| 83 | 83 | 'ttl' => $this->s3Client->getCache()->ttl($bucket, $key), |
@@ -89,17 +89,17 @@ discard block |
||
| 89 | 89 | $table->setHeaders(['prefix', 'count', 'ttl', 'files', 'align']); |
| 90 | 90 | |
| 91 | 91 | foreach ($tableFeed as $prefix => $data) { |
| 92 | - $count = (int)$data[ 'count' ]; |
|
| 92 | + $count = (int)$data['count']; |
|
| 93 | 93 | |
| 94 | - $files = implode(PHP_EOL, array_keys($data[ 'files' ])); |
|
| 95 | - $enabled = implode(PHP_EOL, $data[ 'files' ]); |
|
| 94 | + $files = implode(PHP_EOL, array_keys($data['files'])); |
|
| 95 | + $enabled = implode(PHP_EOL, $data['files']); |
|
| 96 | 96 | $enabled = str_replace('1', '<fg=green>✓</>', $enabled); |
| 97 | 97 | $enabled = str_replace('0', '<fg=red>✗</>', $enabled); |
| 98 | 98 | |
| 99 | 99 | $table->addRow([ |
| 100 | 100 | $prefix, |
| 101 | 101 | $count, |
| 102 | - $data[ 'ttl' ], |
|
| 102 | + $data['ttl'], |
|
| 103 | 103 | $files, |
| 104 | 104 | $enabled |
| 105 | 105 | ]); |
@@ -128,6 +128,6 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | $fileInfo = File::getPathInfo($item); |
| 130 | 130 | |
| 131 | - return $fileInfo[ 'dirname' ] . $this->s3Client->getPrefixSeparator(); |
|
| 131 | + return $fileInfo['dirname'] . $this->s3Client->getPrefixSeparator(); |
|
| 132 | 132 | } |
| 133 | 133 | } |
@@ -60,8 +60,8 @@ |
||
| 60 | 60 | |
| 61 | 61 | try { |
| 62 | 62 | $manager = new Transfer($this->s3Client->getConn(), $src, $dest, [ |
| 63 | - 'before' => function (CommandInterface $command) use ($output, $from, $to) { |
|
| 64 | - $output->writeln('Transferring <fg=green>[' . $command[ 'Key' ] . ']</> from ' . $from . ' to ' . $to); |
|
| 63 | + 'before' => function(CommandInterface $command) use ($output, $from, $to) { |
|
| 64 | + $output->writeln('Transferring <fg=green>[' . $command['Key'] . ']</> from ' . $from . ' to ' . $to); |
|
| 65 | 65 | } |
| 66 | 66 | ]); |
| 67 | 67 | $manager->transfer(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | return $path; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - return self::getPathInfo($path)[ 'basename' ]; |
|
| 56 | + return self::getPathInfo($path)['basename']; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function getExtension(string $filename): ?string |
| 65 | 65 | { |
| 66 | - return self::getPathInfo($filename)[ 'extension' ]; |
|
| 66 | + return self::getPathInfo($filename)['extension']; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $ext = self::getExtension($filename); |
| 157 | 157 | |
| 158 | 158 | if (null !== $ext and array_key_exists($ext, $mime_types)) { |
| 159 | - return $mime_types[ $ext ]; |
|
| 159 | + return $mime_types[$ext]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | return 'application/octet-stream'; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return false|int |
| 179 | 179 | */ |
| 180 | - public static function getSize(string $filename): false|int |
|
| 180 | + public static function getSize(string $filename): false | int |
|
| 181 | 181 | { |
| 182 | 182 | return filesize($filename); |
| 183 | 183 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @return bool|string |
| 190 | 190 | */ |
| 191 | - public static function loadFile(string $url, bool $sslVerify = true): bool|string |
|
| 191 | + public static function loadFile(string $url, bool $sslVerify = true): bool | string |
|
| 192 | 192 | { |
| 193 | 193 | if (function_exists('curl_version')) { |
| 194 | 194 | $ch = curl_init(); |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | */ |
| 124 | 124 | public function __call(string $name, array $args) |
| 125 | 125 | { |
| 126 | - $params = $args[ 0 ] ?? []; |
|
| 126 | + $params = $args[0] ?? []; |
|
| 127 | 127 | |
| 128 | 128 | $commandHandler = 'Matecat\\SimpleS3\\Commands\\Handlers\\' . ucfirst($name); |
| 129 | 129 | |