PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/google/guzzlehttp/psr7/src/UploadedFile.php +23 -23 1.2.6 → 1.4.2 View file →
@@ -1,16 +1,16 @@
1 1 <?php
2 2
3 3 declare (strict_types=1);
4 -namespace Dudlewebs\WPMCS\GuzzleHttp\Psr7;
4 +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7;
5 5
6 6 use InvalidArgumentException;
7 -use Dudlewebs\WPMCS\Psr\Http\Message\StreamInterface;
8 -use Dudlewebs\WPMCS\Psr\Http\Message\UploadedFileInterface;
7 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\StreamInterface;
8 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\UploadedFileInterface;
9 9 use RuntimeException;
10 10 class UploadedFile implements UploadedFileInterface
11 11 {
12 - private const ERRORS = [\UPLOAD_ERR_OK, \UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_EXTENSION];
12 + private const ERROR_MAP = [\UPLOAD_ERR_OK => 'UPLOAD_ERR_OK', \UPLOAD_ERR_INI_SIZE => 'UPLOAD_ERR_INI_SIZE', \UPLOAD_ERR_FORM_SIZE => 'UPLOAD_ERR_FORM_SIZE', \UPLOAD_ERR_PARTIAL => 'UPLOAD_ERR_PARTIAL', \UPLOAD_ERR_NO_FILE => 'UPLOAD_ERR_NO_FILE', \UPLOAD_ERR_NO_TMP_DIR => 'UPLOAD_ERR_NO_TMP_DIR', \UPLOAD_ERR_CANT_WRITE => 'UPLOAD_ERR_CANT_WRITE', \UPLOAD_ERR_EXTENSION => 'UPLOAD_ERR_EXTENSION'];
13 13 /**
14 14 * @var string|null
15 15 */
16 16 private $clientFilename;
@@ -57,13 +57,13 @@
57 57 * @param StreamInterface|string|resource $streamOrFile
58 58 *
59 59 * @throws InvalidArgumentException
60 60 */
61 - private function setStreamOrFile($streamOrFile): void
61 + private function setStreamOrFile($streamOrFile) : void
62 62 {
63 - if (is_string($streamOrFile)) {
63 + if (\is_string($streamOrFile)) {
64 64 $this->file = $streamOrFile;
65 - } elseif (is_resource($streamOrFile)) {
65 + } elseif (\is_resource($streamOrFile)) {
66 66 $this->stream = new Stream($streamOrFile);
67 67 } elseif ($streamOrFile instanceof StreamInterface) {
68 68 $this->stream = $streamOrFile;
69 69 } else {
@@ -72,27 +72,27 @@
72 72 }
73 73 /**
74 74 * @throws InvalidArgumentException
75 75 */
76 - private function setError(int $error): void
76 + private function setError(int $error) : void
77 77 {
78 - if (\false === in_array($error, UploadedFile::ERRORS, \true)) {
78 + if (!isset(UploadedFile::ERROR_MAP[$error])) {
79 79 throw new InvalidArgumentException('Invalid error status for UploadedFile');
80 80 }
81 81 $this->error = $error;
82 82 }
83 - private static function isStringNotEmpty($param): bool
83 + private static function isStringNotEmpty($param) : bool
84 84 {
85 - return is_string($param) && \false === empty($param);
85 + return \is_string($param) && \false === empty($param);
86 86 }
87 87 /**
88 88 * Return true if there is no upload error
89 89 */
90 - private function isOk(): bool
90 + private function isOk() : bool
91 91 {
92 92 return $this->error === \UPLOAD_ERR_OK;
93 93 }
94 - public function isMoved(): bool
94 + public function isMoved() : bool
95 95 {
96 96 return $this->moved;
97 97 }
98 98 /**
@@ -97,18 +97,18 @@
97 97 }
98 98 /**
99 99 * @throws RuntimeException if is moved or not ok
100 100 */
101 - private function validateActive(): void
101 + private function validateActive() : void
102 102 {
103 103 if (\false === $this->isOk()) {
104 - throw new RuntimeException('Cannot retrieve stream due to upload error');
104 + throw new RuntimeException(\sprintf('Cannot retrieve stream due to upload error (%s)', self::ERROR_MAP[$this->error]));
105 105 }
106 106 if ($this->isMoved()) {
107 107 throw new RuntimeException('Cannot retrieve stream after it has already been moved');
108 108 }
109 109 }
110 - public function getStream(): StreamInterface
110 + public function getStream() : StreamInterface
111 111 {
112 112 $this->validateActive();
113 113 if ($this->stream instanceof StreamInterface) {
114 114 return $this->stream;
@@ -116,9 +116,9 @@
116 116 /** @var string $file */
117 117 $file = $this->file;
118 118 return new LazyOpenStream($file, 'r+');
119 119 }
120 - public function moveTo($targetPath): void
120 + public function moveTo($targetPath) : void
121 121 {
122 122 $this->validateActive();
123 123 if (\false === self::isStringNotEmpty($targetPath)) {
124 124 throw new InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
@@ -123,30 +123,30 @@
123 123 if (\false === self::isStringNotEmpty($targetPath)) {
124 124 throw new InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
125 125 }
126 126 if ($this->file) {
127 - $this->moved = \PHP_SAPI === 'cli' ? rename($this->file, $targetPath) : move_uploaded_file($this->file, $targetPath);
127 + $this->moved = \PHP_SAPI === 'cli' ? \rename($this->file, $targetPath) : \move_uploaded_file($this->file, $targetPath);
128 128 } else {
129 129 Utils::copyToStream($this->getStream(), new LazyOpenStream($targetPath, 'w'));
130 130 $this->moved = \true;
131 131 }
132 132 if (\false === $this->moved) {
133 - throw new RuntimeException(sprintf('Uploaded file could not be moved to %s', $targetPath));
133 + throw new RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
134 134 }
135 135 }
136 - public function getSize(): ?int
136 + public function getSize() : ?int
137 137 {
138 138 return $this->size;
139 139 }
140 - public function getError(): int
140 + public function getError() : int
141 141 {
142 142 return $this->error;
143 143 }
144 - public function getClientFilename(): ?string
144 + public function getClientFilename() : ?string
145 145 {
146 146 return $this->clientFilename;
147 147 }
148 - public function getClientMediaType(): ?string
148 + public function getClientMediaType() : ?string
149 149 {
150 150 return $this->clientMediaType;
151 151 }
152 152 }