Passed
Pull Request — master (#39)
by Mostafa Abd El-Salam
04:01
created

PermissionDirectives::hasallroles_directive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maklad\Permission\Directives;
4
5
use Illuminate\View\Compilers\BladeCompiler;
6
7
/**
8
 * Class PermissionDirectives
9
 * @package Maklad\Permission\Directives
10
 */
11
class PermissionDirectives
12
{
13
    private $bladeCompiler;
14
15 18
    public function __construct(BladeCompiler $bladeCompiler)
16
    {
17 18
        $this->bladeCompiler = $bladeCompiler;
18 18
    }
19
20 View Code Duplication
    public function role_directive()
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...
21
    {
22 18
        $this->bladeCompiler->directive('role', function ($arguments) {
23 5
            $arguments = preg_replace('(\(|\)| )', '', $arguments);
24 5
            list($role, $guard) = \explode(',', $arguments . ',');
25
26 5
            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
27 18
        });
28
29 18
        $this->bladeCompiler->directive('endrole', function () {
30 5
            return '<?php endif; ?>';
31 18
        });
32 18
    }
33
34 View Code Duplication
    public function hasrole_directive()
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...
35
    {
36 18
        $this->bladeCompiler->directive('hasrole', function ($arguments) {
37 5
            $arguments = preg_replace('(\(|\)| )', '', $arguments);
38 5
            list($role, $guard) = \explode(',', $arguments . ',');
39
40 5
            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>";
41 18
        });
42 18
        $this->bladeCompiler->directive('endhasrole', function () {
43 5
            return '<?php endif; ?>';
44 18
        });
45 18
    }
46
47 View Code Duplication
    public function hasanyrole_directive()
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...
48
    {
49 18
        $this->bladeCompiler->directive('hasanyrole', function ($arguments) {
50 8
            $arguments = preg_replace('(\(|\)| )', '', $arguments);
51 8
            list($roles, $guard) = \explode(',', $arguments . ',');
52
53 8
            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAnyRole({$roles})): ?>";
54 18
        });
55 18
        $this->bladeCompiler->directive('endhasanyrole', function () {
56 8
            return '<?php endif; ?>';
57 18
        });
58 18
    }
59
60 View Code Duplication
    public function hasallroles_directive()
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...
61
    {
62 18
        $this->bladeCompiler->directive('hasallroles', function ($arguments) {
63 8
            $arguments = preg_replace('(\(|\)| )', '', $arguments);
64 8
            list($roles, $guard) = \explode(',', $arguments . ',');
65
66 8
            return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAllRoles({$roles})): ?>";
67 18
        });
68 18
        $this->bladeCompiler->directive('endhasallroles', function () {
69 8
            return '<?php endif; ?>';
70 18
        });
71
    }
72
}