Skip to content

Commit f7f9f00

Browse files
committed
more scrutinizer fixes
1 parent 0c17c3d commit f7f9f00

File tree

5 files changed

+90
-28
lines changed

5 files changed

+90
-28
lines changed

Embed/FastImage.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*
1111
* MIT Licensed
1212
* @version 0.1
13+
*
14+
* Modified for Embed library by Oscar Otero (https://github.com/oscarotero/Embed)
1315
*/
1416

1517
namespace Embed;
@@ -29,6 +31,11 @@ public function __construct($uri = null)
2931
}
3032
}
3133

34+
/**
35+
* Opens an image stream
36+
*
37+
* @param string $uri
38+
*/
3239
public function load($uri)
3340
{
3441
if ($this->handle) {
@@ -48,21 +55,37 @@ public function load($uri)
4855
}
4956
}
5057

58+
/**
59+
* Closes the stream
60+
*/
5161
public function close()
5262
{
53-
if ($this->handle) fclose($this->handle);
63+
if ($this->handle) {
64+
fclose($this->handle);
65+
}
5466
}
5567

68+
/**
69+
* Gets the image size
70+
*
71+
* @return array|false
72+
*/
5673
public function getSize()
5774
{
5875
$this->strpos = 0;
76+
5977
if ($this->getType() && ($size = $this->parseSize())) {
6078
return array_values($size);
6179
}
6280

6381
return false;
6482
}
6583

84+
/**
85+
* Gets the image type
86+
*
87+
* @return string|false
88+
*/
6689
public function getType()
6790
{
6891
$this->strpos = 0;
@@ -88,6 +111,11 @@ public function getType()
88111
return $this->type;
89112
}
90113

114+
/**
115+
* Parses the image type
116+
*
117+
* @return array|null
118+
*/
91119
private function parseSize()
92120
{
93121
$this->strpos = 0;
@@ -106,20 +134,35 @@ private function parseSize()
106134
return null;
107135
}
108136

137+
/**
138+
* Parses the image size for PNG
139+
*
140+
* @return array
141+
*/
109142
private function parseSizeForPNG()
110143
{
111144
$chars = $this->getChars(25);
112145

113146
return unpack("N*", substr($chars, 16, 8));
114147
}
115148

149+
/**
150+
* Parses the image size for GIF
151+
*
152+
* @return array
153+
*/
116154
private function parseSizeForGIF()
117155
{
118156
$chars = $this->getChars(11);
119157

120158
return unpack("S*", substr($chars, 6, 4));
121159
}
122160

161+
/**
162+
* Parses the image size for BMP
163+
*
164+
* @return array
165+
*/
123166
private function parseSizeForBMP()
124167
{
125168
$chars = $this->getChars(29);
@@ -129,6 +172,11 @@ private function parseSizeForBMP()
129172
return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
130173
}
131174

175+
/**
176+
* Parses the image size for JPEG
177+
*
178+
* @return array
179+
*/
132180
private function parseSizeForJPEG()
133181
{
134182
$state = null;
@@ -179,6 +227,13 @@ private function parseSizeForJPEG()
179227
}
180228
}
181229

230+
/**
231+
* Gets the stream characters until a specific position
232+
*
233+
* @param integer $n The end position of characters
234+
*
235+
* @return false|string
236+
*/
182237
private function getChars($n)
183238
{
184239
$response = null;
@@ -206,6 +261,11 @@ private function getChars($n)
206261
return mb_convert_encoding($result, "8BIT");
207262
}
208263

264+
/**
265+
* Returns the current byte
266+
*
267+
* @return false|string
268+
*/
209269
private function getByte()
210270
{
211271
$c = $this->getChars(1);
@@ -214,18 +274,30 @@ private function getByte()
214274
return reset($b);
215275
}
216276

277+
/**
278+
* Returns an integer
279+
*
280+
* @return integer
281+
*/
217282
private function readInt($str)
218283
{
219284
$size = unpack("C*", $str);
220285

221-
return ($size[1] << 8) + $size[2];
286+
return ($size[1] << 8) + $size[2];
222287
}
223288

224289
public function __destruct()
225290
{
226291
$this->close();
227292
}
228293

294+
/**
295+
* Sort an array of images by their size
296+
*
297+
* @param array $images
298+
*
299+
* @return array
300+
*/
229301
public static function sortImagesBySize(array $images)
230302
{
231303
if (count($images) < 2) {

Embed/Providers/OpenGraph.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,19 @@ public function getType()
7676
public function getCode()
7777
{
7878
if ($this->has('video')) {
79-
if (($videoPath = parse_url($this->get('video'), PHP_URL_PATH))) {
80-
switch (pathinfo($videoPath, PATHINFO_EXTENSION)) {
81-
case 'swf':
82-
return Viewers::flash($this->get('video'), $this->getWidth(), $this->getHeight());
83-
84-
case 'mp4':
85-
case 'ogg':
86-
case 'ogv':
87-
case 'webm':
88-
$image = $this->getImage();
89-
90-
if (is_array($image)) {
91-
$image = current($image);
92-
}
93-
94-
return Viewers::videoHtml($image, $this->get('video'), $this->getWidth(), $this->getHeight());
95-
}
79+
if (!($videoPath = parse_url($this->get('video'), PHP_URL_PATH)) || !($type = pathinfo($videoPath, PATHINFO_EXTENSION))) {
80+
$type = $this->get('video:type');
9681
}
97-
98-
switch ($this->get('video:type')) {
82+
83+
switch ($type) {
84+
case 'swf':
9985
case 'application/x-shockwave-flash':
10086
return Viewers::flash($this->get('video'), $this->getWidth(), $this->getHeight());
10187

88+
case 'mp4':
89+
case 'ogg':
90+
case 'ogv':
91+
case 'webm':
10292
case 'application/mp4':
10393
case 'video/mp4':
10494
case 'video/ogg':

Embed/Providers/Provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function set($name, $value = null)
2929
* @param null|string $name Value name
3030
* @param null|string $subname A subvalue name
3131
*
32-
* @return string/null
32+
* @return string|null
3333
*/
3434
public function get($name = null, $subname = null)
3535
{

Embed/RequestResolvers/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getRequestInfo()
112112
*
113113
* @param string $name Parameter name
114114
*
115-
* @return array/string The result info
115+
* @return array|string The result info
116116
*/
117117
protected function getResult($name)
118118
{

Embed/Url.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ public function getUrl()
4545
/**
4646
* Check if the url match with a specific pattern. The patterns only accepts * and ?
4747
*
48-
* @param string/array $pattern The pattern or an array with various patterns
48+
* @param string|array $patterns The pattern or an array with various patterns
4949
*
5050
* @return boolean True if the url match, false if not
5151
*/
52-
public function match($pattern)
52+
public function match($patterns)
5353
{
5454
$url = $this->getUrl();
5555

56-
if (!is_array($pattern)) {
57-
$pattern = array($pattern);
56+
if (!is_array($patterns)) {
57+
$patterns = array($patterns);
5858
}
5959

60-
foreach ($pattern as $pattern) {
60+
foreach ($patterns as $pattern) {
6161
$pattern = str_replace(array('\\*', '\\?'), array('.+', '?'), preg_quote($pattern, '|'));
6262

6363
if (preg_match('|^'.$pattern.'$|i', $url)) {

0 commit comments

Comments
 (0)