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 |
||
6 | class UserController extends AppController |
||
7 | { |
||
8 | |||
9 | public function index() |
||
10 | { |
||
11 | $this->data = (new User)->find(); |
||
12 | } |
||
13 | |||
14 | public function create() |
||
15 | { |
||
16 | //se verifica si se ha enviado via POST los datos |
||
17 | if (Input::hasPost('user')) { |
||
18 | $obj = new User; |
||
19 | //Intenta guardar el usuario junto con la foto |
||
20 | if ($obj->saveWithPhoto(Input::post('user'))) { |
||
21 | //Mensaje de éxito y retorna al listado |
||
22 | Flash::valid('Usuario creado'); |
||
23 | return Redirect::to(); |
||
|
|||
24 | } |
||
25 | //Si falla se hacen persistentes los datos en el formulario |
||
26 | $this->data = Input::post('user'); |
||
27 | return; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | View Code Duplication | public function edit(int $id)//validación 'int' con php7 |
|
46 | } |
||
47 | } |
||
48 | |||
49 | View Code Duplication | public function update_photo(int $id)//validación 'int' con php7 |
|
64 | } |
||
65 | } |
||
66 | } |
||
67 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.