Skip to content

Commit e30d0eb

Browse files
committed
minor fixes
1 parent 1baa3e0 commit e30d0eb

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

src/Adapters/Adapter.php

+9-14
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,17 @@ public function getImages()
319319
public function getImage()
320320
{
321321
if ($this->config['getBiggerImage']) {
322-
if (($src = Utils::getBiggerValue($this->images, true)) !== null) {
323-
$image = $this->images[$src];
322+
$images = $this->images;
324323

325-
if (($image['width'] >= $this->config['minImageWidth']) && ($image['height'] >= $this->config['minImageHeight'])) {
326-
return $src;
327-
}
324+
if ($images) {
325+
$images = [$images];
328326
}
329-
330-
return;
327+
} else {
328+
$images = Utils::sortByProviders($this->images);
331329
}
332330

333-
foreach (Utils::sortByProviders($this->images) as $images) {
334-
if (($key = Utils::getBiggerValue($images, true)) !== null) {
331+
foreach ($images as $image) {
332+
if (($key = Utils::getBiggerValue($image, true)) !== null) {
335333
$image = $this->images[$key];
336334

337335
if (($image['width'] >= $this->config['minImageWidth']) && ($image['height'] >= $this->config['minImageHeight'])) {
@@ -382,11 +380,8 @@ public function getHeight()
382380
*/
383381
public function getAspectRatio()
384382
{
385-
$width = $this->width;
386-
$height = $this->height;
387-
388-
if ($width && (strpos($width, '%') === false) && $height && (strpos($height, '%') === false)) {
389-
return round(($height / $width) * 100, 3);
383+
if (!empty($this->width) && (strpos($this->width, '%') === false) && !empty($this->height) && (strpos($this->height, '%') === false)) {
384+
return round(($this->height / $this->width) * 100, 3);
390385
}
391386
}
392387

src/Adapters/Archive.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class Archive extends Webpage implements AdapterInterface
1212
{
13+
public $api;
14+
1315
/**
1416
* {@inheritdoc}
1517
*/

src/Adapters/Facebook.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function getSource()
165165
{
166166
$id = $this->api->get('id');
167167

168-
if ($id) {
168+
if (!empty($id)) {
169169
return 'https://www.facebook.com/feeds/page.php?id='.$id.'&format=rss20';
170170
}
171171
}

src/ImageInfo/Curl.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ class Curl implements ImageInfoInterface
3636
*/
3737
public static function getImagesInfo(array $images, array $config = null)
3838
{
39-
if (!$images) {
39+
if (empty($images)) {
4040
return [];
4141
}
4242

4343
if (count($images) === 1) {
4444
$info = self::getImageInfo($images[0], $config);
4545

46-
if ($info) {
47-
return [array_merge($images[0], $info)];
48-
}
49-
50-
return [];
46+
return empty($info) ? [] : [array_merge($images[0], $info)];
5147
}
5248

5349
$finfo = finfo_open(FILEINFO_MIME_TYPE);

src/Providers/Html.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected static function extractImages(\DOMElement $html, Bag $bag, $domain = n
247247
}
248248

249249
//Avoid external images or in external links
250-
if ($domain) {
250+
if ($domain !== null) {
251251
if ($src->getDomain() !== $domain) {
252252
continue;
253253
}
@@ -263,6 +263,9 @@ protected static function extractImages(\DOMElement $html, Bag $bag, $domain = n
263263
continue 2;
264264
}
265265
}
266+
if ($parent->hasAttribute('rel') && (string) $parent->getAttribute('rel') === 'nofollow') {
267+
continue 2;
268+
}
266269

267270
break;
268271
}

src/Request.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class Request
2727
*/
2828
public function __construct(Url $url, $resolverClass = null, array $resolverConfig = null)
2929
{
30-
if ($resolverClass) {
30+
if ($resolverClass !== null) {
3131
$this->setResolverClass($resolverClass);
3232
}
3333

34-
if ($resolverConfig) {
34+
if ($resolverConfig !== null) {
3535
$this->setResolverConfig($resolverConfig);
3636
}
3737

src/Url.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ public function setHost($host)
119119
*
120120
* @param boolean $first_level True to return the first level domain (.com, .es, etc)
121121
*
122-
* @return string The domain or null
122+
* @return string
123123
*/
124124
public function getDomain($first_level = false)
125125
{
126126
$host = $this->getHost();
127127

128-
if (!$host) {
129-
return;
128+
if (empty($host)) {
129+
return '';
130130
}
131131

132132
$host = array_reverse(explode('.', $host));

src/Utils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public static function getBiggerValue(array $values, $returnKey = false)
215215
}
216216
}
217217

218-
if (isset($bigger)) {
218+
if ($bigger !== null) {
219219
return $returnKey ? $bigger : $values[$bigger]['value'];
220220
}
221221
}

0 commit comments

Comments
 (0)