Completed
Push — master ( d096a8...68247b )
by Jasper
05:13
created

ServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 5 1
A getResponseMacroName() 0 3 1
A registerResponseMacro() 0 9 1
1
<?php
2
3
namespace Swis\Laravel\JavaScriptData;
4
5
use Illuminate\Support\Facades\Response;
6
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
7
8
class ServiceProvider extends BaseServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13 9
    public function boot()
14
    {
15 9
        $this->publishes([__DIR__.'/../config/' => config_path()], 'config');
16
17 9
        $this->registerResponseMacro($this->getResponseMacroName());
18 9
    }
19
20
    /**
21
     * Register the application services.
22
     */
23 9
    public function register()
24
    {
25 9
        $this->mergeConfigFrom(__DIR__.'/../config/javascript-data-response.php', 'javascript-data-response');
26
27 9
        $this->app->singleton(Builder::class);
28 9
    }
29
30
    /**
31
     * Response macro for JavaScript data.
32
     *
33
     * @param string $name
34
     */
35 9
    protected function registerResponseMacro(string $name)
36
    {
37 9
        Response::macro(
38 9
            $name,
39 9
            function () {
40 3
                $builder = app(Builder::class);
41 3
                $factory = new ResponseFactory(/* @scrutinizer ignore-type */ $this, $builder);
42
43 3
                return $factory->make(...\func_get_args());
0 ignored issues
show
Bug introduced by
func_get_args() is expanded, but the parameter $name of Swis\Laravel\JavaScriptD...ResponseFactory::make() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
                return $factory->make(/** @scrutinizer ignore-type */ ...\func_get_args());
Loading history...
44 9
            }
45
        );
46 9
    }
47
48 9
    protected function getResponseMacroName(): string
49
    {
50 9
        return 'javascriptData';
51
    }
52
}
53