| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 70.59% |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class OpenItem extends CommandHandler |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Open an item and return the content of it. |
||
| 22 | * |
||
| 23 | * @param array $params |
||
| 24 | * |
||
| 25 | * @return string|null |
||
| 26 | * @throws Exception |
||
| 27 | */ |
||
| 28 | 2 | public function handle(array $params = []): ?string |
|
| 29 | { |
||
| 30 | 2 | $bucketName = $params[ 'bucket' ]; |
|
| 31 | 2 | $keyName = $params[ 'key' ]; |
|
| 32 | |||
| 33 | try { |
||
| 34 | 2 | $url = $this->client->getPublicItemLink(['bucket' => $bucketName, 'key' => $keyName]); |
|
| 35 | 2 | $content = File::loadFile($url, $this->client->hasSslVerify()); |
|
| 36 | |||
| 37 | 2 | if (false === $content) { |
|
| 38 | $this->commandHandlerLogger?->log($this, sprintf('Something went wrong during getting content of \'%s\' item from \'%s\' bucket', $keyName, $bucketName), 'warning'); |
||
| 39 | |||
| 40 | return null; |
||
| 41 | } |
||
| 42 | |||
| 43 | 2 | $this->commandHandlerLogger?->log($this, sprintf('Content from \'%s\' item was successfully obtained from \'%s\' bucket', $keyName, $bucketName)); |
|
| 44 | |||
| 45 | 2 | return $content; |
|
|
|
|||
| 46 | } catch (Exception $e) { |
||
| 47 | $this->commandHandlerLogger?->logExceptionAndReturnFalse($e); |
||
| 48 | |||
| 49 | throw $e; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param array $params |
||
| 55 | * |
||
| 56 | * @return bool |
||
| 57 | */ |
||
| 58 | 2 | public function validateParams(array $params = []): bool |
|
| 63 | 2 | ); |
|
| 64 | } |
||
| 66 |