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

BladeServiceProvider::boot()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 68
Code Lines 40

Duplication

Lines 22
Ratio 32.35 %

Code Coverage

Tests 37
CRAP Score 3.0012

Importance

Changes 7
Bugs 2 Features 2
Metric Value
c 7
b 2
f 2
dl 22
loc 68
ccs 37
cts 39
cp 0.9487
rs 9.2448
cc 3
eloc 40
nc 1
nop 0
crap 3.0012

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 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