1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers\Projects; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Issue\AddIssueCommand; |
15
|
|
|
use Gitamin\Http\Controllers\Controller; |
16
|
|
|
use Gitamin\Models\Issue; |
17
|
|
|
use Gitamin\Models\Project; |
18
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
19
|
|
|
use Illuminate\Support\Facades\Auth; |
20
|
|
|
use Illuminate\Support\Facades\Redirect; |
21
|
|
|
use Illuminate\Support\Facades\View; |
22
|
|
|
|
23
|
|
|
class IssuesController extends Controller |
24
|
|
|
{ |
25
|
|
|
protected $active_item = 'issues'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Display a listing of the resource. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Http\Response |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
public function index($namespace, $project_path) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$project = Project::findByPath($namespace, $project_path); |
35
|
|
|
|
36
|
|
|
return View::make('projects.issues.index') |
37
|
|
|
->withProject($project) |
38
|
|
|
->withIssues($project->issues) |
|
|
|
|
39
|
|
|
->withActiveItem($this->active_item) |
40
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function showAction($owner_path, $project_path, $issue) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$project = Project::findByPath($owner_path, $project_path); |
46
|
|
|
|
47
|
|
|
return View::make('projects.issues.show') |
48
|
|
|
->withProject($project) |
49
|
|
|
->withIssue($issue) |
50
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)) |
|
|
|
|
51
|
|
|
->withActiveItem($this->active_item); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function add($namespace, $project_path) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$project = Project::findByPath($namespace, $project_path); |
57
|
|
|
|
58
|
|
|
return View::make('projects.issues.add') |
59
|
|
|
->withProject($project) |
60
|
|
|
->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name)) |
|
|
|
|
61
|
|
|
->withActiveItem($this->active_item); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Show the form for creating a new resource. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Http\Response |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function create($namespace, $project_path) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$project = Project::findByPath($namespace, $project_path); |
72
|
|
|
$issueData = Binput::get('issue'); |
73
|
|
|
|
74
|
|
|
try { |
75
|
|
|
$issueData['author_id'] = Auth::user()->id; |
76
|
|
|
$issueData['project_id'] = $project->id; |
|
|
|
|
77
|
|
|
$issue = $this->dispatchFromArray(AddIssueCommand::class, $issueData); |
|
|
|
|
78
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
79
|
|
|
return Redirect::route('projects.issue_new') |
80
|
|
|
->withInput(Binput::all()) |
81
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.issues.new.failure'))) |
82
|
|
|
->withErrors($e->getMessageBag()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return Redirect::route('projects.issue_index', ['namespace' => $namespace, 'project' => $project_path]) |
86
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.issues.new.success'))); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.