Completed
Pull Request — master (#47)
by Freek
04:15
created

FractalLumenServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Fractal;
4
5
use Illuminate\Support\ServiceProvider;
6
use League\Fractal\Manager;
7
use League\Fractal\Serializer\SerializerAbstract;
8
9
class FractalLumenServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the application services.
13
     */
14 View Code Duplication
    public function register()
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...
15
    {
16
        $this->app->configure('laravel-fractal');
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean registerConfiguredProviders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
17
18
        $this->app->bind(Fractal::class, function () {
19
            $manager = new Manager();
20
21
            $fractal = new Fractal($manager);
22
23
            $config = $this->app['config']->get('laravel-fractal');
24
25
            if (! empty($config['default_serializer'])) {
26
                $fractal = $this->setDefaultSerializer($fractal, $config['default_serializer']);
27
            }
28
29
            return $fractal;
30
        });
31
32
        $this->app->alias(Fractal::class, 'laravel-fractal');
33
    }
34
35
    /**
36
     * Set the default serializer.
37
     *
38
     * @param \Spatie\Fractal\Fractal                              $fractal
39
     * @param string|\League\Fractal\Serializer\SerializerAbstract $serializer
40
     *
41
     * @return mixed
42
     */
43
    protected function setDefaultSerializer(Fractal $fractal, $serializer)
44
    {
45
        if ($serializer instanceof SerializerAbstract) {
46
            return $fractal->serializeWith($serializer);
47
        }
48
49
        return $fractal->serializeWith(new $serializer());
50
    }
51
}
52