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

DailymotionServiceAdapter::getSmallThumbnail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace RicardoFiorani\Adapter\Dailymotion;
4
5
use RicardoFiorani\Adapter\AbstractServiceAdapter;
6
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
7
use RicardoFiorani\Renderer\EmbedRendererInterface;
8
9
class DailymotionServiceAdapter extends AbstractServiceAdapter
10
{
11
    const THUMBNAIL_DEFAULT = 'thumbnail';
12
13
    public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer)
14
    {
15
        $videoId = strtok(basename($url), '_');
16
        $this->setVideoId($videoId);
17
18
        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...
19
    }
20
21
    public function getServiceName(): string
22
    {
23
        return 'Dailymotion';
24
    }
25
26
    public function hasThumbnail(): bool
27
    {
28
        return true;
29
    }
30
31
    public function getThumbNailSizes(): array
32
    {
33
        return array(
34
            self::THUMBNAIL_DEFAULT,
35
        );
36
    }
37
38
    /**
39
     * @throws InvalidThumbnailSizeException
40
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
41
     */
42 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...
43
    {
44
        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...
45
            throw new InvalidThumbnailSizeException();
46
        }
47
48
        return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
49
    }
50
51
    /**
52
     * @throws InvalidThumbnailSizeException
53
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
54
     */
55
    public function getSmallThumbnail(bool $forceSecure = false): string
56
    {
57
        //Since this service does not provide other thumbnails sizes we just return the default size
58
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
59
    }
60
61
    /**
62
     * @throws InvalidThumbnailSizeException
63
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
64
     */
65
    public function getMediumThumbnail(bool $forceSecure = false): string
66
    {
67
        //Since this service does not provide other thumbnails sizes we just return the default size
68
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
69
    }
70
71
    /**
72
     * @throws InvalidThumbnailSizeException
73
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
74
     */
75
    public function getLargeThumbnail(bool $forceSecure = false): string
76
    {
77
        //Since this service does not provide other thumbnails sizes we just return the default size
78
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
79
    }
80
81
    /**
82
     * @throws InvalidThumbnailSizeException
83
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
84
     */
85
    public function getLargestThumbnail(bool $forceSecure = false): string
86
    {
87
        //Since this service does not provide other thumbnails sizes we just return the default size
88
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
89
    }
90
91
    /**
92
     * @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
93
     */
94
    public function getEmbedUrl(bool $forceAutoplay = false, bool $forceSecure = false): string
95
    {
96
        return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : '');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 147 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
97
    }
98
99
    public function isEmbeddable(): bool
100
    {
101
        return true;
102
    }
103
}
104