Navigation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getController() 0 4 1
A getSections() 0 6 2
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Vault\Models;
10
11
use Psr\Http\Message\ServerRequestInterface;
12
use Spiral\Core\Component;
13
use Spiral\Vault\Vault;
14
15
class Navigation extends Component
16
{
17
    /**
18
     * Associated vault instance.
19
     *
20
     * @var Vault
21
     */
22
    private $vault;
23
24
    /**
25
     * Currently active request (for uri resolution).
26
     *
27
     * @var ServerRequestInterface
28
     */
29
    private $request;
30
31
    /**
32
     * @param \Spiral\Vault\Vault                      $vault
33
     * @param \Psr\Http\Message\ServerRequestInterface $request
34
     */
35
    public function __construct(Vault $vault, ServerRequestInterface $request)
36
    {
37
        $this->vault = $vault;
38
        $this->request = $request;
39
    }
40
41
    /**
42
     * Currently active controller.
43
     *
44
     * @return string
45
     */
46
    public function getController(): string
47
    {
48
        return $this->request->getAttribute('route')->getMatches()['controller'];
49
    }
50
51
    /**
52
     * Get all navigation sections. This is generator.
53
     *
54
     * @generator
55
     * @return \Generator|Section[]
56
     */
57
    public function getSections(): \Generator
58
    {
59
        foreach ($this->vault->getConfig()->navigationSections() as $section) {
60
            yield new Section($this->vault, $section);
61
        }
62
    }
63
}