php-opencloud /
openstack
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace OpenStack\ObjectStore\v1\Models; |
||
| 4 | |||
| 5 | use GuzzleHttp\Psr7\Uri; |
||
| 6 | use OpenStack\Common\Transport\Utils; |
||
| 7 | use Psr\Http\Message\ResponseInterface; |
||
| 8 | use Psr\Http\Message\StreamInterface; |
||
| 9 | use OpenStack\Common\Resource\OperatorResource; |
||
| 10 | use OpenStack\Common\Resource\Creatable; |
||
| 11 | use OpenStack\Common\Resource\Deletable; |
||
| 12 | use OpenStack\Common\Resource\HasMetadata; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @property \OpenStack\ObjectStore\v1\Api $api |
||
| 16 | */ |
||
| 17 | class Object extends OperatorResource implements Creatable, Deletable, HasMetadata |
||
| 18 | { |
||
| 19 | use MetadataTrait; |
||
| 20 | |||
| 21 | const METADATA_PREFIX = 'X-Object-Meta-'; |
||
| 22 | |||
| 23 | /** @var string */ |
||
| 24 | public $containerName; |
||
| 25 | |||
| 26 | /** @var string */ |
||
| 27 | public $name; |
||
| 28 | |||
| 29 | /** @var string */ |
||
| 30 | public $hash; |
||
| 31 | |||
| 32 | /** @var string */ |
||
| 33 | public $contentType; |
||
| 34 | |||
| 35 | /** @var int */ |
||
| 36 | public $contentLength; |
||
| 37 | |||
| 38 | /** @var string */ |
||
| 39 | public $lastModified; |
||
| 40 | |||
| 41 | /** @var array */ |
||
| 42 | public $metadata; |
||
| 43 | |||
| 44 | protected $markerKey = 'name'; |
||
| 45 | protected $aliases = ['bytes' => 'contentLength']; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | 5 | */ |
|
| 50 | public function populateFromResponse(ResponseInterface $response): self |
||
| 51 | 5 | { |
|
| 52 | parent::populateFromResponse($response); |
||
| 53 | 5 | ||
| 54 | 5 | $this->populateHeaders($response); |
|
| 55 | 5 | ||
| 56 | 5 | return $this; |
|
| 57 | 5 | } |
|
| 58 | 5 | ||
| 59 | /** |
||
| 60 | * @param ResponseInterface $response |
||
| 61 | * |
||
| 62 | * @return $this |
||
| 63 | */ |
||
| 64 | View Code Duplication | private function populateHeaders(ResponseInterface $response): self |
|
|
0 ignored issues
–
show
|
|||
| 65 | 1 | { |
|
| 66 | $this->hash = $response->getHeaderLine('ETag'); |
||
| 67 | 1 | $this->contentLength = $response->getHeaderLine('Content-Length'); |
|
|
0 ignored issues
–
show
The property
$contentLength was declared of type integer, but $response->getHeaderLine('Content-Length') is of type string. Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
| 68 | $this->lastModified = $response->getHeaderLine('Last-Modified'); |
||
| 69 | $this->contentType = $response->getHeaderLine('Content-Type'); |
||
| 70 | $this->metadata = $this->parseMetadata($response); |
||
| 71 | |||
| 72 | return $this; |
||
| 73 | } |
||
| 74 | |||
| 75 | 3 | /** |
|
| 76 | * Retrieves the public URI for this resource. |
||
| 77 | 3 | * |
|
| 78 | 3 | * @return \GuzzleHttp\Psr7\Uri |
|
| 79 | */ |
||
| 80 | public function getPublicUri(): Uri |
||
| 81 | { |
||
| 82 | return Utils::addPaths($this->getHttpBaseUrl(), $this->containerName, $this->name); |
||
| 83 | } |
||
| 84 | 4 | ||
| 85 | /** |
||
| 86 | 4 | * @param array $data {@see \OpenStack\ObjectStore\v1\Api::putObject} |
|
| 87 | 2 | * |
|
| 88 | 2 | * @return $this |
|
| 89 | */ |
||
| 90 | public function create(array $data): Creatable |
||
| 91 | { |
||
| 92 | $response = $this->execute($this->api->putObject(), $data + ['containerName' => $this->containerName]); |
||
| 93 | return $this->populateFromResponse($response); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | 1 | */ |
|
| 99 | public function retrieve() |
||
| 100 | 1 | { |
|
| 101 | 1 | $response = $this->executeWithState($this->api->headObject()); |
|
| 102 | $this->populateFromResponse($response); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * This call will perform a `GET` HTTP request for the given object and return back its content in the form of a |
||
| 107 | 1 | * Guzzle Stream object. Downloading an object will transfer all of the content for an object, and is therefore |
|
| 108 | * distinct from fetching its metadata (a `HEAD` request). The body of an object is not fetched by default to |
||
| 109 | 1 | * improve performance when handling large objects. |
|
| 110 | 1 | * |
|
| 111 | * @param array $data {@see \OpenStack\ObjectStore\v1\Api::getObject} |
||
| 112 | * |
||
| 113 | * @return StreamInterface |
||
| 114 | */ |
||
| 115 | 1 | ||
| 116 | public function download(array $data = []): StreamInterface |
||
| 117 | 1 | { |
|
| 118 | 1 | $data += ['name' => $this->name, 'containerName' => $this->containerName]; |
|
| 119 | 1 | ||
| 120 | /** @var ResponseInterface $response */ |
||
| 121 | $response = $this->execute($this->api->getObject(), $data); |
||
| 122 | $this->populateHeaders($response); |
||
| 123 | |||
| 124 | 1 | return $response->getBody(); |
|
| 125 | } |
||
| 126 | |||
| 127 | 1 | /** |
|
| 128 | 1 | * {@inheritdoc} |
|
| 129 | 1 | */ |
|
| 130 | 1 | public function delete() |
|
| 131 | { |
||
| 132 | 1 | $this->executeWithState($this->api->deleteObject()); |
|
| 133 | 1 | } |
|
| 134 | |||
| 135 | /** |
||
| 136 | * @param array $options {@see \OpenStack\ObjectStore\v1\Api::copyObject} |
||
| 137 | */ |
||
| 138 | public function copy(array $options) |
||
| 139 | 1 | { |
|
| 140 | $options += ['name' => $this->name, 'containerName' => $this->containerName]; |
||
| 141 | $this->execute($this->api->copyObject(), $options); |
||
| 142 | 1 | } |
|
| 143 | 1 | ||
| 144 | 1 | /** |
|
| 145 | 1 | * {@inheritdoc} |
|
| 146 | */ |
||
| 147 | 1 | View Code Duplication | public function mergeMetadata(array $metadata) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 148 | 1 | { |
|
| 149 | $options = [ |
||
| 150 | 'containerName' => $this->containerName, |
||
| 151 | 'name' => $this->name, |
||
| 152 | 'metadata' => array_merge($metadata, $this->getMetadata()), |
||
| 153 | ]; |
||
| 154 | 2 | ||
| 155 | $response = $this->execute($this->api->postObject(), $options); |
||
| 156 | 2 | $this->metadata = $this->parseMetadata($response); |
|
| 157 | 2 | } |
|
| 158 | |||
| 159 | /** |
||
| 160 | * {@inheritdoc} |
||
| 161 | */ |
||
| 162 | View Code Duplication | public function resetMetadata(array $metadata) |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 163 | { |
||
| 164 | $options = [ |
||
| 165 | 'containerName' => $this->containerName, |
||
| 166 | 'name' => $this->name, |
||
| 167 | 'metadata' => $metadata, |
||
| 168 | ]; |
||
| 169 | |||
| 170 | $response = $this->execute($this->api->postObject(), $options); |
||
| 171 | $this->metadata = $this->parseMetadata($response); |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * {@inheritdoc} |
||
| 176 | */ |
||
| 177 | public function getMetadata(): array |
||
| 178 | { |
||
| 179 | $response = $this->executeWithState($this->api->headObject()); |
||
| 180 | return $this->parseMetadata($response); |
||
| 181 | } |
||
| 182 | } |
||
| 183 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.