HtmlServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
rs 10
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 1
A registerHtmlBuilder() 0 6 1
A registerFormBuilder() 0 10 1
A registerBlenderBuilder() 0 4 1
1
<?php
2
3
namespace App\Services\Html;
4
5
use Collective\Html\HtmlServiceProvider as ServiceProvider;
6
7
class HtmlServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Indicates if loading of the provider is deferred.
11
     *
12
     * @var bool
13
     */
14
    protected $defer = true;
15
16
    /**
17
     * Register the service provider.
18
     */
19
    public function register()
20
    {
21
        $this->registerHtmlBuilder();
22
        $this->registerFormBuilder();
23
        $this->registerBlenderBuilder();
24
25
        $this->app->alias('html', HtmlBuilder::class);
26
        $this->app->alias('form', FormBuilder::class);
27
    }
28
29
    /**
30
     * Register the HTML builder instance.
31
     */
32
    protected function registerHtmlBuilder()
33
    {
34
        $this->app->singleton('html', function ($app) {
35
            return new HtmlBuilder($app['url'], view());
0 ignored issues
show
Bug introduced by
It seems like view() can also be of type object<Illuminate\View\View>; however, Collective\Html\HtmlBuilder::__construct() does only seem to accept object<Illuminate\Contracts\View\Factory>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36
        });
37
    }
38
39
    /**
40
     * Register the form builder instance.
41
     */
42
    protected function registerFormBuilder()
43
    {
44
        $this->app->singleton('form', function ($app) {
45
            $formBuilder = new FormBuilder($app['html'], $app['url'], view(), $app['session.store']->getToken());
0 ignored issues
show
Bug introduced by
It seems like view() can also be of type object<Illuminate\View\View>; however, Collective\Html\FormBuilder::__construct() does only seem to accept object<Illuminate\Contracts\View\Factory>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
46
47
            $formBuilder->setSessionStore($app['session.store']);
48
49
            return $formBuilder;
50
        });
51
    }
52
53
    /**
54
     * Register the blender builder instance.
55
     */
56
    protected function registerBlenderBuilder()
57
    {
58
        $this->app->singleton(BlenderFormBuilder::class);
59
    }
60
}
61