ChiefNavigation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 3
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Thinktomorrow\Chief\App\Http\Middleware;
5
6
use Closure;
7
use Illuminate\Contracts\Container\Container;
8
use Thinktomorrow\Chief\Admin\Nav\Nav;
9
use Thinktomorrow\Chief\Managers\Register\Registry;
10
11
final class ChiefNavigation
12
{
13
    /** @var Container */
14
    private $container;
15
16
    /** @var Registry */
17
    private Registry $registry;
18
19
    public function __construct(Registry $registry, Container $container)
20
    {
21
        $this->container = $container;
22
        $this->registry = $registry;
23
    }
24
25
    public function handle($request, Closure $next)
26
    {
27
        foreach ($this->registry->pageResources() as $resource) {
28
            if ($navItem = $resource->getNavItem()) {
29
                $this->container->make(Nav::class)->add($navItem);
30
            }
31
        }
32
33
        return $next($request);
34
    }
35
}
36