Conditions | 29 |
Paths | 68 |
Total Lines | 96 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
94 | /** |
||
95 | * @param string $video_url |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | protected function flashPlayer(string $video_url):string{ |
||
100 | |||
101 | return '<div'.$this->getCssClass($this->cssclass).'>' |
||
102 | .'<object type="application/x-shockwave-flash" data="'.$video_url.'">' |
||
103 | .'<param name="allowfullscreen" value="true">' |
||
104 | .'<param name="wmode" value="opaque" />' |
||
105 | .'<param name="movie" value="'.$video_url.'" />' |
||
106 | .'</object></div>'; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param string $video_url |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function embedPlayer(string $video_url):string{ |
||
115 | |||
116 | return '<div'.$this->getCssClass($this->cssclass).'>' |
||
117 | .'<iframe src="'.$video_url.'" allowfullscreen></iframe></div>'; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function html5Player():string{ |
||
124 | |||
125 | return '<video src="'.$this->checkUrl($this->content).'"' |
||
126 | .$this->getCssClass($this->cssclass).' preload="auto" controls="true"></video>'; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param string $host |
||
131 | * @param array $url |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | protected function dailymotion(string $host, array $url):string{ |
||
136 | |||
137 | if($host === 'dailymotion.com'){ |
||
138 | $id = explode('_', str_replace('/video/', '', $url['path']), 2)[0]; |
||
139 | } |
||
140 | else if($host === 'dai.ly'){ |
||
141 | $id = $url['path']; |
||
142 | } |
||
143 | else{ |
||
144 | $id = $this->content; |
||
145 | } |
||
146 | |||
147 | $id = preg_replace('#[^a-z\d]#i', '', $id); |
||
148 | |||
149 | return $this->flash |
||
150 | ? $this->flashPlayer('http://www.dailymotion.com/swf/video/'.$id) |
||
151 | : $this->embedPlayer('http://www.dailymotion.com/embed/video/'.$id); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @param string $host |
||
156 | * @param array $url |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function moddb(string $host, array $url):string{ |
||
161 | |||
162 | $id = $host === 'moddb.com' && strpos('http://www.moddb.com/media/', $this->content) === 0 |
||
163 | ? $url['path'] |
||
164 | : $this->content; |
||
165 | |||
166 | $id = preg_replace('/[^\d]/', '', $id); |
||
167 | |||
168 | return $this->flash |
||
169 | ? $this->flashPlayer('http://www.moddb.com/media/embed/'.$id) |
||
170 | : $this->embedPlayer('http://www.moddb.com/media/iframe/'.$id); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | protected function vimeo():string{ |
||
177 | // since the video id is the only numeric part in a common vimeo share url, we can safely strip anything which is not number |
||
178 | $id = preg_replace('/[^\d]/', '', $this->content); |
||
179 | |||
180 | // @todo collect & batch request |
||
181 | $response = $this->fetch('https://api.vimeo.com/videos/'.$id, ['access_token' => $this->parserOptions->vimeo_access_token])->json; |
||
182 | |||
183 | // access token needed - no coverage |
||
184 | // @codeCoverageIgnoreStart |
||
185 | if(isset($response->link)){ |
||
186 | // @todo add fancyness |
||
187 | return $this->flash |
||
188 | ? $this->flashPlayer('https://vimeo.com/moogaloop.swf?clip_id='.$id) |
||
189 | : $this->embedPlayer('https://player.vimeo.com/video/'.$id); |
||
190 | } |
||
242 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.