Completed
Pull Request — master (#8)
by Ricardo
01:45
created

FacebookServiceAdapter::getThumbnail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php declare(strict_types=1);
2
3
namespace RicardoFiorani\Adapter\Facebook;
4
5
use RicardoFiorani\Adapter\AbstractServiceAdapter;
6
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
7
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable;
8
use RicardoFiorani\Renderer\EmbedRendererInterface;
9
10
class FacebookServiceAdapter extends AbstractServiceAdapter
11
{
12
    const THUMBNAIL_SIZE_DEFAULT = 'default';
13
14
    public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer)
15
    {
16
        $match = array();
17
        preg_match($pattern, $url, $match);
18
        $this->setVideoId($match[1]);
19
20
        return parent::__construct($url, $pattern, $renderer);
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
21
    }
22
23
    public function getServiceName(): string
24
    {
25
        return 'Facebook';
26
    }
27
28
    public function hasThumbnail(): bool
29
    {
30
        return true;
31
    }
32
33
    public function getThumbNailSizes(): array
34
    {
35
        return array(self::THUMBNAIL_SIZE_DEFAULT);
36
    }
37
38 View Code Duplication
    public function getThumbnail(string $size, bool $forceSecure = false): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        if (false == in_array($size, $this->getThumbNailSizes())) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
41
            throw new InvalidThumbnailSizeException();
42
        }
43
44
        return $this->getScheme($forceSecure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture';
45
    }
46
47
    /**
48
     * @throws ThumbnailSizeNotAvailable
49
     */
50
    public function getSmallThumbnail(bool $forceSecure = false): string
51
    {
52
        throw new ThumbnailSizeNotAvailable();
53
    }
54
55
    /**
56
     * @throws InvalidThumbnailSizeException
57
     */
58
    public function getMediumThumbnail(bool $forceSecure = false): string
59
    {
60
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
61
    }
62
63
    /**
64
     * @throws ThumbnailSizeNotAvailable
65
     */
66
    public function getLargeThumbnail(bool $forceSecure = false): string
67
    {
68
        throw new ThumbnailSizeNotAvailable();
69
    }
70
71
    /**
72
     * @throws InvalidThumbnailSizeException
73
     */
74
    public function getLargestThumbnail(bool $forceSecure = false): string
75
    {
76
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
77
    }
78
79
    public function getEmbedUrl(bool $forceAutoplay = false, bool $forceSecure = false): string
80
    {
81
        return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId();
82
    }
83
84
    public function isEmbeddable(): bool
85
    {
86
        return true;
87
    }
88
}
89