Skip to content

Commit afa62af

Browse files
committed
code improvements
1 parent 54dbe34 commit afa62af

File tree

12 files changed

+55
-57
lines changed

12 files changed

+55
-57
lines changed

src/Adapters/Adapter.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
use Embed\Utils;
77
use Embed\Request;
88
use Embed\Providers\ProviderInterface;
9+
use Embed\GetTrait;
910

1011
/**
1112
* Base class extended by all adapters.
1213
*
13-
* @property Request $request
1414
* @property null|string $title
1515
* @property null|string $description
1616
* @property null|string $url
@@ -34,6 +34,11 @@
3434
*/
3535
abstract class Adapter
3636
{
37+
use GetTrait;
38+
39+
/**
40+
* @var Request
41+
*/
3742
protected $request;
3843

3944
protected $providers = [];
@@ -141,23 +146,6 @@ public function getAllProviders()
141146
return $this->providers;
142147
}
143148

144-
/**
145-
* Magic method to execute and save the url data.
146-
* For example, on call $this->title, executes $this->getTitle().
147-
*
148-
* @param string $name
149-
*
150-
* @return mixed
151-
*/
152-
public function __get($name)
153-
{
154-
$method = 'get'.$name;
155-
156-
if (method_exists($this, $method)) {
157-
return $this->$name = $this->$method();
158-
}
159-
}
160-
161149
/**
162150
* {@inheritdoc}
163151
*/
@@ -199,7 +187,7 @@ public function getType()
199187

200188
return 'link';
201189
}
202-
190+
203191
/**
204192
* {@inheritdoc}
205193
*/
@@ -248,7 +236,7 @@ public function getCode()
248236
foreach ($choosen['providers'] as $provider) {
249237
$this->width = $this->providers[$provider]->getWidth();
250238
$this->height = $this->providers[$provider]->getHeight();
251-
239+
252240
if (is_numeric($this->width)) {
253241
$this->width = (int) $this->width;
254242
}

src/Adapters/Howcast.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getCode()
2626
{
2727
$this->width = null;
2828
$this->height = null;
29-
29+
3030
$dom = $this->request->getHtmlContent();
3131
$modal = $dom->getElementById('embedModal');
3232

src/Adapters/Jsfiddle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Jsfiddle extends Webpage implements AdapterInterface
1414
*/
1515
public function getCode()
1616
{
17-
$this->width = null;
17+
$this->width = null;
1818
$this->height = null;
1919

2020
$url = $this->url;

src/Adapters/N500px.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ protected function run()
6060
$this->addProvider('oembed', new Providers\OEmbed());
6161
$this->addProvider('opengraph', new Providers\OpenGraph());
6262
$this->addProvider('html', new Providers\Html());
63-
6463
}
6564
}

src/DataInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getDescription();
3131
public function getType();
3232

3333
/**
34-
* Gets the tags of the url
34+
* Gets the tags of the url.
3535
*
3636
* @return array
3737
*/

src/GetTrait.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Embed;
4+
5+
/**
6+
* Trait to provide a magic method to get parameters using get* methods.
7+
*/
8+
trait GetTrait
9+
{
10+
/**
11+
* Magic method to execute methods on get paramaters
12+
* For example, $source->sourceUrl executes $source->getSourceUrl().
13+
*
14+
* @param string $name The property name
15+
*
16+
* @return mixed
17+
*/
18+
public function __get($name)
19+
{
20+
$method = 'get'.$name;
21+
22+
if (method_exists($this, $method)) {
23+
return $this->$name = $this->$method();
24+
}
25+
}
26+
}

src/Providers/Html.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public function getTags()
8787
return array_filter(array_map('trim', $keywords));
8888
}
8989

90-
9190
/**
9291
* {@inheritdoc}
9392
*/

src/Providers/OEmbed.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ public function getTags()
108108
{
109109
if ($this->bag->has('meta[keywords]')) {
110110
//it means we are using iframe.ly api
111-
return array_map('trim', explode(',',$this->bag->get('meta[keywords]')));
111+
return array_map('trim', explode(',', $this->bag->get('meta[keywords]')));
112112
}
113-
114-
return [];
115113

116-
114+
return [];
117115
}
118116

119117
/**

src/Providers/OpenGraph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function run()
3333

3434
if ($name === 'image') {
3535
$this->bag->add('images', $value);
36-
} else if (strpos($name, ':tag') !== false) {
36+
} elseif (strpos($name, ':tag') !== false) {
3737
$this->bag->add('tags', $value);
3838
} else {
3939
$this->bag->set($name, $value);

src/Sources/Source.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Embed\Sources;
44

5+
use Embed\GetTrait;
6+
57
/**
68
* Base Source extended by all sources
79
* Provide default functionalities.
@@ -12,22 +14,7 @@
1214
*/
1315
abstract class Source
1416
{
15-
public $request;
17+
use GetTrait;
1618

17-
/**
18-
* Magic method to execute methods on get paramaters
19-
* For example, $source->sourceUrl executes $source->getSourceUrl().
20-
*
21-
* @param string $name The property name
22-
*
23-
* @return mixed
24-
*/
25-
public function __get($name)
26-
{
27-
$method = 'get'.$name;
28-
29-
if (method_exists($this, $method)) {
30-
return $this->$name = $this->$method();
31-
}
32-
}
19+
public $request;
3320
}

0 commit comments

Comments
 (0)