TagController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Tag;
6
use App\Transformers\TagTransformer;
7
use Illuminate\Http\Request;
8
9
use App\Http\Requests;
10
use App\Http\Controllers\Controller;
11
use Illuminate\Support\Facades\Response;
12
use Symfony\Component\Console\Input\Input;
13
14
class TagController extends Controller
15
{
16
    /**
17
     * TaskController constructor.
18
     */
19
    public function __construct(TagTransformer $tagTransformer)
20
    {
21
        $this->tagTransformer = $tagTransformer;
0 ignored issues
show
Bug introduced by
The property tagTransformer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->middleware('auth.basic', ['only' => 'store']);
23
    }
24
25
    /**
26
     * Display a listing of the resource.
27
     *
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function index($tagId = null)
31
    {
32
33
        //$tags = 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...
34
35
36
        $tag = $this->getTags($tagId);
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...
37
        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...
38
    }
39
40
    /**
41
     * Show the form for creating a new resource.
42
     *
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function create()
46
    {
47
        //
48
    }
49
50
    /**
51
     * Store a newly created resource in storage.
52
     *
53
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function store()
57
    {
58
59 View Code Duplication
        if (! Input::get('name') or ! Input::get('done') or ! Input::get('priority'))
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Symfony\Component\Console\Input\Input>.

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...
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...
Duplication introduced by
This code seems to be duplicated across 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...
60
        {
61
            return $this->setStatusCode(IlluminateResponse::HTTP_UNPROCESSABLE_ENTITY)
0 ignored issues
show
Documentation Bug introduced by
The method setStatusCode 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...
62
                ->respondWithError('Parameters failed validation for a tag.');
63
        }
64
        Tag::create(Input::all());
0 ignored issues
show
Bug introduced by
The method all() does not seem to exist on object<Symfony\Component\Console\Input\Input>.

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...
65
        return $this->respondCreated('Tag successfully created.');
0 ignored issues
show
Bug introduced by
The method respondCreated() does not exist on App\Http\Controllers\TagController. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
67
    }
68
69
    /**
70
     * Display the specified resource.
71
     *
72
     * @param  int  $id
73
     * @return \Illuminate\Http\Response
74
     */
75
    public function show($id)
76
    {
77
78
        $tag = Tag::find($id);
79
        // $task = Task::where('id',$id)->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
80
81
        if (! $tag){
82
            return Response::json([
83
84
                'error' => [
85
                    'message' => 'La tag no existeix',
86
                    'code'
87
                ]
88
            ], 404);
89
        }
90
        return Response::json([
91
            $this->tagTransfomer->transform($tag)
0 ignored issues
show
Bug introduced by
The property tagTransfomer does not seem to exist. Did you mean tagTransformer?

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...
92
        ], 200);
93
    }
94
95
    /**
96
     * Show the form for editing the specified resource.
97
     *
98
     * @param  int  $id
99
     * @return \Illuminate\Http\Response
100
     */
101
    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...
102
    {
103
        //
104
    }
105
106
    /**
107
     * Update the specified resource in storage.
108
     *
109
     * @param  \Illuminate\Http\Request  $request
110
     * @param  int  $id
111
     * @return \Illuminate\Http\Response
112
     */
113
    public function update(Request $request, $id)
114
    {
115
        $tag =  Tag::findorFail($id);
116
        $this->saveTag($request, $tag);
117
    }
118
119
    /**
120
     * Remove the specified resource from storage.
121
     *
122
     * @param  int  $id
123
     * @return \Illuminate\Http\Response
124
     */
125
    public function destroy($id)
126
    {
127
        Tag::destroy($id);
128
    }
129
130
    /**
131
     * @param Request $request
132
     * @param $tag
133
     */
134
    public function saveTag(Request $request, $tag)
135
    {
136
        $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...
137
        $tag->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...
138
        $tag->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...
139
        $tag->save();
140
    }
141
142
}
143