1 | <?php |
||
19 | class Balloon implements StorageInterface |
||
20 | { |
||
21 | /** |
||
22 | * Logger. |
||
23 | * |
||
24 | * @var LoggerInterface |
||
25 | */ |
||
26 | protected $logger; |
||
27 | |||
28 | /** |
||
29 | * Balloon. |
||
30 | * |
||
31 | * @var ApiClient |
||
32 | */ |
||
33 | protected $balloon; |
||
34 | |||
35 | /** |
||
36 | * Collection ID. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $collection; |
||
41 | |||
42 | /** |
||
43 | * Init storage. |
||
44 | */ |
||
45 | 7 | public function __construct(ApiClient $balloon, LoggerInterface $logger, ?ObjectIdInterface $collection = null) |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 1 | public function openReadStreams(string $pattern): Generator |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 2 | public function openReadStream(string $file) |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | 1 | public function openWriteStream(string $file) |
|
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | 3 | public function syncWriteStream($stream, string $file): bool |
|
118 | { |
||
119 | 3 | $size = fstat($stream)['size']; |
|
120 | |||
121 | 3 | if ($size === 0) { |
|
122 | 1 | $this->logger->info('skip file of 0 bytes upload to balloon', [ |
|
123 | 1 | 'category' => get_class($this), |
|
124 | ]); |
||
125 | |||
126 | 1 | return true; |
|
127 | } |
||
128 | |||
129 | 2 | $chunks = $size / 8388608; |
|
130 | 2 | if ($chunks < 1) { |
|
131 | 1 | $chunks = 1; |
|
132 | } |
||
133 | |||
134 | 2 | $this->logger->info('upload file to balloon as ['.$file.']', [ |
|
135 | 2 | 'category' => get_class($this), |
|
136 | ]); |
||
137 | |||
138 | $query = [ |
||
139 | 2 | 'collection' => $this->collection, |
|
140 | 2 | 'name' => $file, |
|
141 | 2 | 'size' => $size, |
|
142 | 2 | 'chunks' => $chunks, |
|
143 | ]; |
||
144 | |||
145 | 2 | rewind($stream); |
|
146 | |||
147 | 2 | $index = 0; |
|
148 | 2 | $session = null; |
|
149 | 2 | while (!feof($stream) && $index !== $chunks) { |
|
150 | 2 | $buffer = fread($stream, 8388608); |
|
151 | $query += [ |
||
152 | 2 | 'index' => $index, |
|
153 | 2 | 'session' => $session, |
|
154 | ]; |
||
155 | |||
156 | 2 | $this->logger->debug('upload file chunk ['.$index.'/'.$chunks.'] of total ['.$size.'] bytes to balloon', [ |
|
157 | 2 | 'category' => get_class($this), |
|
158 | ]); |
||
159 | 2 | $result = $this->balloon->restCall('/api/v2/files/chunk', $query, 'PUT'); |
|
160 | |||
161 | 2 | ++$index; |
|
162 | 2 | $session = $result['session']; |
|
163 | } |
||
164 | |||
165 | 2 | return fclose($stream); |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * Search balloon for files matching pattern. |
||
170 | */ |
||
171 | 1 | protected function getFiles(string $pattern): array |
|
192 | } |
||
193 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.