FlickRFinder::find()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebThumbnailer\Finder;
6
7
/**
8
 * Finder for flickr.com. Works with the homepage, profiles and picture page.
9
 *
10
 * Apply size parameter on thumb URL.
11
 *
12
 * @see QueryRegexFinder for more info.
13
 */
14
class FlickRFinder extends QueryRegexFinder
15
{
16
    /**
17
     * FlickR image permalinks are suffixed by a size character.
18
     * This finder will replace it according to user size settings.
19
     *
20
     * @inheritdoc
21
     */
22
    public function find()
23
    {
24
        $thumb = parent::find();
25
        if (empty($thumb)) {
26
            return false;
27
        }
28
29
        $size = $this->getOptionValue('size');
30
        // One size is actually no suffix...
31
        $size = ! empty($size) ? '_' . $size : '';
32
        $thumb = preg_replace('#(.*)_\w(\.\w+)$#i', '$1' . $size . '$2', $thumb);
33
34
        return $thumb ?? false;
35
    }
36
}
37