Completed
Pull Request — master (#17)
by Phecho
42:37
created

GroupsController::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 28
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
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;
13
14
use AltThree\Validator\ValidationException;
15
use Gitamin\Commands\ProjectNamespace\AddProjectNamespaceCommand;
16
use Gitamin\Commands\ProjectNamespace\RemoveProjectNamespaceCommand;
17
use Gitamin\Commands\ProjectNamespace\UpdateProjectNamespaceCommand;
18
use Gitamin\Models\Project;
19
use Gitamin\Models\ProjectNamespace;
20
use Gitamin\Models\Group;
21
use Gitamin\Models\Tag;
22
use Gitamin\Http\Controllers\Controller;
23
use GrahamCampbell\Binput\Facades\Binput;
24
use Illuminate\Support\Facades\Redirect;
25
use Illuminate\Support\Facades\Auth;
26
use Illuminate\Support\Facades\View;
27
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
28
29
class GroupsController extends Controller
30
{
31
    /**
32
     * Array of sub-menu items.
33
     *
34
     * @var array
35
     */
36
    protected $subMenu = [];
37
38
    /**
39
     * Creates a new project controller instance.
40
     *
41
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
42
     */
43
    public function __construct()
44
    {
45
        $this->subMenu = [
46
            'projects' => [
47
                'title'  => trans('dashboard.projects.projects'),
48
                'url'    => route('dashboard.projects.index'),
49
                'icon'   => 'fa fa-sitemap',
50
                'active' => false,
51
            ], 
52
            'groups'   => [
53
                'title'  => trans_choice('gitamin.groups.groups', 2),
54
                'url'    => route('dashboard.groups.index'),
55
                'icon'   => 'fa fa-folder',
56
                'active' => false,
57
            ],
58
            'labels' => [
59
                'title'  => trans_choice('dashboard.projects.labels.labels', 2),
60
                'url'    => route('dashboard.projects.index'),
61
                'icon'   => 'fa fa-tags',
62
                'active' => false,
63
            ],
64
        ];
65
66
        View::share([
67
            'sub_menu'  => $this->subMenu,
68
            'sub_title' => trans_choice('dashboard.projects.projects', 2),
69
        ]);
70
    }
71
72
    /**
73
     * Shows the project teams view.
74
     *
75
     * @return \Illuminate\View\View
76
     */
77
    public function index()
78
    {
79
        $this->subMenu['groups']['active'] = true;
80
81
        return View::make('groups.index')
82
            ->withPageTitle(trans_choice('gitamin.groups.groups', 2).' - '.trans('dashboard.dashboard'))
83
            ->withGroups(Group::get())
84
            ->withSubMenu($this->subMenu);
85
    }
86
87
    public function show($namespace)
88
    {
89
        $group = Group::where('path', '=', $namespace)->first();
90
        return View::make('groups.show')
91
            ->withGroup($group);
92
    }
93
94
    /**
95
     * Shows the add project view.
96
     *
97
     * @return \Illuminate\View\View
98
     */
99
    public function new()
100
    {
101
        return View::make('groups.new')
102
            ->withPageTitle(trans('dashboard.groups.new.title').' - '.trans('dashboard.dashboard'));
103
            //->withGroups(ProjectNamespace::all());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
104
    }
105
106
    
107
    /**
108
     * Creates a new project.
109
     *
110
     * @return \Illuminate\Http\RedirectResponse
111
     */
112
    public function create()
113
    {
114
        $groupData = Binput::get('group');
115
        $groupData['type'] = 'group';
116
        $groupData['owner_id'] = Auth::user()->id;
117
        try {
118
            $group = $this->dispatchFromArray(AddProjectNamespaceCommand::class, $groupData);
0 ignored issues
show
Unused Code introduced by
$group 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...
119
        } catch (ValidationException $e) {
120
            return Redirect::route('groups.new')
121
                ->withInput(Binput::all())
122
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.teams.add.failure')))
123
                ->withErrors($e->getMessageBag());
124
        }
125
126
        return Redirect::route('groups.index')
127
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.teams.add.success')));
128
    }
129
130
    /**
131
     * Shows the edit project team view.
132
     *
133
     * @param \Gitamin\Models\ProjectTeam $team
0 ignored issues
show
Bug introduced by
There is no parameter named $team. 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...
134
     *
135
     * @return \Illuminate\View\View
136
     */
137
    public function edit($namespace)
138
    {
139
        $group = Group::where('path', '=', $namespace)->first();
140
141
        return View::make('groups.edit')
142
            ->withPageTitle(trans('dashboard.teams.edit.title').' - '.trans('dashboard.dashboard'))
143
            ->withGroup($group);
144
    }
145
146
   
147
148
    /**
149
     * Updates a project team.
150
     *
151
     * @param \Gitamin\Models\ProjectTeam $team
0 ignored issues
show
Bug introduced by
There is no parameter named $team. 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...
152
     *
153
     * @return \Illuminate\Http\RedirectResponse
154
     */
155
    public function update($namespace)
156
    {
157
        $groupData = Binput::get('group');
158
        $group = ProjectNamespace::where('path', '=', $namespace)->first();
159
        try {
160
            $groupData['project_namespace'] = $group;
161
            $groupData['owner_id'] = Auth::user()->id;
162
            $group = $this->dispatchFromArray(UpdateProjectNamespaceCommand::class, $groupData);
163
        } catch (ValidationException $e) {
164
            return Redirect::route('groups.group_edit', ['namespace' => $group->path])
165
                ->withInput(Binput::all())
166
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.groups.edit.failure')))
167
                ->withErrors($e->getMessageBag());
168
        }
169
170
        return Redirect::route('groups.group_edit', ['namespace' => $group->path])
171
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('gitamin.groups.edit.success')));
172
    }
173
}
174