FractalServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Spatie\Fractal;
4
5
use Illuminate\Foundation\Application as LaravelApplication;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\ServiceProvider;
8
use Laravel\Lumen\Application as LumenApplication;
0 ignored issues
show
Bug introduced by
The type Laravel\Lumen\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Spatie\Fractal\Console\Commands\TransformerMakeCommand;
10
11
class FractalServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16 228
    public function boot()
17
    {
18 228
        $this->setupConfig();
19
20 228
        if ($this->app->runningInConsole()) {
21 228
            $this->commands([
22 228
                TransformerMakeCommand::class,
23
            ]);
24
        }
25
26 228
        $this->setupMacro();
27 228
    }
28
29
    /**
30
     * Register the application services.
31
     */
32 190
    public function register()
33
    {
34 38
        $this->app->singleton('fractal', function ($app, $arguments) {
35 48
            return fractal(...$arguments);
0 ignored issues
show
Bug introduced by
$arguments is expanded, but the parameter $data of fractal() 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

35
            return fractal(/** @scrutinizer ignore-type */ ...$arguments);
Loading history...
36 228
        });
37
38 228
        $this->app->alias('fractal', Fractal::class);
39 228
    }
40
41 228
    protected function setupConfig()
42
    {
43 228
        $source = realpath(__DIR__.'/../config/fractal.php');
44
45 228
        if ($this->app instanceof LaravelApplication) {
46 228
            $this->publishes([$source => config_path('fractal.php')]);
47
        } elseif ($this->app instanceof LumenApplication) {
48
            $this->app->configure('fractal');
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean configPath()? ( Ignorable by Annotation )

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

48
            $this->app->/** @scrutinizer ignore-call */ 
49
                        configure('fractal');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        }
50
51 228
        $this->mergeConfigFrom($source, 'fractal');
52 228
    }
53
54
    /**
55
     * Add a 'transformWith' macro to Laravel's collection.
56
     */
57 38
    protected function setupMacro()
58
    {
59 190
        Collection::macro('transformWith', function ($transformer) {
60 6
            return fractal($this, $transformer);
61 228
        });
62 228
    }
63
}
64