Completed
Push — master ( b5f838...0fc1b0 )
by Renato
04:39 queued 01:57
created

SprintController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 6
dl 0
loc 166
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 19 2
A create() 0 13 2
A store() 0 7 1
B show() 0 27 2
A edit() 0 8 1
A update() 0 8 1
A destroy() 0 13 2
A statusUpdate() 0 9 1
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::orderby('date_start', 'DESC')
28
            ->orderby('date_finish', 'ASC');
29
30
        if (!is_null($slug_product_backlog)) {
31
            $sprints = $sprints->join('product_backlogs', 'product_backlogs.id', 'sprints.product_backlog_id')
32
                ->where('product_backlogs.slug', $slug_product_backlog);
33
        }
34
35
        $sprints = $sprints->with('issues')
36
            ->with('favorite')
37
            ->with('status')
38
            ->select('sprints.*')
39
            ->paginate(env('APP_PAGINATE'));
40
41
        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...
42
            ->with('sprints', $sprints);
43
    }
44
45
    /**
46
     * Show the form for creating a new resource.
47
     *
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function create($slug_product_backlog = null)
51
    {
52
        $productBacklog_id = null;
53
54
        if (!is_null($slug_product_backlog)) {
55
            $productBacklog_id = ProductBacklog::slug($slug_product_backlog)->first()->id;
56
        }
57
58
        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...
59
            ->with('productBacklogs', Auth::user()->productBacklogs())
60
            ->with('productBacklog_id', $productBacklog_id)
61
            ->with('action', 'Create');
62
    }
63
64
    /**
65
     * Store a newly created resource in storage.
66
     *
67
     * @param GitScrum\Http\Requests\SprintRequest $request
68
     *
69
     * @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...
70
     */
71
    public function store(SprintRequest $request)
72
    {
73
        $sprint = Sprint::create($request->all());
74
75
        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...
76
            ->with('success', trans('Congratulations! The Sprint has been created with successfully'));
77
    }
78
79
    /**
80
     * Display the specified resource.
81
     *
82
     * @param str $slug
83
     *
84
     * @return \Illuminate\Http\Response
85
     */
86
    public function show($slug)
87
    {
88
        $sprint = Sprint::slug($slug)
89
            ->with('issues.user')
90
            ->with('issues.users')
91
            ->with('issues.commits')
92
            ->with('branches.user')
93
            ->with('branches.commits')
94
            ->with('branches.commits.files')
95
            ->with('issues.statuses')
96
            ->with('issues.statuses.configStatus')
97
            ->with('issues.statuses.configStatus.users')
98
            ->with('issues.statuses.user')
99
            ->with('issues.statuses.statusesable')
100
            ->with('notes')
101
            ->first();
102
103
        if (!count($sprint)) {
104
            return redirect()->route('sprints.index');
105
        }
106
107
        $configStatus = ConfigStatus::type('sprint')->get();
108
109
        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...
110
            ->with('sprint', $sprint)
111
            ->with('configStatus', $configStatus);
112
    }
113
114
    /**
115
     * Show the form for editing the specified resource.
116
     *
117
     * @param $slug
118
     *
119
     * @return \Illuminate\Http\Response
120
     *
121
     * @internal param int $id
122
     */
123
    public function edit($slug)
124
    {
125
        $sprint = Sprint::slug($slug)->first();
126
127
        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...
128
            ->with('action', 'Edit')
129
            ->with('sprint', $sprint);
130
    }
131
132
    /**
133
     * Update the specified resource in storage.
134
     *
135
     * @param SprintRequest|Request $request
136
     * @param $slug
137
     *
138
     * @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...
139
     *
140
     * @internal param int $id
141
     */
142
    public function update(SprintRequest $request, $slug)
143
    {
144
        $sprint = Sprint::slug($slug)->first();
145
        $sprint->update($request->all());
146
147
        return back()
148
            ->with('success', trans('Congratulations! The Sprint has been edited with successfully'));
149
    }
150
151
    /**
152
     * Remove the specified resource from storage.
153
     *
154
     * @param Request $request
155
     *
156
     * @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...
157
     *
158
     * @internal param int $id
159
     */
160
    public function destroy(Request $request)
161
    {
162
        $sprint = Sprint::slug($request->input('slug'))->first();
163
164
        if (!count($sprint)) {
165
            return redirect()->route('sprints.index');
166
        }
167
168
        $sprint->delete();
169
170
        return redirect()->route('sprints.index')
171
            ->with('success', trans('Congratulations! The Sprint has been deleted successfully'));
172
    }
173
174
    public function statusUpdate($slug, $status)
175
    {
176
        $sprint = Sprint::slug($slug)
177
            ->firstOrFail();
178
        $sprint->config_status_id = $status;
179
        $sprint->save();
180
        
181
        return back()->with('success', trans('Updated successfully'));
182
    }
183
}
184