1 | <?php |
||||
2 | |||||
3 | namespace Bavix\CupKit\Storage; |
||||
4 | |||||
5 | use Bavix\CupKit\CupKitServiceProvider; |
||||
6 | use Illuminate\Foundation\Application; |
||||
7 | use League\Flysystem\Adapter\AbstractAdapter; |
||||
8 | use League\Flysystem\Config; |
||||
9 | use Bavix\CupKit\Client; |
||||
10 | |||||
11 | class CupAdapter extends AbstractAdapter |
||||
12 | { |
||||
13 | |||||
14 | /** |
||||
15 | * @var Client |
||||
16 | */ |
||||
17 | protected $cup; |
||||
18 | |||||
19 | /** |
||||
20 | * @var Application |
||||
21 | */ |
||||
22 | protected $app; |
||||
23 | |||||
24 | /** |
||||
25 | * @var array |
||||
26 | */ |
||||
27 | protected $config; |
||||
28 | |||||
29 | /** |
||||
30 | * CupAdapter constructor. |
||||
31 | * @param Application $app |
||||
32 | * @param array $config |
||||
33 | */ |
||||
34 | public function __construct(Application $app, array $config) |
||||
35 | { |
||||
36 | $this->app = $app; |
||||
37 | $this->config = $config; |
||||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * @return Client |
||||
42 | */ |
||||
43 | protected function cup(): Client |
||||
44 | { |
||||
45 | if (!$this->cup) { |
||||
46 | $this->cup = app(CupKitServiceProvider::SINGLETON_CLIENT); |
||||
0 ignored issues
–
show
|
|||||
47 | } |
||||
48 | return $this->cup; |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * @param string $path |
||||
53 | * @return array |
||||
54 | */ |
||||
55 | protected function parse(string $path): array |
||||
56 | { |
||||
57 | return \explode('.', $path); |
||||
58 | } |
||||
59 | |||||
60 | /** |
||||
61 | * {uuid} |
||||
62 | * {uuid}.webp |
||||
63 | * {view}.{uuid} |
||||
64 | * {view}.{uuid}.webp |
||||
65 | * |
||||
66 | * @param $path |
||||
67 | * @return string |
||||
68 | */ |
||||
69 | public function getUrl($path): string |
||||
70 | { |
||||
71 | return $path; |
||||
72 | } |
||||
73 | |||||
74 | /** |
||||
75 | * @param string $path |
||||
76 | * @param string $contents |
||||
77 | * @param Config $config |
||||
78 | * @return array|false |
||||
79 | */ |
||||
80 | public function write($path, $contents, Config $config) |
||||
81 | { |
||||
82 | return $this->writeStream($path, \stream_context_create($contents), $config); |
||||
0 ignored issues
–
show
$contents of type string is incompatible with the type array|null expected by parameter $options of stream_context_create() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
83 | } |
||||
84 | |||||
85 | /** |
||||
86 | * @param string $path |
||||
87 | * @param resource $resource |
||||
88 | * @param Config $config |
||||
89 | * @return array|false |
||||
90 | */ |
||||
91 | public function writeStream($path, $resource, Config $config) |
||||
92 | { |
||||
93 | [$bucket, $uuid] = $this->parse($path); |
||||
94 | return $this->cup()->createImage($bucket, $resource, $uuid); |
||||
95 | } |
||||
96 | |||||
97 | /** |
||||
98 | * @param string $path |
||||
99 | * @param string $contents |
||||
100 | * @param Config $config |
||||
101 | * @return array|bool|false |
||||
102 | */ |
||||
103 | public function update($path, $contents, Config $config) |
||||
104 | { |
||||
105 | return false; |
||||
106 | } |
||||
107 | |||||
108 | /** |
||||
109 | * @param string $path |
||||
110 | * @param resource $resource |
||||
111 | * @param Config $config |
||||
112 | * @return array|bool|false |
||||
113 | */ |
||||
114 | public function updateStream($path, $resource, Config $config) |
||||
115 | { |
||||
116 | return false; |
||||
117 | } |
||||
118 | |||||
119 | /** |
||||
120 | * @param string $path |
||||
121 | * @param string $newpath |
||||
122 | * @return bool |
||||
123 | */ |
||||
124 | public function rename($path, $newpath): bool |
||||
125 | { |
||||
126 | return false; |
||||
127 | } |
||||
128 | |||||
129 | /** |
||||
130 | * @param string $path |
||||
131 | * @param string $newpath |
||||
132 | * @return bool |
||||
133 | */ |
||||
134 | public function copy($path, $newpath): bool |
||||
135 | { |
||||
136 | return false; |
||||
137 | } |
||||
138 | |||||
139 | /** |
||||
140 | * @param string $path |
||||
141 | * @return bool |
||||
142 | */ |
||||
143 | public function delete($path): bool |
||||
144 | { |
||||
145 | return $this->cup()->dropImage(...$this->parse($path)); |
||||
146 | } |
||||
147 | |||||
148 | /** |
||||
149 | * @param string $dirname |
||||
150 | * @return bool |
||||
151 | */ |
||||
152 | public function deleteDir($dirname): bool |
||||
153 | { |
||||
154 | return $this->cup()->dropBucket($dirname); |
||||
155 | } |
||||
156 | |||||
157 | /** |
||||
158 | * @param string $dirname |
||||
159 | * @param Config $config |
||||
160 | * @return array|false |
||||
161 | */ |
||||
162 | public function createDir($dirname, Config $config) |
||||
163 | { |
||||
164 | return $this->cup()->createBucket($dirname); |
||||
165 | } |
||||
166 | |||||
167 | /** |
||||
168 | * @param string $path |
||||
169 | * @param string $visibility |
||||
170 | * @return array|bool|false |
||||
171 | */ |
||||
172 | public function setVisibility($path, $visibility) |
||||
173 | { |
||||
174 | return false; |
||||
175 | } |
||||
176 | |||||
177 | /** |
||||
178 | * @param string $path |
||||
179 | * @return bool |
||||
180 | */ |
||||
181 | public function has($path): bool |
||||
182 | { |
||||
183 | try { |
||||
184 | $this->cup()->getImage(...$this->parse($path)); |
||||
185 | return true; |
||||
186 | } catch (\Throwable $throwable) { |
||||
187 | return false; |
||||
188 | } |
||||
189 | } |
||||
190 | |||||
191 | /** |
||||
192 | * @param string $path |
||||
193 | * @return array|bool|false |
||||
194 | */ |
||||
195 | public function read($path) |
||||
196 | { |
||||
197 | return false; |
||||
198 | } |
||||
199 | |||||
200 | /** |
||||
201 | * @param string $path |
||||
202 | * @return array|bool|false |
||||
203 | */ |
||||
204 | public function readStream($path) |
||||
205 | { |
||||
206 | return false; |
||||
207 | } |
||||
208 | |||||
209 | /** |
||||
210 | * @param string $directory |
||||
211 | * @param bool $recursive |
||||
212 | * @return array |
||||
213 | */ |
||||
214 | public function listContents($directory = '', $recursive = false) |
||||
215 | { |
||||
216 | return []; |
||||
217 | } |
||||
218 | |||||
219 | /** |
||||
220 | * @param string $path |
||||
221 | * @return array|bool|false |
||||
222 | */ |
||||
223 | public function getMetadata($path) |
||||
224 | { |
||||
225 | return false; |
||||
226 | } |
||||
227 | |||||
228 | /** |
||||
229 | * @param string $path |
||||
230 | * @return array|bool|false |
||||
231 | */ |
||||
232 | public function getSize($path) |
||||
233 | { |
||||
234 | return false; |
||||
235 | } |
||||
236 | |||||
237 | /** |
||||
238 | * @param string $path |
||||
239 | * @return array|bool|false |
||||
240 | */ |
||||
241 | public function getMimetype($path) |
||||
242 | { |
||||
243 | return false; |
||||
244 | } |
||||
245 | |||||
246 | /** |
||||
247 | * @param string $path |
||||
248 | * @return array|bool|false |
||||
249 | */ |
||||
250 | public function getTimestamp($path) |
||||
251 | { |
||||
252 | return false; |
||||
253 | } |
||||
254 | |||||
255 | /** |
||||
256 | * @param string $path |
||||
257 | * @return array|bool|false |
||||
258 | */ |
||||
259 | public function getVisibility($path) |
||||
260 | { |
||||
261 | return false; |
||||
262 | } |
||||
263 | |||||
264 | } |
||||
265 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.