UserController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 53.45 %

Importance

Changes 0
Metric Value
wmc 10
dl 31
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 15 15 3
A index() 0 3 1
A create() 0 14 3
A update_photo() 15 15 3

How to fix   Duplicated Code   

Duplicated Code

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
2
3
/**
4
 * Controlador para las acciones y vistas con el usuario
5
 */
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();
0 ignored issues
show
Bug introduced by
Are you sure the usage of Redirect::to() targeting Redirect::to() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        //Carga los datos del usuario
34
        $this->user = (new User)->find($id);
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
        //se verifica si se ha enviado via POST los datos
36
        if (Input::hasPost('user')) {
37
            //Intenta guardar los cambios
38
            if ($this->user->update(Input::post('user'))) {
39
                //Mensaje de éxito y retorna al listado
40
                Flash::valid('Usuario actualizado');
41
                return Redirect::to();
0 ignored issues
show
Bug introduced by
Are you sure the usage of Redirect::to() targeting Redirect::to() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
42
            }
43
            //Si falla se hacen persistentes los datos en el formulario
44
            $this->user = Input::post('user');
45
            return;
46
        }
47
    }
48
49 View Code Duplication
    public function update_photo(int $id)//validación 'int' con php7
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        //Carga los datos del usuario
52
        $this->user = (new User)->find($id);
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
53
        //se verifica si se ha enviado via POST los datos
54
        if (Input::hasPost('user')) {
55
            //Si falla al intentar actualizar
56
            if ($this->user->updatePhoto()) {
0 ignored issues
show
Bug introduced by
The method updatePhoto() does not exist on ActiveRecord. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            if ($this->user->/** @scrutinizer ignore-call */ updatePhoto()) {
Loading history...
57
                //Mensaje de éxito y retorna al listado
58
                Flash::valid('Foto de usuario actualizada');
59
                return Redirect::to();
0 ignored issues
show
Bug introduced by
Are you sure the usage of Redirect::to() targeting Redirect::to() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
60
            }
61
            //se hacen persistentes los datos en el formulario
62
            $this->user = Input::post('user');
63
            return;
64
        }
65
    }
66
}
67