Completed
Pull Request — master (#39)
by Phecho
05:53
created

IssuesController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 1
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
33
    {
34
        $project = $this->getProject($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 add($namespace, $project_path)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
44
    {
45
        $project = $this->getProject($namespace, $project_path);
46
47
        return View::make('projects.issues.add')
48
            ->withProject($project)
49
            ->withPageTitle(sprintf('%s - %s', trans('dashboard.issues.issues'), $project->name))
50
            ->withActiveItem($this->active_item);
51
    }
52
53
    /**
54
     * Show the form for creating a new resource.
55
     *
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function create($namespace, $project_path)
59
    {
60
        $project = $this->getProject($namespace, $project_path);
61
        $issueData = Binput::get('issue');
62
63
        try {
64
            $issueData['author_id'] = Auth::user()->id;
65
            $issueData['project_id'] = $project->id;
66
            $issue = $this->dispatchFromArray(AddIssueCommand::class, $issueData);
0 ignored issues
show
Unused Code introduced by
$issue is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67
        } catch (ValidationException $e) {
0 ignored issues
show
Bug introduced by
The class Gitamin\Http\Controllers...cts\ValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
68
            return Redirect::route('projects.issue_new')
69
                ->withInput(Binput::all())
70
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.issues.new.failure')))
71
                ->withErrors($e->getMessageBag());
72
        }
73
74
        return Redirect::route('projects.issue_index', ['namespace' => $namespace, 'project' => $project_path])
75
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.issues.new.success')));
76
    }
77
}
78