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

FacebookServiceAdapter::getThumbnail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

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 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Ricardo Fiorani
5
 * Date: 02/09/2015
6
 * Time: 22:42.
7
 */
8
namespace RicardoFiorani\Adapter\Facebook;
9
10
use RicardoFiorani\Adapter\AbstractServiceAdapter;
11
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
12
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable;
13
use RicardoFiorani\Renderer\EmbedRendererInterface;
14
15
class FacebookServiceAdapter extends AbstractServiceAdapter
16
{
17
    const THUMBNAIL_SIZE_DEFAULT = 'default';
18
19
    /**
20
     * AbstractVideoAdapter constructor.
21
     *
22
     * @param string $url
23
     * @param string $pattern
24
     * @param EmbedRendererInterface $renderer
25
     */
26
    public function __construct($url, $pattern, EmbedRendererInterface $renderer)
27
    {
28
        $match = array();
29
        preg_match($pattern, $url, $match);
30
        $this->setVideoId($match[1]);
31
32
        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...
33
    }
34
35
    /**
36
     * Returns the service name .
37
     *
38
     * @return string
39
     */
40
    public function getServiceName()
41
    {
42
        return 'Facebook';
43
    }
44
45
    /**
46
     * Returns if the service has a thumbnail image.
47
     *
48
     * @return bool
49
     */
50
    public function hasThumbnail()
51
    {
52
        return true;
53
    }
54
55
    /**
56
     * Returns all thumbnails available sizes.
57
     *
58
     * @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...
59
     */
60
    public function getThumbNailSizes()
61
    {
62
        return array(self::THUMBNAIL_SIZE_DEFAULT);
63
    }
64
65
    /**
66
     * @param string $size
67
     *
68
     * @param bool $forceSecure
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) . '://graph.facebook.com/' . $this->getVideoId() . '/picture';
79
    }
80
81
    /**
82
     * Returns the small thumbnail's url.
83
     *
84
     * @param bool $forceSecure
85
     * @return string
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use NoType.

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...
86
     * @throws ThumbnailSizeNotAvailable
87
     */
88
    public function getSmallThumbnail($forceSecure = false)
89
    {
90
        throw new ThumbnailSizeNotAvailable();
91
    }
92
93
    /**
94
     * Returns the medium thumbnail's url.
95
     *
96
     * @param bool $forceSecure
97
     * @return string
98
     * @throws InvalidThumbnailSizeException
99
     */
100
    public function getMediumThumbnail($forceSecure = false)
101
    {
102
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
103
    }
104
105
    /**
106
     * Returns the large thumbnail's url.
107
     *
108
     * @param bool $forceSecure
109
     * @return string
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use NoType.

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...
110
     * @throws ThumbnailSizeNotAvailable
111
     */
112
    public function getLargeThumbnail($forceSecure = false)
113
    {
114
        throw new ThumbnailSizeNotAvailable();
115
    }
116
117
    /**
118
     * Returns the largest thumbnail's url.
119
     *
120
     * @param bool $forceSecure
121
     * @return string
122
     * @throws InvalidThumbnailSizeException
123
     */
124
    public function getLargestThumbnail($forceSecure = false)
125
    {
126
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure);
127
    }
128
129
    /**
130
     * @param bool $forceAutoplay
131
     *
132
     * @param bool $forceSecure
133
     * @return string
134
     */
135
    public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
136
    {
137
        return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId();
138
    }
139
140
    /**
141
     * @return bool
142
     */
143
    public function isEmbeddable()
144
    {
145
        return true;
146
    }
147
}
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...
148