TagController::show()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
use App\Acme\Transformers\TagTransformer;
8
use App\Http\Requests;
9
use App\Http\Controllers\Controller;
10
use phpDocumentor\Reflection\DocBlock\Tag;
11
12
class TagController extends Controller
13
{
14
    protected $tagTransformer;
15
    /**
16
     * TagController constructor.
17
     */
18
    public function __construct(TagTransformer $tagTransformer)
19
    {
20
        $this->tagTransformer = $tagTransformer;
21
        $this->middleware("auth.api");
22
    }
23
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index($taskId = null)
30
    {
31
        //problema 1, no retorna: paginació
32
        //$tag = Tag::all();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
33
        $tag = $this->getTags($taskId);
0 ignored issues
show
Documentation Bug introduced by
The method getTags does not exist on object<App\Http\Controllers\TagController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
        return $this->respond($this->tagTransformer->transformCollection($tag->all()));
0 ignored issues
show
Documentation Bug introduced by
The method respond does not exist on object<App\Http\Controllers\TagController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
35
    }
36
37
    /**
38
     * Show the form for creating a new resource.
39
     *
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function create()
43
    {
44
        //
45
    }
46
47
    /**
48
     * Store a newly created resource in storage.
49
     *
50
     * @param  \Illuminate\Http\Request  $request
51
     * @return \Illuminate\Http\Response
52
     */
53
    public function store(Request $request)
54
    {
55
        $tag = new tag();
0 ignored issues
show
Bug introduced by
The call to Tag::__construct() misses some required arguments starting with $name.
Loading history...
56
57
        $this->saveTag($request, $tag);
58
    }
59
60
    /**
61
     * Display the specified resource.
62
     *
63
     * @param  int  $id
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function show($id)
67
    {
68
        return $tag = Tag::findOrFail($id);
0 ignored issues
show
Bug introduced by
The method findOrFail() does not seem to exist on object<phpDocumentor\Reflection\DocBlock\Tag>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
$tag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
69
70
        //Es el mateix
71
        //$tag= Tag::where('id', $id)->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param  int  $id
78
     * @return \Illuminate\Http\Response
79
     */
80
    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...
81
    {
82
        //
83
    }
84
85
    /**
86
     * Update the specified resource in storage.
87
     *
88
     * @param  \Illuminate\Http\Request  $request
89
     * @param  int  $id
90
     * @return \Illuminate\Http\Response
91
     */
92
    public function update(Request $request, $id)
93
    {
94
        $tag = Tag::findOrFail($id);
0 ignored issues
show
Bug introduced by
The method findOrFail() does not seem to exist on object<phpDocumentor\Reflection\DocBlock\Tag>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
95
        $this->saveTag($request, $tag);
96
    }
97
98
    /**
99
     * Remove the specified resource from storage.
100
     *
101
     * @param  int  $id
102
     * @return \Illuminate\Http\Response
103
     */
104
    public function destroy($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...
105
    {
106
        //
107
    }
108
109
    /**
110
     * @param Request $request
111
     * @param $tag
112
     */
113
    public function saveTag(Request $request, $tag)
114
    {
115
        $tag->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...
116
        $tag->save();
117
    }
118
}
119