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

ProjectsRoutes::map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 53

Duplication

Lines 16
Ratio 21.62 %

Importance

Changes 8
Bugs 2 Features 2
Metric Value
c 8
b 2
f 2
dl 16
loc 74
rs 9.0336
cc 1
eloc 53
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Routes;
13
14
use Illuminate\Contracts\Routing\Registrar;
15
16
/**
17
 * This is the projects routes class.
18
 */
19
class ProjectsRoutes
20
{
21
    /**
22
     * Define the projects routes.
23
     *
24
     * @param \Illuminate\Contracts\Routing\Registrar $router
25
     */
26
    public function map(Registrar $router)
27
    {
28
        // Project Area
29
        $router->group([
30
            'middleware' => ['app.hasSetting'],
31
            'setting'    => 'app_name',
32
            'prefix'     => 'projects',
33
            'as'         => 'projects.',
34 View Code Duplication
        ], function ($router) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
35
            $router->get('/', [
36
                'as'   => 'index',
37
                'uses' => 'ProjectsController@indexAction',
38
            ]);
39
            $router->get('new', [
40
                'as'    => 'new',
41
                'uses'  => 'ProjectsController@newAction',
42
            ]);
43
            $router->post('create', [
44
                'as'    => 'create',
45
                'uses'  => 'ProjectsController@createAction',
46
            ]);
47
        });
48
49
        // Project Sub-routes
50
        $router->group([
51
            'middleware' => ['app.hasSetting'],
52
            'setting'    => 'app_name',
53
            'as'         => 'projects.',
54
        ], function ($router) {
55
           $router->get('{namespace}/{project}', [
56
                'as'   => 'project_show',
57
                'uses' => 'ProjectsController@showAction',
58
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
59
60
           $router->get('{namespace}/{project}/edit', [
61
                'as'   => 'project_edit',
62
                'uses' => 'ProjectsController@editAction',
63
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
64
            $router->post('{namespace}/{project}/update', [
65
                'as'    => 'project_update',
66
                'uses'  => 'ProjectsController@updateAction',
67
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
68
69
            //Issues
70
            $router->get('{namespace}/{project}/issues', [
71
                'as'   => 'issue_index',
72
                'uses' => 'Projects\\IssuesController@index',
73
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
74
75
            //new
76
            $router->get('{namespace}/{project}/issues/new', [
77
                'as'   => 'issue_new',
78
                'uses' => 'Projects\\IssuesController@add',
79
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
80
81
            //create
82
            $router->post('{namespace}/{project}/issues', [
83
                'as'   => 'issue_create',
84
                'uses' => 'Projects\\IssuesController@create',
85
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
86
87
            //show
88
            $router->get('{namespace}/{project}/issues/{issue}', [
89
                'as'   => 'issue_show',
90
                'uses' => 'Projects\\IssuesController@show',
91
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
92
93
            //update
94
            $router->post('{namespace}/{project}/issues/{issue}', [
95
                'as'   => 'issue_update',
96
                'uses' => 'Projects\\IssuesController@update',
97
            ])->where('namespace', '[a-zA-z.0-9_\-]+')->where('project', '[a-zA-z.0-9_\-]+');
98
        });
99
    }
100
}
101