Completed
Branch develop (a31570)
by Mohamed
08:09 queued 04:45
created

BladeServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 25.88 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 95.12%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 4
c 7
b 2
f 2
lcom 0
cbo 1
dl 22
loc 85
ccs 39
cts 41
cp 0.9512
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 22 68 3
A register() 0 3 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
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
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 Tinyissue\Providers;
13
14
use Illuminate\Support\ServiceProvider;
15
16
/**
17
 * BladeServiceProvider is the blade service provider for extending blade template engine
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class BladeServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Bootstrap any application services.
25
     */
26 53
    public function boot()
27
    {
28 53
        \Blade::directive(
29 53
            'macro',
30 View Code Duplication
            function ($expression) {
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...
31 2
                $pattern = '/(\([\'|\"](\w+)[\'|\"],\s*(([^\@])+|(.*))\))/xim';
32 2
                $matches = [];
33 2
                preg_match_all($pattern, $expression, $matches);
34
35 2
                if (!isset($matches[3][0])) {
36
                    throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: macro%s', $expression));
37
                }
38
39 2
                return sprintf("<?php \$___tiny['%s']=function(%s){ ob_start(); ?>\n", $matches[2][0], $matches[3][0]);
40 53
            }
41
        );
42
43 53
        \Blade::directive(
44 53
            'endmacro',
45
            function ($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46 2
                return "\n<?php return ob_get_clean();} ?>\n";
47 53
            }
48
        );
49
50 53
        \Blade::directive(
51 53
            'usemacro',
52 View Code Duplication
            function ($expression) {
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...
53 2
                $pattern = '/(\([\'|\"](\w+)[\'|\"],\s*(([^\@])+|(.*))\))/xim';
54 2
                $matches = [];
55 2
                preg_match_all($pattern, $expression, $matches);
56
57 2
                if (!isset($matches[3][0])) {
58
                    throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: usemacro%s', $expression));
59
                }
60
61 2
                return sprintf("<?php echo \$___tiny['%s'](%s); ?>\n", $matches[2][0], $matches[3][0]);
62 53
            }
63
        );
64
65 53
        \Blade::directive(
66 53
            'permission',
67
            function ($expression) {
68 5
                return "<?php if(!Auth::guest() && Auth::user()->permission{$expression}): ?>";
69 53
            }
70
        );
71
72 53
        \Blade::directive(
73 53
            'endpermission',
74
            function ($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75 5
                return '<?php endif; ?>';
76 53
            }
77
        );
78
79 53
        \Blade::directive(
80 53
            'settings',
81
            function ($expression) {
82
                $expression = substr(substr($expression, 0, -2), 2);
83
                return "<?php if(with(new \\Tinyissue\\Model\\Settings)->{$expression}()): ?>";
84 53
            }
85
        );
86
87 53
        \Blade::directive(
88 53
            'endsettings',
89 53
            function ($expression) {
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
                return '<?php endif; ?>';
91 53
            }
92
        );
93 53
    }
94
95
    /**
96
     * Register any application services.
97
     *
98
     * This service provider is a great spot to register your various container
99
     * bindings with the application. As you can see, we are registering our
100
     * "Registrar" implementation here. You can add your own bindings too!
101
     */
102 53
    public function register()
103
    {
104 53
    }
105
}
106