Completed
Push — develop ( d1af83...ae4f91 )
by Mohamed
05:59
created

BladeServiceProvider::boot()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 53
Code Lines 31

Duplication

Lines 22
Ratio 41.51 %

Code Coverage

Tests 31
CRAP Score 3.002

Importance

Changes 8
Bugs 2 Features 2
Metric Value
c 8
b 2
f 2
dl 22
loc 53
ccs 31
cts 33
cp 0.9394
rs 9.5797
cc 3
eloc 31
nc 1
nop 0
crap 3.002

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 59
    public function boot()
27
    {
28 59
        \Blade::directive(
29 59
            '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 59
            }
41
        );
42
43 59
        \Blade::directive(
44 59
            '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 59
            }
48
        );
49
50 59
        \Blade::directive(
51 59
            '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 59
            }
63
        );
64
65 59
        \Blade::directive(
66 59
            'permission',
67
            function ($expression) {
68 5
                return "<?php if(!Auth::guest() && Auth::user()->permission{$expression}): ?>";
69 59
            }
70
        );
71
72 59
        \Blade::directive(
73 59
            'endpermission',
74 59
            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 59
            }
77
        );
78 59
    }
79
80
    /**
81
     * Register any application services.
82
     *
83
     * This service provider is a great spot to register your various container
84
     * bindings with the application. As you can see, we are registering our
85
     * "Registrar" implementation here. You can add your own bindings too!
86
     */
87 59
    public function register()
88
    {
89 59
    }
90
}
91