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 |
||
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() |
|
54 | |||
55 | /** |
||
56 | * Returns all thumbnails available sizes. |
||
57 | * |
||
58 | * @return array |
||
|
|||
59 | */ |
||
60 | 3 | public function getThumbNailSizes() |
|
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) |
80 | |||
81 | /** |
||
82 | * Returns the small thumbnail's url. |
||
83 | * |
||
84 | * @param bool $secure |
||
85 | * @return string |
||
86 | * @throws ThumbnailSizeNotAvailable |
||
87 | */ |
||
88 | 1 | public function getSmallThumbnail($secure = false) |
|
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) |
|
104 | |||
105 | /** |
||
106 | * Returns the large thumbnail's url. |
||
107 | * |
||
108 | * @param bool $secure |
||
109 | * @return string |
||
110 | * @throws ThumbnailSizeNotAvailable |
||
111 | */ |
||
112 | 1 | public function getLargeThumbnail($secure = false) |
|
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) |
|
128 | |||
129 | /** |
||
130 | * @param bool $autoplay |
||
131 | * |
||
132 | * @param bool $secure |
||
133 | * @return string |
||
134 | */ |
||
135 | 3 | public function getEmbedUrl($autoplay = false, $secure = false) |
|
139 | |||
140 | /** |
||
141 | * @return bool |
||
142 | */ |
||
143 | 2 | public function isEmbeddable() |
|
147 | } |
||
148 |
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.