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 |
||
21 | View Code Duplication | class ServiceStop extends \Risoluto\RisolutoControllerBase implements \Risoluto\RisolutoControllerInterface |
|
22 | { |
||
23 | // View関連の処理を使用する |
||
24 | use \Risoluto\RisolutoViewTrait; |
||
25 | |||
26 | /** |
||
27 | * play() |
||
28 | * |
||
29 | * 主処理を行う |
||
30 | * |
||
31 | * @access public |
||
32 | * |
||
33 | * @param void |
||
34 | * |
||
35 | * @return void なし |
||
36 | */ |
||
37 | public function play() |
||
48 | } |
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
.