Skip to content

Commit d9c352d

Browse files
committed
Fixed bug from scrutinizer
1 parent 50dee0b commit d9c352d

File tree

9 files changed

+47
-35
lines changed

9 files changed

+47
-35
lines changed

Embed/Adapters/Adapter.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
<?php
22
/**
3-
* Base Adapter extended by all adapters
3+
* Base class extended by all adapters
44
*
5-
* Provide default functionalities
5+
* @property $title
6+
* @property $description
7+
* @property $url
8+
* @property $type
9+
* @property $images
10+
* @property $image
11+
* @property $imageWidth
12+
* @property $imageHeight
13+
* @property $code
14+
* @property $width
15+
* @property $height
16+
* @property $aspectRatio
17+
* @property $authorName
18+
* @property $authorUrl
19+
* @property $providerIcons
20+
* @property $providerIcon
21+
* @property $providerName
22+
* @property $providerUrl
623
*/
24+
725
namespace Embed\Adapters;
826

927
use Embed\Request;

Embed/Adapters/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class File extends Adapter implements AdapterInterface
3737

3838
public static function check(Request $request)
3939
{
40-
return isset(static::$contentTypes[$request->getMimeType()]);
40+
return isset(self::$contentTypes[$request->getMimeType()]);
4141
}
4242

4343
protected function initProviders(Request $request)
@@ -51,12 +51,12 @@ protected function initProviders(Request $request)
5151

5252
public function getType()
5353
{
54-
return static::$contentTypes[$this->request->getMimeType()][0];
54+
return self::$contentTypes[$this->request->getMimeType()][0];
5555
}
5656

5757
public function getCode()
5858
{
59-
switch (static::$contentTypes[$this->request->getMimeType()][1]) {
59+
switch (self::$contentTypes[$this->request->getMimeType()][1]) {
6060
case 'videoHtml':
6161
return Viewers::videoHtml($this->getImage(), $this->getUrl(), $this->getWidth(), $this->getHeight());
6262

Embed/Adapters/Webpage.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66

77
use Embed\Request;
88
use Embed\FastImage;
9-
10-
use Embed\Providers\Html;
11-
use Embed\Providers\OEmbed;
12-
use Embed\Providers\OEmbedImplementations;
13-
use Embed\Providers\OpenGraph;
14-
use Embed\Providers\TwitterCards;
15-
use Embed\Providers\Facebook;
16-
use Embed\Providers\Embedly;
9+
use Embed\Providers;
1710

1811
class Webpage extends Adapter implements AdapterInterface
1912
{
@@ -27,17 +20,17 @@ protected function initProviders(Request $request)
2720
$this->request = $request;
2821

2922
$this->providers = array(
30-
'Html' => new Html($request),
31-
'Facebook' => new Facebook($request),
32-
'TwitterCards' => new TwitterCards($request),
33-
'OpenGraph' => new OpenGraph($request)
23+
'Html' => new Providers\Html($request),
24+
'Facebook' => new Providers\Facebook($request),
25+
'TwitterCards' => new Providers\TwitterCards($request),
26+
'OpenGraph' => new Providers\OpenGraph($request)
3427
);
3528

3629
if ($this->providers['Html']->get('oembed')) {
37-
$this->providers['OEmbed'] = new OEmbed(new Request($request->getAbsolute($this->providers['Html']->get('oembed'))));
38-
} elseif (($oEmbed = OEmbedImplementations::create($request))) {
30+
$this->providers['OEmbed'] = new Providers\OEmbed(new Request($request->getAbsolute($this->providers['Html']->get('oembed'))));
31+
} elseif (($oEmbed = Providers\OEmbedImplementations::create($request))) {
3932
$this->providers['OEmbed'] = $oEmbed;
40-
} elseif ($this->options['embedlyKey'] && ($oEmbed = Embedly::create($request, $this->options['embedlyKey']))) {
33+
} elseif ($this->options['embedlyKey'] && ($oEmbed = Providers\Embedly::create($request, $this->options['embedlyKey']))) {
4134
$this->providers['OEmbed'] = $oEmbed;
4235
}
4336

Embed/Providers/OEmbed.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function __construct(Request $request)
3232

3333
default:
3434
throw new \Exception("No valid format specified");
35-
break;
3635
}
3736

3837
}

Embed/Providers/OpenGraph.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ public function getType()
7676
public function getCode()
7777
{
7878
if ($this->has('video')) {
79-
switch (pathinfo(parse_url($this->get('video'), PHP_URL_PATH), PATHINFO_EXTENSION)) {
80-
case 'swf':
81-
return Viewers::flash($this->get('video'), $this->getWidth(), $this->getHeight());
82-
83-
case 'mp4':
84-
case 'ogg':
85-
case 'ogv':
86-
case 'webm':
87-
return Viewers::videoHtml($this->getImage(), $this->get('video'), $this->getWidth(), $this->getHeight());
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+
return Viewers::videoHtml($this->getImage(), $this->get('video'), $this->getWidth(), $this->getHeight());
89+
}
8890
}
8991

9092
switch ($this->get('video:type')) {

Embed/Providers/Provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Provider
1212
* Save a value
1313
*
1414
* @param string $name Name of the value
15-
* @param string $value The value to save
15+
* @param mixed $value The value to save
1616
*/
1717
public function set($name, $value = null)
1818
{

Embed/RequestResolvers/Curl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ protected function resolve()
151151

152152
$charset = substr(strtoupper(strstr($charset, '=')), 1);
153153

154-
if (!empty($charset) && ($charset !== 'UTF-8')) {
155-
$content = @mb_convert_encoding($content, 'UTF-8', $charset);
154+
if (!empty($charset) && !empty($this->content) && ($charset !== 'UTF-8')) {
155+
$this->content = @mb_convert_encoding($this->content, 'UTF-8', $charset);
156156
}
157157
} elseif (strpos($this->getResult('content_type'), '/') !== false) {
158158
$this->result['mime_type'] = $this->result['content_type'];

Embed/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function getFragmentArray()
285285
*/
286286
public function setFragment($fragment)
287287
{
288-
$this->info['fragment'];
288+
$this->info['fragment'] = $fragment;
289289
}
290290

291291

test-sources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<tr>
8888
<th>Content</th>
8989
<td>
90-
<pre><?php echo htmlspecialchars($url->getContent(), ENT_IGNORE); ?></pre>
90+
<pre><?php echo htmlspecialchars($request->getContent(), ENT_IGNORE); ?></pre>
9191
</td>
9292
</tr>
9393
</table>

0 commit comments

Comments
 (0)