Completed
Push — master ( 0309f7...e870c7 )
by Arjay
14:45
created

FormServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 4
Bugs 2 Features 2
Metric Value
dl 0
loc 49
rs 10
c 4
b 2
f 2
wmc 5
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 31 4
A register() 0 4 1
1
<?php
2
3
namespace Yajra\CMS\Providers;
4
5
use Illuminate\Support\HtmlString;
6
use Illuminate\Support\ServiceProvider;
7
use Yajra\CMS\Entities\Category;
8
9
class FormServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        form()->macro('categories', function ($name = 'category_id', $selected = null, $options = []) {
19
            $html = [];
20
            Category::lists()->each(function (Category $category) use (&$html, $selected, $name) {
21
                $selected = form()->getValueAttribute($name, $selected);
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $selected, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
22
23
                if (is_array($selected)) {
24
                    $selected = in_array($category->id, $selected) ? 'selected' : null;
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $selected, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
25
                } else {
26
                    $selected = ((string) $category->id == (string) $selected) ? 'selected' : null;
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $selected, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
27
                }
28
29
                $options = ['value' => $category->id, 'selected' => $selected, 'data-alias' => $category->present()->alias];
30
31
                $html[] = new HtmlString('<option ' . html()->attributes($options) . '>' . e($category->present()->indentedTitle) . '</option>');
32
            });
33
34
            $list    = implode('', $html);
35
            $options = html()->attributes($options + ['name' => $name]);
36
37
            return new HtmlString("<select{$options}>{$list}</select>");
38
        });
39
40
        form()->macro('imageBrowser', function ($name = 'intro_image', $options = []) {
41
            return view('system.macro.image-browser', [
42
                'name'    => $name,
43
                'options' => $options,
44
            ]);
45
        });
46
    }
47
48
    /**
49
     * Register the application services.
50
     *
51
     * @return void
52
     */
53
    public function register()
54
    {
55
        //
56
    }
57
}
58