RouteDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRoute() 0 4 1
A decorateFile() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Renderable\Routing;
11
12
use Symplify\PHP7_Sculpin\Contract\Renderable\DecoratorInterface;
13
use Symplify\PHP7_Sculpin\Contract\Renderable\Routing\Route\RouteInterface;
14
use Symplify\PHP7_Sculpin\Renderable\File\AbstractFile;
15
16
final class RouteDecorator implements DecoratorInterface
17
{
18
    /**
19
     * @var RouteInterface[]
20
     */
21
    private $routes = [];
22
23 10
    public function addRoute(RouteInterface $route)
24
    {
25 10
        $this->routes[] = $route;
26 10
    }
27
28 7
    public function decorateFile(AbstractFile $file)
29
    {
30 7
        foreach ($this->routes as $route) {
31 7
            if ($route->matches($file)) {
32 6
                $file->setOutputPath($route->buildOutputPath($file));
33 6
                $file->setRelativeUrl($route->buildRelativeUrl($file));
34
35 7
                return;
36
            }
37
        }
38
39 2
        $file->setOutputPath($file->getBaseName() . DIRECTORY_SEPARATOR . 'index.html');
40 2
        $file->setRelativeUrl($file->getBaseName());
41 2
    }
42
}
43