SprintController::statusUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Http\Controllers;
10
11
use GitScrum\Http\Requests\SprintRequest;
12
use GitScrum\Models\ConfigStatus;
13
use GitScrum\Models\ProductBacklog;
14
use GitScrum\Models\Sprint;
15
use Auth;
16
use Illuminate\Http\Request;
17
18
class SprintController extends Controller
19
{
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function index($mode = 'default', $slug_product_backlog = null)
26
    {
27
        $sprints = Sprint::order();
28
29
        if (!is_null($slug_product_backlog)) {
30
            $sprints = $sprints->join('product_backlogs', 'product_backlogs.id', 'sprints.product_backlog_id')
31
                ->where('product_backlogs.slug', $slug_product_backlog);
32
        }
33
34
        $sprints = $sprints->with('issues')
35
            ->with('favorite')
36
            ->with('status')
37
            ->select('sprints.*')
38
            ->paginate(env('APP_PAGINATE'));
39
40
        return view('sprints.index-'.$mode)
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
41
            ->with('sprints', $sprints);
42
    }
43
44
    /**
45
     * Show the form for creating a new resource.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function create($slug_product_backlog = null)
50
    {
51
        $productBacklog_id = null;
52
53
        if (!is_null($slug_product_backlog)) {
54
            $productBacklog_id = ProductBacklog::slug($slug_product_backlog)->first()->id;
55
        }
56
57
        return view('sprints.create')
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58
            ->with('productBacklogs', Auth::user()->productBacklogs())
59
            ->with('productBacklog_id', $productBacklog_id)
60
            ->with('action', 'Create');
61
    }
62
63
    /**
64
     * Store a newly created resource in storage.
65
     *
66
     * @param GitScrum\Http\Requests\SprintRequest $request
67
     *
68
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
69
     */
70
    public function store(SprintRequest $request)
71
    {
72
        $sprint = Sprint::create($request->all());
73
74
        return redirect()->route('sprints.show', ['slug' => $sprint->slug])
0 ignored issues
show
Documentation introduced by
The property slug does not exist on object<GitScrum\Models\Sprint>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
75
            ->with('success', trans('Congratulations! The Sprint has been created with successfully'));
76
    }
77
78
    /**
79
     * Display the specified resource.
80
     *
81
     * @param str $slug
82
     *
83
     * @return \Illuminate\Http\Response
84
     */
85
    public function show($slug)
86
    {
87
        $sprint = Sprint::slug($slug)
88
            ->with('issues.user')
89
            ->with('issues.users')
90
            ->with('issues.commits')
91
            ->with('branches.user')
92
            ->with('branches.commits')
93
            ->with('branches.commits.files')
94
            ->with('issues.statuses')
95
            ->with('issues.statuses.configStatus')
96
            ->with('issues.statuses.configStatus.users')
97
            ->with('issues.statuses.user')
98
            ->with('issues.statuses.statusesable')
99
            ->with('notes')
100
            ->first();
101
102
        if (!count($sprint)) {
103
            return redirect()->route('sprints.index');
104
        }
105
106
        $configStatus = ConfigStatus::type('sprint')->get();
107
108
        return view('sprints.show')
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
109
            ->with('sprint', $sprint)
110
            ->with('configStatus', $configStatus);
111
    }
112
113
    /**
114
     * Show the form for editing the specified resource.
115
     *
116
     * @param $slug
117
     *
118
     * @return \Illuminate\Http\Response
119
     *
120
     * @internal param int $id
121
     */
122
    public function edit($slug)
123
    {
124
        $sprint = Sprint::slug($slug)->first();
125
126
        return view('sprints.edit')
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
            ->with('action', 'Edit')
128
            ->with('sprint', $sprint);
129
    }
130
131
    /**
132
     * Update the specified resource in storage.
133
     *
134
     * @param SprintRequest|Request $request
135
     * @param $slug
136
     *
137
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
138
     *
139
     * @internal param int $id
140
     */
141
    public function update(SprintRequest $request, $slug)
142
    {
143
        $sprint = Sprint::slug($slug)->first();
144
        $sprint->update($request->all());
145
146
        return back()
147
            ->with('success', trans('Congratulations! The Sprint has been edited with successfully'));
148
    }
149
150
    /**
151
     * Remove the specified resource from storage.
152
     *
153
     * @param Request $request
154
     *
155
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
156
     *
157
     * @internal param int $id
158
     */
159
    public function destroy(Request $request)
160
    {
161
        $sprint = Sprint::slug($request->input('slug'))->first();
162
163
        if (!count($sprint)) {
164
            return redirect()->route('sprints.index');
165
        }
166
167
        $sprint->delete();
168
169
        return redirect()->route('sprints.index')
170
            ->with('success', trans('Congratulations! The Sprint has been deleted successfully'));
171
    }
172
173
    public function statusUpdate($slug, $status)
174
    {
175
        $sprint = Sprint::slug($slug)
176
            ->firstOrFail();
177
        $sprint->config_status_id = $status;
178
        $sprint->save();
179
180
        return back()->with('success', trans('Updated successfully'));
181
    }
182
}
183