Completed
Push — master ( 4b2a2e...a7f05a )
by Ricardo
02:17
created

FacebookServiceAdapter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 133
Duplicated Lines 6.02 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 12
c 3
b 0
f 1
lcom 1
cbo 3
dl 8
loc 133
ccs 27
cts 27
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A hasThumbnail() 0 4 1
A __construct() 0 8 1
A getServiceName() 0 4 1
A getThumbNailSizes() 0 4 1
A getThumbnail() 8 8 2
A getSmallThumbnail() 0 4 1
A getMediumThumbnail() 0 4 1
A getLargeThumbnail() 0 4 1
A getLargestThumbnail() 0 4 1
A getEmbedUrl() 0 4 1
A isEmbeddable() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 19
    public function __construct($url, $pattern, EmbedRendererInterface $renderer)
27
    {
28 19
        $match = array();
29 19
        preg_match($pattern, $url, $match);
30 19
        $this->setVideoId($match[1]);
31
32 19
        return parent::__construct($url, $pattern, $renderer);
33
    }
34
35
    /**
36
     * Returns the service name .
37
     *
38
     * @return string
39
     */
40 1
    public function getServiceName()
41
    {
42 1
        return 'Facebook';
43
    }
44
45
    /**
46
     * Returns if the service has a thumbnail image.
47
     *
48
     * @return bool
49
     */
50 1
    public function hasThumbnail()
51
    {
52 1
        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 3
    public function getThumbNailSizes()
61
    {
62 3
        return array(self::THUMBNAIL_SIZE_DEFAULT);
63
    }
64
65
    /**
66
     * @param string $size
67
     *
68
     * @param bool $secure
69
     * @return string
70
     * @throws InvalidThumbnailSizeException
71
     */
72 2 View Code Duplication
    public function getThumbnail($size, $secure = 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 2
        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 1
            throw new InvalidThumbnailSizeException();
76
        }
77
78 1
        return $this->getScheme($secure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture';
79
    }
80
81
    /**
82
     * Returns the small thumbnail's url.
83
     *
84
     * @param bool $secure
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 1
    public function getSmallThumbnail($secure = false)
89
    {
90 1
        throw new ThumbnailSizeNotAvailable();
91
    }
92
93
    /**
94
     * Returns the medium thumbnail's url.
95
     *
96
     * @param bool $secure
97
     * @return string
98
     * @throws InvalidThumbnailSizeException
99
     */
100 1
    public function getMediumThumbnail($secure = false)
101
    {
102 1
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure);
103
    }
104
105
    /**
106
     * Returns the large thumbnail's url.
107
     *
108
     * @param bool $secure
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 1
    public function getLargeThumbnail($secure = false)
113
    {
114 1
        throw new ThumbnailSizeNotAvailable();
115
    }
116
117
    /**
118
     * Returns the largest thumbnail's url.
119
     *
120
     * @param bool $secure
121
     * @return string
122
     * @throws InvalidThumbnailSizeException
123
     */
124 1
    public function getLargestThumbnail($secure = false)
125
    {
126 1
        return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure);
127
    }
128
129
    /**
130
     * @param bool $autoplay
131
     *
132
     * @param bool $secure
133
     * @return string
134
     */
135 3
    public function getEmbedUrl($autoplay = false, $secure = false)
136
    {
137 3
        return $this->getScheme($secure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId();
138
    }
139
140
    /**
141
     * @return bool
142
     */
143 2
    public function isEmbeddable()
144
    {
145 2
        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