PathDeducer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A deducePath() 0 6 1
A deduceViewLogicalName() 0 10 2
1
<?php
2
3
namespace Knp\RadBundle\View;
4
5
use Symfony\Component\Templating\TemplateNameParserInterface;
6
use Knp\RadBundle\Filesystem\PathExpander;
7
8
/**
9
 * The path deducer is responsible of deducing paths from logical view names
10
 */
11
class PathDeducer
12
{
13
    private $nameParser;
14
    private $pathExpander;
15
    private $logicalNames = array();
16
    private $defaultLogicalName;
17
18
    public function __construct(TemplateNameParserInterface $nameParser, PathExpander $pathExpander, array $logicalNames, $defaultLogicalName)
19
    {
20
        $this->nameParser   = $nameParser;
21
        $this->pathExpander = $pathExpander;
22
        $this->logicalNames = $logicalNames;
23
        $this->defaultLogicalName = $defaultLogicalName;
24
    }
25
26
    /**
27
     * Returns the path corresponding to the specified view name
28
     *
29
     * @param string $logicalName A logical view name (i.e FooBundle:Bar:baz.html.twig)
30
     *
31
     * @return string The path of the view
32
     */
33
    public function deducePath($logicalName)
34
    {
35
        $path = $this->nameParser->parse($logicalName)->getPath();
36
37
        return $this->pathExpander->expand($path);
38
    }
39
40
    public function deduceViewLogicalName($logicalName)
41
    {
42
        $name = $this->nameParser->parse($logicalName)->get('name');
43
44
        if (isset($this->logicalNames[$name])) {
45
            return $this->logicalNames[$name];
46
        }
47
48
        return $this->defaultLogicalName;
49
    }
50
}
51