Passed
Push — master ( 6f560d...092f27 )
by Iman
01:45
created

RouteMacros   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 70.21 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 33
loc 47
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMacros() 0 8 1
A registerViewMacro() 11 11 1
A registerWidget() 11 11 1
A registerJsonWidget() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Imanghafoori\Widgets;
4
5
use Illuminate\Support\Facades\Route;
6
7
class RouteMacros
8
{
9
    public function registerMacros()
10
    {
11
        $this->registerViewMacro();
12
13
        $this->registerWidget();
14
15
        $this->registerJsonWidget();
16
    }
17
18 View Code Duplication
    private function registerViewMacro()
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...
19
    {
20
        Route::macro('view', function ($url, $view, $name = null) {
21
            return Route::get($url, [
22
                'as' => $name,
23
                'uses' => function () use ($view) {
24
                    return view($view);
25
                },
26
            ]);
27
        });
28
    }
29
30 View Code Duplication
    private function registerWidget()
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...
31
    {
32
        Route::macro('widget', function ($url, $widget, $name = null) {
33
            return Route::get($url, [
34
                'as' => $name,
35
                'uses' => function (...$args) use ($widget) {
36
                    return render_widget($widget, $args);
37
                },
38
            ]);
39
        });
40
    }
41
42 View Code Duplication
    private function registerJsonWidget()
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...
43
    {
44
        Route::macro('jsonWidget', function ($url, $widget, $name = null) {
45
            return Route::get($url, [
46
                'as' => $name,
47
                'uses' => function (...$args) use ($widget) {
48
                    return json_widget($widget, $args);
49
                },
50
            ]);
51
        });
52
    }
53
}
54