Completed
Push — master ( 1f9ea0...5fc4df )
by Freek
02:28
created

BladeJavaScriptServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A register() 0 7 1
A removeBrackets() 0 4 1
1
<?php
2
3
namespace Spatie\BladeJavaScript;
4
5
use Illuminate\Support\Facades\Blade;
6
use Illuminate\Support\ServiceProvider;
7
8
class BladeJavaScriptServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->publishes([
13
            __DIR__.'/../config/laravel-blade-javascript.php' => config_path('laravel-blade-javascript.php'),
14
        ], 'config');
15
16
        Blade::directive('javascript', function ($expression) {
17
            return "<?= \Spatie\BladeJavaScript\Renderer::render({$this->removeBrackets($expression)}); ?>";
18
        });
19
    }
20
21
    public function register()
22
    {
23
        $this->mergeConfigFrom(
24
            __DIR__.'/../config/laravel-blade-javascript.php',
25
            'laravel-blade-javascript'
26
        );
27
    }
28
29
    protected function removeBrackets(string $expression): string
30
    {
31
        return trim($expression, '()');
32
    }
33
}
34