ViewName   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A getViewName() 0 8 2
A generateViewHierarchy() 0 10 2
B getPrefix() 0 17 5
1
<?php
2
3
namespace Knp\RadBundle\Routing\Conventional\Generator;
4
5
use Knp\RadBundle\Routing\Conventional\Config;
6
use Knp\RadBundle\Routing\Conventional\Generator;
7
8
class ViewName implements Generator
9
{
10
    public function generate(Config $config)
11
    {
12
        return sprintf('%s:%s', $this->getViewName($config), $config->name);
13
    }
14
15
    private function getViewName(Config $config)
16
    {
17
        if ($config->getView()) {
18
            return $config->getView();
19
        }
20
21
        return $this->generateViewHierarchy($config);
22
    }
23
24
    private function generateViewHierarchy(Config $config)
25
    {
26
        $parts = array();
27
        if ($config->parent) {
28
            $parts[] = $this->generateViewHierarchy($config->parent);
29
        }
30
        $parts[] = $this->getPrefix($config);
31
32
        return implode('/', array_filter($parts));
33
    }
34
35
    private function getPrefix(Config $config)
36
    {
37
        $parts = explode(':', $config->name);
38
39
        if (1 === count($parts)) {
40
            return;
41
        }
42
43
        if ($config->parent && 2 === count($parts)) {
44
            array_shift($parts);
45
            return implode('/', $parts);
46
        }
47
48
        if (!$config->parent) {
49
            return implode(':', $parts);
50
        }
51
    }
52
}
53