Completed
Push — master ( 5bd517...c7b86e )
by Tomáš
08:52
created

RouteDecorator::isFileNonHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
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
    public function addRoute(RouteInterface $route)
24 10
    {
25
        $this->routes[] = $route;
26 10
    }
27 10
28
    public function decorateFile(AbstractFile $file)
29 8
    {
30
        foreach ($this->routes as $route) {
31 8
            if ($route->matches($file)) {
32 8
                $file->setOutputPath($route->buildOutputPath($file));
33
                $file->setRelativeUrl($route->buildRelativeUrl($file));
34 8
                return;
35
            }
36 8
        }
37 3
38
        $file->setOutputPath($file->getBaseName() . DIRECTORY_SEPARATOR . 'index.html');
39
        $file->setRelativeUrl($file->getBaseName());
40 5
    }
41
}
42