TagController   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 8
Bugs 0 Features 3
Metric Value
wmc 13
c 8
b 0
f 3
lcom 2
cbo 4
dl 0
loc 113
rs 10

9 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 2
A show() 0 10 2
A edit() 0 4 1
A update() 0 10 2
A destroy() 0 4 1
A getTags() 0 4 2
1
<?php
2
namespace App\Http\Controllers;
3
use Acme\Transformers\TagTransformer;
4
use App\Tag;
5
use App\Task;
6
use Illuminate\Http\Request;
7
use Illuminate\Http\Response as IlluminateResponse;
8
use Illuminate\Support\Facades\Input;
9
/**
10
 * Class TagController
11
 * @package App\Http\Controllers
12
 */
13
class TagController extends ApiController
14
{
15
    /**
16
     * @var TagTransformer
17
     */
18
    protected $tagTransformer;
19
    /**
20
     * TagController constructor.
21
     * @param $tagTransformer
22
     */
23
    public function __construct(TagTransformer $tagTransformer)
24
    {
25
        $this->tagTransformer = $tagTransformer;
26
        //$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...
27
        $this->middleware('auth:api');
28
    }
29
    /**
30
     * Display a listing of the resource.
31
     * @param null $taskId
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function index($taskId = null)
35
    {
36
        //1. No és retorna: paginació
37
        //return Tag::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...
38
        $tag = $this->getTags($taskId);
39
        return $this->respond($this->tagTransformer->transformCollection($tag->all()));
40
    }
41
    /**
42
     * Show the form for creating a new resource.
43
     *
44
     * @return \Illuminate\Http\Response
45
     */
46
    public function create()
47
    {
48
        //
49
    }
50
    /**
51
     * Store a newly created resource in storage.
52
     *  @return \Illuminate\Http\Response
53
     */
54
    public function store()
55
    {
56
        if (!Input::get('title'))
57
        {
58
            return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
59
                ->respondWithError('Parameters failed validation for a task.');
60
        }
61
        Tag::create(Input::all());
62
        return $this->respondCreated('Task successfully created.');
63
    }
64
    /**
65
     * Display the specified resource.
66
     *
67
     * @param  int $id
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function show($id)
71
    {
72
        $tag = Tag::find($id);
73
        if (!$tag) {
74
            return $this->respondNotFound('Tag does not exsist');
75
        }
76
        return $this->respond([
77
            'data' => $this->tagTransformer->transform($tag)
78
        ]);
79
    }
80
    /**
81
     * Show the form for editing the specified resource.
82
     *
83
     * @param  int $id
84
     * @return \Illuminate\Http\Response
85
     */
86
    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...
87
    {
88
        //
89
    }
90
    /**
91
     * Update the specified resource in storage.
92
     *
93
     * @param  \Illuminate\Http\Request $request
94
     * @param  int $id
95
     * @return \Illuminate\Http\Response
96
     */
97
    public function update(Request $request, $id)
98
    {
99
        $tag = Tag::find($id);
100
        if (!$tag)
101
        {
102
            return $this->respondNotFound('Tag does not exist!');
103
        }
104
        $tag->title = $request->title;
1 ignored issue
show
Bug introduced by
The property title 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...
105
        $tag->save();
106
    }
107
    /**
108
     * Remove the specified resource from storage.
109
     *
110
     * @param  int $id
111
     * @return \Illuminate\Http\Response
112
     */
113
    public function destroy($id)
114
    {
115
        Tag::destroy($id);
116
    }
117
    /**
118
     * @param $taskId
119
     * @return \Illuminate\Database\Eloquent\Collection|static[]
120
     */
121
    public function getTags($taskId)
122
    {
123
        return $taskId ? Task::findOrFail($taskId)->tags : Tag::all();
124
    }
125
}