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 |
||
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 | 10 | public function __construct($url, $pattern, EmbedRendererInterface $renderer) |
|
32 | |||
33 | /** |
||
34 | * Returns the service name (ie: "Youtube" or "Vimeo"). |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | 1 | public function getServiceName() |
|
42 | |||
43 | /** |
||
44 | * Returns if the service has a thumbnail image. |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | 1 | public function hasThumbnail() |
|
52 | |||
53 | /** |
||
54 | * Returns all thumbnails available sizes. |
||
55 | * |
||
56 | * @return array |
||
|
|||
57 | */ |
||
58 | 3 | public function getThumbNailSizes() |
|
64 | |||
65 | /** |
||
66 | * @param string $size |
||
67 | * @param bool $secure |
||
68 | * |
||
69 | * @return string |
||
70 | * @throws InvalidThumbnailSizeException |
||
71 | */ |
||
72 | 2 | View Code Duplication | public function getThumbnail($size, $secure = false) |
80 | |||
81 | /** |
||
82 | * Returns the small thumbnail's url. |
||
83 | * |
||
84 | * @param bool $secure |
||
85 | * @return string |
||
86 | * @throws InvalidThumbnailSizeException |
||
87 | */ |
||
88 | 1 | public function getSmallThumbnail($secure = false) |
|
89 | { |
||
90 | //Since this service does not provide other thumbnails sizes we just return the default size |
||
91 | 1 | return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Returns the medium thumbnail's url. |
||
96 | * |
||
97 | * @param bool $secure |
||
98 | * @return string |
||
99 | * @throws InvalidThumbnailSizeException |
||
100 | */ |
||
101 | 1 | public function getMediumThumbnail($secure = false) |
|
102 | { |
||
103 | //Since this service does not provide other thumbnails sizes we just return the default size |
||
104 | 1 | return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Returns the large thumbnail's url. |
||
109 | * |
||
110 | * @param bool $secure |
||
111 | * @return string |
||
112 | * @throws InvalidThumbnailSizeException |
||
113 | */ |
||
114 | 1 | public function getLargeThumbnail($secure = false) |
|
115 | { |
||
116 | //Since this service does not provide other thumbnails sizes we just return the default size |
||
117 | 1 | return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * Returns the largest thumnbnaail's url. |
||
122 | * @param bool $secure |
||
123 | * @return string |
||
124 | * @throws InvalidThumbnailSizeException |
||
125 | */ |
||
126 | 1 | public function getLargestThumbnail($secure = false) |
|
127 | { |
||
128 | //Since this service does not provide other thumbnails sizes we just return the default size |
||
129 | 1 | return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure); |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param bool $autoplay |
||
134 | * @param bool $secure |
||
135 | * @return string |
||
136 | */ |
||
137 | 2 | public function getEmbedUrl($autoplay = false, $secure = false) |
|
141 | |||
142 | /** |
||
143 | * @return bool |
||
144 | */ |
||
145 | 1 | public function isEmbeddable() |
|
149 | } |
||
150 |
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.