UrlExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 5 1
A getCurrentRouteName() 0 5 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Template\Extension;
5
6
use Acelaya\Website\Service\RouteAssemblerInterface;
7
use League\Plates\Engine;
8
use League\Plates\Extension\ExtensionInterface;
9
10
class UrlExtension implements ExtensionInterface
11
{
12
    /**
13
     * @var RouteAssemblerInterface
14
     */
15
    protected $routeAssembler;
16
17
    public function __construct(RouteAssemblerInterface $routeAssembler)
18
    {
19
        $this->routeAssembler = $routeAssembler;
20
    }
21
22
    public function register(Engine $engine)
23
    {
24
        $engine->registerFunction('assemble_url', [$this->routeAssembler, 'assembleUrl']);
25
        $engine->registerFunction('current_route', [$this, 'getCurrentRouteName']);
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getCurrentRouteName(): string
32
    {
33
        $routeResult = $this->routeAssembler->getCurrentRouteResult();
34
        return $routeResult->isSuccess() ? $routeResult->getMatchedRouteName() : '';
35
    }
36
}
37