Skip to content

Commit 35d2f7d

Browse files
committed
more scrutinizer fixes
1 parent f7f9f00 commit 35d2f7d

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

Embed/Adapters/Archive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function getImages()
9999
$images[] = $this->request->getAbsolute($image);
100100
}
101101

102-
if (($files = $this->api->get('files'))) {
102+
if (is_array($files = $this->api->get('files'))) {
103103
foreach ($files as $url => $info) {
104104
if ($info['format'] === 'Thumbnail') {
105105
$images[] = $this->request->getAbsolute($url);

Embed/FastImage.php

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -137,72 +137,70 @@ private function parseSize()
137137
/**
138138
* Parses the image size for PNG
139139
*
140-
* @return array
140+
* @return array|null
141141
*/
142142
private function parseSizeForPNG()
143143
{
144-
$chars = $this->getChars(25);
145-
146-
return unpack("N*", substr($chars, 16, 8));
144+
if (($chars = $this->getChars(25))) {
145+
return unpack("N*", substr($chars, 16, 8));
146+
}
147147
}
148148

149149
/**
150150
* Parses the image size for GIF
151151
*
152-
* @return array
152+
* @return array|null
153153
*/
154154
private function parseSizeForGIF()
155155
{
156-
$chars = $this->getChars(11);
157-
158-
return unpack("S*", substr($chars, 6, 4));
156+
if (($chars = $this->getChars(11))) {
157+
return unpack("S*", substr($chars, 6, 4));
158+
}
159159
}
160160

161161
/**
162162
* Parses the image size for BMP
163163
*
164-
* @return array
164+
* @return array|null
165165
*/
166166
private function parseSizeForBMP()
167167
{
168-
$chars = $this->getChars(29);
169-
$chars = substr($chars, 14, 14);
170-
$type = unpack('C', $chars);
168+
if (($chars = $this->getChars(29))) {
169+
$chars = substr($chars, 14, 14);
170+
$type = unpack('C', $chars);
171171

172-
return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
172+
return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
173+
}
173174
}
174175

175176
/**
176177
* Parses the image size for JPEG
177178
*
178-
* @return array
179+
* @return array|null
179180
*/
180181
private function parseSizeForJPEG()
181182
{
182183
$state = null;
183-
$i = 0;
184+
$skip = 0;
184185

185186
while (true) {
186187
switch ($state) {
187-
default:
188-
$this->getChars(2);
189-
$state = 'started';
190-
break;
191-
192188
case 'started':
193-
$b = $this->getByte();
194-
if ($b === false) return false;
189+
if (($b = $this->getByte()) === false) {
190+
return false;
191+
}
195192

196-
$state = $b == 0xFF ? 'sof' : 'started';
193+
$state = $b === 0xFF ? 'sof' : 'started';
197194
break;
198195

199196
case 'sof':
200197
$b = $this->getByte();
198+
201199
if (in_array($b, range(0xe0, 0xef))) {
202200
$state = 'skipframe';
203201
} elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF)))) {
204202
$state = 'readsize';
205-
} elseif ($b == 0xFF) {
203+
} elseif ($b === 0xFF) {
206204
$state = 'sof';
207205
} else {
208206
$state = 'skipframe';
@@ -223,6 +221,10 @@ private function parseSizeForJPEG()
223221
$c = $this->getChars(7);
224222

225223
return array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
224+
225+
default:
226+
$this->getChars(2);
227+
$state = 'started';
226228
}
227229
}
228230
}
@@ -268,10 +270,13 @@ private function getChars($n)
268270
*/
269271
private function getByte()
270272
{
271-
$c = $this->getChars(1);
272-
$b = unpack("C", $c);
273+
if (($c = $this->getChars(1))) {
274+
$b = unpack("C", $c);
273275

274-
return reset($b);
276+
return reset($b);
277+
}
278+
279+
return false;
275280
}
276281

277282
/**

0 commit comments

Comments
 (0)