Completed
Push — master ( 8fb65e...6702e8 )
by Renato
02:44
created

IssueController::statusUpdate()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 19
nc 3
nop 3
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
namespace GitScrum\Http\Controllers;
9
10
use Illuminate\Http\Request;
11
use GitScrum\Http\Requests\IssueRequest;
12
use GitScrum\Models\Sprint;
13
use GitScrum\Models\UserStory;
14
use GitScrum\Models\Issue;
15
use GitScrum\Models\Organization;
16
use GitScrum\Models\IssueType;
17
use GitScrum\Models\ConfigStatus;
18
use GitScrum\Models\ConfigIssueEffort;
19
use Carbon\Carbon;
20
use Auth;
21
22
class IssueController extends Controller
23
{
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index($slug)
30
    {
31
        if ($slug) {
32
            $sprint = Sprint::where('slug', $slug)
33
                ->with('issues.user')
34
                ->with('issues.users')
35
                ->with('issues.commits')
36
                ->with('issues.statuses')
37
                ->with('issues.status')
38
                ->with('issues.comments')
39
                ->with('issues.attachments')
40
                ->with('issues.type')
41
                ->first();
42
43
            $issues = $sprint->issues;
44
        } else {
45
            $sprint = null;
46
            $issues = Auth::user()->issues;
47
        }
48
49
        $issues = $issues->sortBy('position')->groupBy('config_status_id');
50
51
        $configStatus = configStatus::where('type', 'issue')
52
            ->orderby('position', 'ASC')->get();
53
54
        if (!is_null($sprint) && !count($sprint)) {
55
            return redirect()->route('sprints.index');
56
        }
57
58
        return view('issues.index')
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('sprint', $sprint)
60
            ->with('issues', $issues)
61
            ->with('configStatus', $configStatus);
62
    }
63
64
    /**
65
     * Show the form for creating a new resource.
66
     *
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function create($slug_sprint = null, $slug_user_story = null)
70
    {
71
        $issue_types = IssueType::where('enabled', 1)
72
            ->orderby('position', 'ASC')
73
            ->get();
74
75
        $issue_efforts = ConfigIssueEffort::where('enabled', 1)
76
            ->orderby('position', 'ASC')
77
            ->get();
78
79
        $userStory = $productBacklogs = null;
80
81
        if (is_null($slug_sprint) || $slug_sprint == '-') {
82
            $userStory = UserStory::where('slug', $slug_user_story)->first();
83
            $productBacklogs = Auth::user()->productBacklogs($userStory->product_backlog_id);
84
            $usersByOrganization = Organization::find($userStory->productBacklog->organization_id)->users;
85
        } else {
86
            $usersByOrganization = Organization::find(Sprint::where('slug', $slug_sprint)->first()
87
                ->productBacklog->organization_id)->users;
88
        }
89
90
        return view('issues.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...
91
            ->with('productBacklogs', $productBacklogs)
92
            ->with('userStory', $userStory)
93
            ->with('slug', $slug_sprint)
94
            ->with('issue_types', $issue_types)
95
            ->with('issue_efforts', $issue_efforts)
96
            ->with('usersByOrganization', $usersByOrganization)
97
            ->with('action', 'Create');
98
    }
99
100
    /**
101
     * Store a newly created resource in storage.
102
     *
103
     * @param \Illuminate\Http\Request $request
104
     *
105
     * @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...
106
     */
107
    public function store(IssueRequest $request)
108
    {
109
        $issue = Issue::create($request->all());
110
111
        if (is_array($request->members)) {
0 ignored issues
show
Documentation introduced by
The property members does not exist on object<GitScrum\Http\Requests\IssueRequest>. 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...
112
            $issue->users()->sync($request->members);
0 ignored issues
show
Documentation introduced by
The property members does not exist on object<GitScrum\Http\Requests\IssueRequest>. 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...
113
        }
114
115
        return redirect()->route('issues.show', ['slug' => $issue->slug])
0 ignored issues
show
Documentation introduced by
The property slug does not exist on object<GitScrum\Models\Issue>. 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...
116
            ->with('success', _('Congratulations! The Issue has been created with successfully'));
117
    }
118
119
    /**
120
     * Display the specified resource.
121
     *
122
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
123
     *
124
     * @return \Illuminate\Http\Response
125
     */
126
    public function show($slug)
127
    {
128
        $issue = Issue::where('slug', '=', $slug)
129
            ->with('sprint')
130
            ->with('type')
131
            ->with('configEffort')
132
            ->with('labels')
133
            ->first();
134
135
        $usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users;
136
137
        $configStatus = configStatus::where('type', 'issue')
138
            ->orderby('position', 'ASC')->get();
139
140
        return view('issues.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...
141
            ->with('issue', $issue)
142
            ->with('usersByOrganization', $usersByOrganization)
143
            ->with('configStatus', $configStatus);
144
    }
145
146
    /**
147
     * Show the form for editing the specified resource.
148
     *
149
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
150
     *
151
     * @return \Illuminate\Http\Response
152
     */
153
    public function edit($slug)
154
    {
155
        $issue = Issue::where('slug', '=', $slug)->first();
156
157
        $issue_types = IssueType::where('enabled', 1)
158
            ->orderby('position', 'ASC')
159
            ->get();
160
161
        $issue_efforts = ConfigIssueEffort::where('enabled', 1)
162
            ->orderby('position', 'ASC')
163
            ->get();
164
165
        $usersByOrganization = Organization::find($issue->productBacklog->organization_id)->users;
166
167
        return view('issues.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...
168
            ->with('userStory', $issue->userStory)
169
            ->with('slug', isset($issue->sprint->slug) ? $issue->sprint->slug : null)
170
            ->with('issue_types', $issue_types)
171
            ->with('issue_efforts', $issue_efforts)
172
            ->with('usersByOrganization', $usersByOrganization)
173
            ->with('issue', $issue)
174
            ->with('action', 'Edit');
175
    }
176
177
    /**
178
     * Update the specified resource in storage.
179
     *
180
     * @param \Illuminate\Http\Request $request
181
     * @param int                      $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
182
     *
183
     * @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...
184
     */
185
    public function update(IssueRequest $request, $slug)
186
    {
187
        $issue = Issue::where('slug', '=', $slug)->first();
188
        $issue->update($request->all());
189
190
        if (is_array($request->members)) {
0 ignored issues
show
Documentation introduced by
The property members does not exist on object<GitScrum\Http\Requests\IssueRequest>. 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...
191
            $issue->users()->sync($request->members);
0 ignored issues
show
Documentation introduced by
The property members does not exist on object<GitScrum\Http\Requests\IssueRequest>. 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...
192
        }
193
194
        return redirect()->route('issues.show', ['slug' => $issue->slug])
195
            ->with('success', _('Congratulations! The Issue has been edited with successfully'));
196
    }
197
198
    public function statusUpdate(Request $request, $slug=null, int $status=0)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
199
    {
200
        if (!$request->ajax()) {
201
            $issue = Issue::where('slug', $slug)
202
                ->firstOrFail();
203
204
            $issue->config_status_id = $status;
205
            $issue->closed_user_id = Auth::id();
206
            $issue->closed_at = Carbon::now();
207
            $issue->save();
208
209
            return redirect()->back()->with('success', _('Updated successfully'));
210
        } else {
211
212
            $position = 0;
213
214
            foreach(json_decode($request->json) as $id){
215
                $issue = Issue::find($id);
216
                $issue->config_status_id = $request->status_id;
217
                $issue->closed_user_id = Auth::id();
218
                $issue->closed_at = Carbon::now();
219
                $issue->position = $position++;
220
                $issue->save();
221
            }
222
            return true;
223
        }
224
    }
225
226
    /**
227
     * Remove the specified resource from storage.
228
     *
229
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
230
     *
231
     * @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...
232
     */
233
    public function destroy($slug)
234
    {
235
        $issue = Issue::where('slug', $slug)->firstOrFail();
236
237
        if (isset($issue->userStory)) {
238
            $redirect = redirect()->route('user_stories.show', ['slug' => $issue->userStory->slug]);
239
        } else {
240
            $redirect = redirect()->route('sprints.show', ['slug' => $issue->sprint->slug]);
241
        }
242
243
        $issue->delete();
244
245
        return $redirect;
246
    }
247
}
248