GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 414922...a9bc98 )
by butschster
12:35
created

WidgetsRegistry   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A registerWidget() 0 6 1
B placeWidgets() 0 37 4
A makeWidget() 0 4 2
A createClassWidget() 0 4 1
1
<?php
2
3
namespace SleepingOwl\Admin\Widgets;
4
5
use Illuminate\View\View;
6
use Illuminate\Support\Collection;
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\Container\Container;
9
use SleepingOwl\Admin\Contracts\Widgets\WidgetInterface;
10
use SleepingOwl\Admin\Contracts\Widgets\WidgetsRegistryInterface;
11
12
class WidgetsRegistry implements WidgetsRegistryInterface
13
{
14
    /**
15
     * @var Collection|WidgetInterface[]
16
     */
17
    protected $widgets;
18
19
    /**
20
     * @var Container
21
     */
22
    private $container;
23
24
    /**
25
     * BlocksRegistry constructor.
26
     *
27
     * @param Container $container
28
     */
29
    public function __construct(Container $container)
30
    {
31
        $this->widgets = new Collection();
32
        $this->container = $container;
33
    }
34
35
    /**
36
     * @param $widget
37
     *
38
     * @return $this
39
     */
40
    public function registerWidget($widget)
41
    {
42
        $this->widgets->push($widget);
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param Factory $factory
49
     */
50
    public function placeWidgets(Factory $factory)
51
    {
52
        if ($this->widgets->count() === 0) {
53
            return;
54
        }
55
56
        $groupedBlocks = $this->widgets
57
            ->map(function ($class) {
58
                return $this->makeWidget($class);
59
            })
60
            ->filter(function (WidgetInterface $block) {
61
                return $block->active();
62
            })
63
            ->groupBy(function (WidgetInterface $block) {
64
                return $block->template();
65
            });
66
67
        foreach ($groupedBlocks as $template => $widgets) {
68
            $factory->composer($template, function (View $view) use ($widgets) {
69
                $factory = $view->getFactory();
70
71
                /** @var Collection|WidgetInterface[] $widgets */
72
                $widgets = $widgets->sortBy(function (WidgetInterface $block) {
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $widgets, 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...
73
                    return $block->position();
74
                });
75
76
                foreach ($widgets as $widget) {
77
                    $widget->setInjectableView($view);
78
79
                    $factory->inject(
80
                        $widget->block(),
81
                        $widget->toHtml()
82
                    );
83
                }
84
            });
85
        }
86
    }
87
88
    /**
89
     * @param  mixed  $widget
90
     * @return mixed
91
     */
92
    public function makeWidget($widget)
93
    {
94
        return is_string($widget) ? $this->createClassWidget($widget) : $widget;
95
    }
96
97
    /**
98
     * @param $widget
99
     *
100
     * @return \Closure
101
     */
102
    public function createClassWidget($widget)
103
    {
104
        return $this->container->make($widget);
105
    }
106
}
107