Completed
Push — master ( 415647...d02380 )
by Ricardo
02:50
created

DailymotionServiceAdapter::hasThumbnail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Ricardo Fiorani
5
 * Date: 30/08/2015
6
 * Time: 14:38.
7
 */
8
namespace RicardoFiorani\Adapter\Dailymotion;
9
10
use RicardoFiorani\Adapter\AbstractServiceAdapter;
11
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
12
use RicardoFiorani\Renderer\EmbedRendererInterface;
13
14
class DailymotionServiceAdapter extends AbstractServiceAdapter
15
{
16
    const THUMBNAIL_DEFAULT = 'thumbnail';
17
18
    /**
19
     * AbstractVideoAdapter constructor.
20
     *
21
     * @param string $url
22
     * @param string $pattern
23
     * @param EmbedRendererInterface $renderer
24
     */
25
    public function __construct($url, $pattern, EmbedRendererInterface $renderer)
26
    {
27
        $videoId = strtok(basename($url), '_');
28
        $this->setVideoId($videoId);
29
30
        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...
31
    }
32
33
    /**
34
     * Returns the service name (ie: "Youtube" or "Vimeo").
35
     *
36
     * @return string
37
     */
38
    public function getServiceName()
39
    {
40
        return 'Dailymotion';
41
    }
42
43
    /**
44
     * Returns if the service has a thumbnail image.
45
     *
46
     * @return bool
47
     */
48
    public function hasThumbnail()
49
    {
50
        return true;
51
    }
52
53
    /**
54
     * Returns all thumbnails available sizes.
55
     *
56
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
57
     */
58
    public function getThumbNailSizes()
59
    {
60
        return array(
61
            self::THUMBNAIL_DEFAULT,
62
        );
63
    }
64
65
    /**
66
     * @param string $size
67
     * @param bool $forceSecure
68
     *
69
     * @return string
70
     * @throws InvalidThumbnailSizeException
71
     */
72 View Code Duplication
    public function getThumbnail($size, $forceSecure = false)
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...
73
    {
74
        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...
75
            throw new InvalidThumbnailSizeException();
76
        }
77
78
        return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
79
    }
80
81
    /**
82
     * Returns the small thumbnail's url.
83
     *
84
     * @param bool $forceSecure
85
     * @return string
86
     * @throws InvalidThumbnailSizeException
87
     */
88
    public function getSmallThumbnail($forceSecure = false)
89
    {
90
        //Since this service does not provide other thumbnails sizes we just return the default size
91
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
92
    }
93
94
    /**
95
     * Returns the medium thumbnail's url.
96
     *
97
     * @param bool $forceSecure
98
     * @return string
99
     * @throws InvalidThumbnailSizeException
100
     */
101
    public function getMediumThumbnail($forceSecure = false)
102
    {
103
        //Since this service does not provide other thumbnails sizes we just return the default size
104
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
105
    }
106
107
    /**
108
     * Returns the large thumbnail's url.
109
     *
110
     * @param bool $forceSecure
111
     * @return string
112
     * @throws InvalidThumbnailSizeException
113
     */
114
    public function getLargeThumbnail($forceSecure = false)
115
    {
116
        //Since this service does not provide other thumbnails sizes we just return the default size
117
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
118
    }
119
120
    /**
121
     * Returns the largest thumnbnaail's url.
122
     * @param bool $forceSecure
123
     * @return string
124
     * @throws InvalidThumbnailSizeException
125
     */
126
    public function getLargestThumbnail($forceSecure = false)
127
    {
128
        //Since this service does not provide other thumbnails sizes we just return the default size
129
        return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
130
    }
131
132
    /**
133
     * @param bool $forceAutoplay
134
     * @param bool $forceSecure
135
     * @return string
136
     */
137
    public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
138
    {
139
        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...
140
    }
141
142
    /**
143
     * @return bool
144
     */
145
    public function isEmbeddable()
146
    {
147
        return true;
148
    }
149
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
150