TaskController   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 10
Bugs 0 Features 3
Metric Value
wmc 13
c 10
b 0
f 3
lcom 2
cbo 5
dl 0
loc 104
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 7 1
A create() 0 4 1
A store() 0 10 4
A show() 0 10 2
A edit() 0 4 1
A update() 0 12 2
A destroy() 0 4 1
1
<?php
2
3
namespace App\Http\Controllers;
4
use Acme\Transformers\TaskTransformer;
5
use App\Task;
6
use Illuminate\Http\Request;
7
use Illuminate\Http\Response as IlluminateResponse;
8
use Illuminate\Support\Facades\Input;
9
class TaskController extends ApiController
10
{
11
    protected $taskTransformer;
12
    /**
13
     * TaskController constructor.
14
     * @param $taskTransformer
15
     */
16
    public function __construct(TaskTransformer $taskTransformer)
17
    {
18
        $this->taskTransformer = $taskTransformer;
19
        //$this->middleware('auth.basic', ['only' => 'store']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
        $this->middleware('auth:api');
21
    }
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function index()
28
    {
29
        //1. No és retorna: paginació
30
        //return Task::all();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
        $task = Task::all();
32
        return $this->respond($this->taskTransformer->transformCollection($task->all()));
33
    }
34
    /**
35
     * Show the form for creating a new resource.
36
     *
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function create()
40
    {
41
        //
42
    }
43
    /**
44
     * Store a newly created resource in storage.
45
     *  @return \Illuminate\Http\Response
46
     */
47
    public function store()
48
    {
49
        if (!Input::get('name') or !Input::get('done') or !Input::get('priority'))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
50
        {
51
            return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
52
                ->respondWithError('Parameters failed validation for a task.');
53
        }
54
        Task::create(Input::all());
55
        return $this->respondCreated('Task successfully created.');
56
    }
57
    /**
58
     * Display the specified resource.
59
     *
60
     * @param  int $id
61
     * @return \Illuminate\Http\Response
62
     */
63
    public function show($id)
64
    {
65
        $task = Task::find($id);
66
        if (!$task) {
67
            return $this->respondNotFound('Task does not exsist');
68
        }
69
        return $this->respond([
70
            'data' => $this->taskTransformer->transform($task)
71
        ]);
72
    }
73
    /**
74
     * Show the form for editing the specified resource.
75
     *
76
     * @param  int $id
77
     * @return \Illuminate\Http\Response
78
     */
79
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        //
82
    }
83
    /**
84
     * Update the specified resource in storage.
85
     *
86
     * @param  \Illuminate\Http\Request $request
87
     * @param  int $id
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function update(Request $request, $id)
91
    {
92
        $task = Task::find($id);
93
        if (!$task)
94
        {
95
            return $this->respondNotFound('Task does not exist!!');
96
        }
97
        $task->name = $request->name;
1 ignored issue
show
Bug introduced by
The property name does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
98
        $task->priority = $request->priority;
1 ignored issue
show
Bug introduced by
The property priority does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
99
        $task->done = $request->done;
1 ignored issue
show
Bug introduced by
The property done does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
100
        $task->save();
101
    }
102
    /**
103
     * Remove the specified resource from storage.
104
     *
105
     * @param  int $id
106
     * @return \Illuminate\Http\Response
107
     */
108
    public function destroy($id)
109
    {
110
        Task::destroy($id);
111
    }
112
}
113